Compare commits
10 Commits
0fbfb7fb82
...
8d12d96bb3
Author | SHA1 | Date | |
---|---|---|---|
|
8d12d96bb3 | ||
|
53bc27a6f4 | ||
|
cabeaafab5 | ||
|
1fad5689af | ||
|
2668559dbc | ||
|
cd2e06b74f | ||
|
99e46a4d1f | ||
|
2c1d79c425 | ||
|
97acf514b3 | ||
|
7ee48f98d9 |
|
@ -10,6 +10,9 @@ USERNAME=$1
|
||||||
NAME=$2
|
NAME=$2
|
||||||
DEFAULT_QUOTA=256000 # 256MB
|
DEFAULT_QUOTA=256000 # 256MB
|
||||||
|
|
||||||
|
# Extract surname
|
||||||
|
LAST_NAME=$(echo $NAME | awk '{print $NF}')
|
||||||
|
|
||||||
# Check if arguments are not empty
|
# Check if arguments are not empty
|
||||||
if [ -z "$USERNAME" ] || [ -z "$NAME" ]; then
|
if [ -z "$USERNAME" ] || [ -z "$NAME" ]; then
|
||||||
echo "Usage: $0 <username> <name>"
|
echo "Usage: $0 <username> <name>"
|
||||||
|
@ -22,6 +25,12 @@ if [[ $USERNAME =~ " " ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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")
|
NAME=$(echo $NAME | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")
|
||||||
|
|
||||||
# Check if $USERNAME is already in use
|
# Check if $USERNAME is already in use
|
||||||
|
@ -30,11 +39,9 @@ if samba-tool user show $USERNAME >/dev/null 2>&1; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Capitalize every first letter of $NAME
|
|
||||||
|
|
||||||
# Create user
|
# Create user
|
||||||
echo "Creating user $USERNAME with name $NAME and password $USERNAME"
|
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" --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=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
|
# Add user to group alunos
|
||||||
echo "Adding user $USERNAME 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"
|
echo "Creating home directory for user $USERNAME"
|
||||||
mkdir /home/$USERNAME
|
mkdir /home/$USERNAME
|
||||||
echo "Setting permissions for home directory"
|
echo "Setting permissions for home directory"
|
||||||
chmod 700 /home/$USERNAME/ -R
|
chmod 711 /home/$USERNAME/ -R
|
||||||
chown $USERNAME:'domain users' /home/$USERNAME/ -R
|
chown $USERNAME:'domain users' /home/$USERNAME/ -R
|
||||||
|
|
||||||
# Set user quota
|
# Set user quota
|
||||||
|
|
|
@ -10,6 +10,9 @@ USERNAME=$1
|
||||||
NAME=$2
|
NAME=$2
|
||||||
DEFAULT_QUOTA=256000 # 256MB
|
DEFAULT_QUOTA=256000 # 256MB
|
||||||
|
|
||||||
|
# Extract surname
|
||||||
|
LAST_NAME=$(echo $NAME | awk '{print $NF}')
|
||||||
|
|
||||||
# Check if arguments are not empty
|
# Check if arguments are not empty
|
||||||
if [ -z "$USERNAME" ] || [ -z "$NAME" ]; then
|
if [ -z "$USERNAME" ] || [ -z "$NAME" ]; then
|
||||||
echo "Usage: $0 <username> <name>"
|
echo "Usage: $0 <username> <name>"
|
||||||
|
@ -22,6 +25,12 @@ if [[ $USERNAME =~ " " ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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")
|
NAME=$(echo $NAME | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")
|
||||||
|
|
||||||
# Check if $USERNAME is already in use
|
# Check if $USERNAME is already in use
|
||||||
|
@ -30,11 +39,9 @@ if samba-tool user show $USERNAME >/dev/null 2>&1; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Capitalize every first letter of $NAME
|
|
||||||
|
|
||||||
# Create user
|
# Create user
|
||||||
echo "Creating user $USERNAME with name $NAME and password $USERNAME"
|
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
|
# Add user to group alunos
|
||||||
echo "Adding user $USERNAME to group professores"
|
echo "Adding user $USERNAME to group professores"
|
||||||
|
|
60
pdc-add-user-servidor.sh
Executable file
60
pdc-add-user-servidor.sh
Executable 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
36
pdc-bulk-add-user-servidor.sh
Executable 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
45
pdc-bulk-addtogroup.sh
Executable 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
0
pdc-bulk-del-user.sh
Normal file → Executable file
50
pdc-bulk-reset-password.sh
Executable file
50
pdc-bulk-reset-password.sh
Executable 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
|
|
@ -8,6 +8,12 @@ if [ -z "$USERNAME" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
# Check if user exists
|
||||||
if ! samba-tool user show $USERNAME >/dev/null 2>&1; then
|
if ! samba-tool user show $USERNAME >/dev/null 2>&1; then
|
||||||
echo "User $USERNAME does not exist"
|
echo "User $USERNAME does not exist"
|
||||||
|
|
33
pdc-reset-password.sh
Executable file
33
pdc-reset-password.sh
Executable 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
3
users.example.csv
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
aluno1;aluno minusculo;
|
||||||
|
aluno2;ALUNO MAIUSCULO;
|
||||||
|
aluno3;ALUNO misturado;
|
|
Loading…
Reference in New Issue
Block a user