-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_core_acc.sh
55 lines (40 loc) · 1.32 KB
/
create_core_acc.sh
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
#!/bin/bash
# Add users directory
sudo mkdir -p /home/users
# New home base directory
NEW_HOME_BASE="/home/users"
add_and_move_user() {
local username=$1
# Add user
sudo adduser --gecos "" "$username" >/dev/null
# Add core to group sudo
sudo usermod -aG sudo "$username"
if [ $? -eq 0 ]; then
echo "Successfully added user: $username"
# Move the home directory to the new location
OLD_HOME_DIR="/home/$username"
NEW_HOME_DIR="$NEW_HOME_BASE/$username"
if [ -d "$OLD_HOME_DIR" ]; then
sudo mv "$OLD_HOME_DIR" "$NEW_HOME_DIR"
sudo chown -R "$username:$username" "$NEW_HOME_DIR"
# Delete the initial home directory of it exists
if [ -d "$OLD_HOME_DIR" ]; then
sudo rm -rf "$OLD_HOME_DIR"
fi
else
echo "Initial home directory $OLD_HOME_DIR does not exist for user $username"
fi
# Update the user's home directory path in /etc/passwd
sudo usermod -d "$NEW_HOME_DIR" "$username"
else
echo "Failed to add user: $username"
fi
}
add_and_move_user "core"
# Add a mentees_domain.txt file to core's home directory
sudo echo "name rollno domain" > /home/users/core/mentees_domain.txt
# Add core to root group
sudo usermod -aG root core
# Add groups
sudo groupadd mentors
sudo groupadd mentees