Initial commit
This commit is contained in:
commit
783f265d0b
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
.vscode
|
||||||
|
users.csv
|
53
pdc-add-user-aluno.sh
Executable file
53
pdc-add-user-aluno.sh
Executable file
|
@ -0,0 +1,53 @@
|
||||||
|
#!/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
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Add user to group alunos
|
||||||
|
echo "Adding user $USERNAME to group alunos"
|
||||||
|
samba-tool group addmembers alunos $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-aluno.sh
Executable file
36
pdc-bulk-add-user-aluno.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-aluno.sh $USERNAME "$NAME"
|
||||||
|
|
||||||
|
done <$file
|
20
pdc-del-user.sh
Executable file
20
pdc-del-user.sh
Executable file
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
USERNAME=$1
|
||||||
|
|
||||||
|
# Check if arguments are not empty
|
||||||
|
if [ -z "$USERNAME" ]; then
|
||||||
|
echo "Usage: $0 <username>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if user exists
|
||||||
|
if ! samba-tool user show $USERNAME >/dev/null 2>&1; then
|
||||||
|
echo "User $USERNAME does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
samba-tool user delete $USERNAME
|
||||||
|
|
||||||
|
rm -rf /home/$USERNAME
|
||||||
|
echo "/home/$USERNAME directory deleted"
|
21
pdc-setquota.sh
Executable file
21
pdc-setquota.sh
Executable file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
USERNAME=$1
|
||||||
|
QUOTA=$2
|
||||||
|
|
||||||
|
# Check if arguments are not empty
|
||||||
|
if [ -z "$USERNAME" ] || [ -z "$QUOTA" ]; then
|
||||||
|
echo "Usage: $0 <username> <quota>"
|
||||||
|
exit 1
|
||||||
|
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 quota
|
||||||
|
echo "Setting user quota for user $USERNAME"
|
||||||
|
uidNumber=$(id -u $USERNAME)
|
||||||
|
/usr/share/zentyal-samba/user-quota -s $uidNumber $QUOTA
|
Loading…
Reference in New Issue
Block a user