-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenUser
More file actions
executable file
·79 lines (73 loc) · 2.54 KB
/
genUser
File metadata and controls
executable file
·79 lines (73 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#TODO: Need to trap on successful completion
#trap "echo '\\n'All the users were created successfully." EXIT
. config
#Only consider the first paramater if many are given -- $1
if [ -n "$1" ] && [ -f "$1" ]; then
userAccounts="$1"
else
userAccounts=`mktemp -t omegaServer.users.XXXXXX`
echo "Temporary data will be stored in "$userAccounts
. getUserInfo #Loads getUInfo function
while echo;do
getUInfo $userAccounts
while echo; do
read -n1 -p "Do you want to add more? [Y/n]: " eoc; echo
case $eoc in
y|Y) break;;
n|N) break 2;;
esac
done
done
fi
mkdir -p log_files
echo "" > $LOGFILE # Initialize log file for current run
mkdir -p $SERVER_DIR
#Create userlevel groups
for x in Users Managers Ceo;do
groupadd omega$x 2>/dev/null # To throw duplicate addition error
done
cat $userAccounts | while read aNum branch citizen age legacy; do
# Create Branch
if ! ( id $branch &> /dev/null); then
## Note: Branch Balance and Transaction history are initiated by updateBranch script
useradd -g omegaManagers -G omegaUsers -mk $MANAGER_FILES -b $SERVER_DIR $branch &>/dev/null
echo $branch >> log_files/managers.log # Or Branches
echo "Created Branch: $branch" | tee -a $LOGFILE # Pipe can be replaced with redirection to supress output to /dev/stdout
fi
# Create Account
if ! ( id $aNum &> /dev/null);then
useradd -g omegaUsers -mk $USER_FILES -b $SERVER_DIR/$branch $aNum &>/dev/null|| (echo "user $aNum not created" && continue)
echo $aNum>>log_files/users.log #These files can be used to remove the users and groups
else
echo "User $aNum already exists" | tee -a $LOGFILE
continue
fi
# Create a group based on citizenship
if ! ( getent group $citizen &> /dev/null); then #Assuming the citizenship as the required category
groupadd $citizen
echo $citizen >> log_files/citizenship.log
echo "Created Citizenship: $citizen" | tee -a $LOGFILE
fi
# Create a group based on age reservation OPTIONAL
if [ $age = "-" ]; then
age=""
elif ! ( getent group $age &> /dev/null ); then
groupadd $age
echo $age >> log_files/age_reservation.log
echo "Created Age reservation: $age" | tee -a $LOGFILE
fi
# Create a group based on legacy OPTIONAL
if [ $legacy = "-" ]; then
legacy=""
elif ! ( getent group $legacy &> /dev/null ); then
groupadd $legacy
echo $legacy >> log_files/legacy.log
echo "Created legacy category: $legacy" | tee -a $LOGFILE
fi
# Add the user to the respective groups
for category in $citizen $age $legacy;do
usermod -aG "$category" $aNum
done
echo "Created user: $aNum" | tee -a $LOGFILE
done