Compare commits

...

10 Commits

Author SHA1 Message Date
Douglas Barone
8d12d96bb3 Add u if necessary 2023-03-07 14:22:56 -04:00
Douglas Barone
53bc27a6f4 Append u 2023-03-02 10:27:13 -04:00
Douglas Barone
cabeaafab5 Append char if only numeric 2023-03-01 12:53:47 -04:00
Douglas Barone
1fad5689af Append char if only numeric 2023-03-01 12:53:01 -04:00
Douglas Barone
2668559dbc Added bulk reset 2023-02-28 15:11:34 -04:00
Douglas Barone
cd2e06b74f Added reset password 2023-02-28 14:59:52 -04:00
Douglas Barone
99e46a4d1f Added example 2023-02-25 08:38:44 -04:00
Douglas Barone
2c1d79c425 Added surname 2023-02-16 11:26:18 -04:00
Douglas Barone
97acf514b3 Updated scripts 2023-02-16 10:42:07 -04:00
Douglas Barone
7ee48f98d9 Updated scripts 2022-07-25 16:15:22 -04:00
10 changed files with 255 additions and 8 deletions

View File

@ -10,6 +10,9 @@ USERNAME=$1
NAME=$2
DEFAULT_QUOTA=256000 # 256MB
# Extract surname
LAST_NAME=$(echo $NAME | awk '{print $NF}')
# Check if arguments are not empty
if [ -z "$USERNAME" ] || [ -z "$NAME" ]; then
echo "Usage: $0 <username> <name>"
@ -22,6 +25,12 @@ if [[ $USERNAME =~ " " ]]; then
exit 1
fi
# Check if $USERNAME starts with a number
if [[ $USERNAME =~ ^[0-9] ]]; then
echo "Username cannot start with a number. Appending 'u' to the beginning of the username..."
USERNAME="u$USERNAME"
fi
NAME=$(echo $NAME | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")
# Check if $USERNAME is already in use
@ -30,11 +39,9 @@ if samba-tool user show $USERNAME >/dev/null 2>&1; then
exit 1
fi
# Capitalize every first letter of $NAME
# Create user
echo "Creating user $USERNAME with name $NAME and password $USERNAME"
samba-tool user create $USERNAME $USERNAME --userou='OU=Alunos,OU=IFMS-PP' --given-name="$NAME" --home-drive='H:' --home-directory="\\\\acadsrv.ACAD.PP.IFMS.EDU.BR\\$USERNAME" --use-username-as-cn --must-change-at-next-login
echo "Creating user $USERNAME with display name $NAME, last name $LAST_NAME and password $USERNAME"
samba-tool user create $USERNAME $USERNAME --userou='OU=Alunos,OU=IFMS-PP' --given-name="$NAME" --surname="$LAST_NAME" --home-drive='H:' --home-directory="\\\\acadsrv.ACAD.PP.IFMS.EDU.BR\\$USERNAME" --use-username-as-cn --must-change-at-next-login
# Add user to group alunos
echo "Adding user $USERNAME to group alunos"
@ -44,7 +51,7 @@ samba-tool group addmembers alunos $USERNAME
echo "Creating home directory for user $USERNAME"
mkdir /home/$USERNAME
echo "Setting permissions for home directory"
chmod 700 /home/$USERNAME/ -R
chmod 711 /home/$USERNAME/ -R
chown $USERNAME:'domain users' /home/$USERNAME/ -R
# Set user quota

View File

@ -10,6 +10,9 @@ USERNAME=$1
NAME=$2
DEFAULT_QUOTA=256000 # 256MB
# Extract surname
LAST_NAME=$(echo $NAME | awk '{print $NF}')
# Check if arguments are not empty
if [ -z "$USERNAME" ] || [ -z "$NAME" ]; then
echo "Usage: $0 <username> <name>"
@ -22,6 +25,12 @@ if [[ $USERNAME =~ " " ]]; then
exit 1
fi
# Check if $USERNAME starts with a number
if [[ $USERNAME =~ ^[0-9] ]]; then
echo "Username cannot start with a number. Appending 'u' to the beginning of the username..."
USERNAME="u$USERNAME"
fi
NAME=$(echo $NAME | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")
# Check if $USERNAME is already in use
@ -30,11 +39,9 @@ if samba-tool user show $USERNAME >/dev/null 2>&1; then
exit 1
fi
# Capitalize every first letter of $NAME
# Create user
echo "Creating user $USERNAME with name $NAME and password $USERNAME"
samba-tool user create $USERNAME $USERNAME --userou='OU=Professores,OU=IFMS-PP' --given-name="$NAME" --home-drive='H:' --home-directory="\\\\acadsrv.ACAD.PP.IFMS.EDU.BR\\$USERNAME" --use-username-as-cn --must-change-at-next-login
samba-tool user create $USERNAME $USERNAME --userou='OU=Professores,OU=IFMS-PP' --given-name="$NAME" --surname="$LAST_NAME" --home-drive='H:' --home-directory="\\\\acadsrv.ACAD.PP.IFMS.EDU.BR\\$USERNAME" --use-username-as-cn --must-change-at-next-login
# Add user to group alunos
echo "Adding user $USERNAME to group professores"

60
pdc-add-user-servidor.sh Executable file
View File

@ -0,0 +1,60 @@
#!/bin/bash
###############################
# Script to add a student #
# Must be run as root #
# For use with Zential Server #
###############################
USERNAME=$1
NAME=$2
DEFAULT_QUOTA=256000 # 256MB
# Extract surname
LAST_NAME=$(echo $NAME | awk '{print $NF}')
# Check if arguments are not empty
if [ -z "$USERNAME" ] || [ -z "$NAME" ]; then
echo "Usage: $0 <username> <name>"
exit 1
fi
# Check if $USERNAME has spaces
if [[ $USERNAME =~ " " ]]; then
echo "Username cannot have spaces"
exit 1
fi
# Check if $USERNAME starts with a number
if [[ $USERNAME =~ ^[0-9] ]]; then
echo "Username cannot start with a number. Appending 'u' to the beginning of the username..."
USERNAME="u$USERNAME"
fi
NAME=$(echo $NAME | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")
# Check if $USERNAME is already in use
if samba-tool user show $USERNAME >/dev/null 2>&1; then
echo "User $USERNAME already exists"
exit 1
fi
# Create user
echo "Creating user $USERNAME with name $NAME and password $USERNAME"
samba-tool user create $USERNAME $USERNAME --userou='OU=Servidores,OU=IFMS-PP' --given-name="$NAME" --surname="$LAST_NAME" --home-drive='H:' --home-directory="\\\\acadsrv.ACAD.PP.IFMS.EDU.BR\\$USERNAME" --use-username-as-cn --must-change-at-next-login
# Add user to group alunos
echo "Adding user $USERNAME to group servidores"
samba-tool group addmembers servidores $USERNAME
# Create home directory
echo "Creating home directory for user $USERNAME"
mkdir /home/$USERNAME
echo "Setting permissions for home directory"
chmod 700 /home/$USERNAME/ -R
chown $USERNAME:'domain users' /home/$USERNAME/ -R
# Set user quota
./pdc-setquota.sh $USERNAME $DEFAULT_QUOTA
echo "User $USERNAME ($NAME) created. Password must be changed at next login."

36
pdc-bulk-add-user-servidor.sh Executable file
View File

@ -0,0 +1,36 @@
#!/bin/bash
file=$1
# Check if arguments are not empty
if [ -z "$file" ]; then
echo "Usage: $0 <file>"
exit 1
fi
# Check if file exists
if [ ! -f "$file" ]; then
echo "File $file does not exist"
exit 1
fi
# Check if file is empty
if [ ! -s "$file" ]; then
echo "File $file is empty"
exit 1
fi
while IFS="" read -r p || [ -n "$p" ]; do
USERNAME=$(echo $p | cut -d ";" -f 1)
NAME=$(echo $p | cut -d ";" -f 2)
# Check if $USERNAME is empty
if [ -z "$USERNAME" ]; then
echo "Username is empty"
continue
fi
echo "---"
./pdc-add-user-servidor.sh $USERNAME "$NAME"
done <$file

45
pdc-bulk-addtogroup.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
file=$1
group=$2
# Check if arguments are not empty
if [ -z "$file" ]; then
echo "Usage: $0 <file>"
exit 1
fi
# Check if file exists
if [ ! -f "$file" ]; then
echo "File $file does not exist"
exit 1
fi
# Check if file is empty
if [ ! -s "$file" ]; then
echo "File $file is empty"
exit 1
fi
while IFS="" read -r p || [ -n "$p" ]; do
USERNAME=$(echo $p | cut -d ";" -f 1)
# Check if $USERNAME is empty
if [ -z "$USERNAME" ]; then
echo "Username is empty"
continue
fi
echo "---"# Add user to group alunos
echo "Adding user $USERNAME to group $group"
samba-tool group addmembers $group $USERNAME
done <$file

0
pdc-bulk-del-user.sh Normal file → Executable file
View File

50
pdc-bulk-reset-password.sh Executable file
View File

@ -0,0 +1,50 @@
#!/bin/bash
file=$1
DEFAULT_PASSWORD=123456789
PASSWORD=${2:-$DEFAULT_PASSWORD}
# Check if arguments are not empty
if [ -z "$file" ]; then
echo "Usage: $0 <file>"
exit 1
fi
# Check if file exists
if [ ! -f "$file" ]; then
echo "File $file does not exist"
exit 1
fi
# Check if file is empty
if [ ! -s "$file" ]; then
echo "File $file is empty"
exit 1
fi
while IFS="" read -r p || [ -n "$p" ]; do
echo "---"
USERNAME=$(echo $p | cut -d ";" -f 1)
# Check if $USERNAME is empty
if [ -z "$USERNAME" ]; then
echo "Username is empty"
continue
fi
# Check if $USERNAME starts with a number
if [[ $USERNAME =~ ^[0-9] ]]; then
echo "Username cannot start with a number. Appending 'u' to the beginning of the username..."
USERNAME="u$USERNAME"
fi
# Check if user exists
if ! samba-tool user show $USERNAME >/dev/null 2>&1; then
echo "User $USERNAME do not exists"
continue
fi
./pdc-reset-password.sh $USERNAME $PASSWORD
done <$file

View File

@ -8,6 +8,12 @@ if [ -z "$USERNAME" ]; then
exit 1
fi
# Check if $USERNAME starts with a number
if [[ $USERNAME =~ ^[0-9] ]]; then
echo "Username cannot start with a number. Appending 'u' to the beginning of the username..."
USERNAME="u$USERNAME"
fi
# Check if user exists
if ! samba-tool user show $USERNAME >/dev/null 2>&1; then
echo "User $USERNAME does not exist"

33
pdc-reset-password.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
USERNAME=$1
DEFAULT_PASSWORD=123456789
PASSWORD=${2:-$DEFAULT_PASSWORD}
# Check if arguments are not empty
if [ -z "$USERNAME" ]; then
echo "Usage: $0 <username>"
exit 1
fi
# Check if $USERNAME starts with a number
if [[ $USERNAME =~ ^[0-9] ]]; then
echo "Username cannot start with a number. Appending 'u' to the beginning of the username..."
USERNAME="u$USERNAME"
fi
# Check if $USERNAME exists
if ! samba-tool user show $USERNAME >/dev/null 2>&1; then
echo "User $USERNAME do not exists"
exit 1
fi
# Set user password
echo "Setting user password $PASSWORD for user $USERNAME"
# Set user password with smbpasswd, inject password and password confirmation into stdin
echo -e "$PASSWORD\n$PASSWORD" | smbpasswd -s -a $USERNAME >>/var/log/samba/smbpasswd.log 2>&1
# Force password change on next login
echo "Forcing password change on next login for user $USERNAME"
net sam set pwdmustchangenow $USERNAME yes >>/var/log/samba/smbpasswd.log 2>&1

3
users.example.csv Normal file
View File

@ -0,0 +1,3 @@
aluno1;aluno minusculo;
aluno2;ALUNO MAIUSCULO;
aluno3;ALUNO misturado;
1 aluno1 aluno minusculo
2 aluno2 ALUNO MAIUSCULO
3 aluno3 ALUNO misturado