-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathaddb52user.sh
More file actions
executable file
·66 lines (57 loc) · 2.84 KB
/
addb52user.sh
File metadata and controls
executable file
·66 lines (57 loc) · 2.84 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
#!/bin/sh
# Xavier de Pedro Puente - UEB-VHIR
# http://ueb.vhir.org
# Check that the script is run as root (or with sudo)
if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root (run with sudo, for instance)" ; exit 1 ; fi
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize our own variables:
new_username=""
verbose=0
while getopts "h?vn:" opt; do
case "$opt" in
h|\?)
echo "Tip: Run this script with the username as argument. I.e., for user foo.bar, run the script as 'sudo sh addb52user.sh foo.bar'"
exit 0
;;
v) verbose=1
echo "Tip: You can also specify the new user with the argument '-n foo.bar' (i.e. 'sudo sh addb52user.sh -n foo.bar')"
echo "verbose=$verbose, new_user='$new_username', Leftovers: $@"
;;
n) new_username=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
newuser="$@"
# Check that there was a username provided as an argument in the command run
if [[ $newuser == "" ]] ; then echo "You need to specify the username you want to create. Read the help info with 'sudo addb52user.sh -h'" ; exit 1 ; fi
adduser $newuser --force-badname
echo "* System user created..."
newuserid=$(tail -1 /etc/passwd | gawk -F ':' '{print $3}')
echo "export LIBGL_ALWAYS_INDIRECT=yes" >> /home/$newuser/.bashrc
echo "export PATH=$PATH:/usr/local/stata" >> /home/$newuser/.bashrc
echo "* His/her .bashrc tweaked..."
cd /home/ueb/scripts/templates4systemusers;cp --parents Desktop/*.desktop /home/$newuser/;cd ~
echo "* Desktop shortcuts added..."
cd /home/ueb/scripts/templates4systemusers;cp --parents .b52/* /home/$newuser/;cd ~
echo "* Desktop icon and background files copied to the "$newuser" folders..."
cd /home/ueb/scripts/templates4systemusers;cp --parents .config/lxsession/LXDE/autostart /home/$newuser/;cd ~
echo "* Keyboard fixed..."
cd /home/ueb/scripts/templates4systemusers;cp --parents .config/pcmanfm/LXDE/*.conf /home/$newuser/;cd ~
echo "* Desktop background changed..."
sed -i -e "s/foo.bar/$newuser/g" /home/$newuser/Desktop/*.desktop
sed -i -e "s/foo.bar/$newuser/g" /home/$newuser/.b52/*.svg
sed -i -e "s/foo.bar/$newuser/g" /home/$newuser/.config/pcmanfm/LXDE/*.conf
echo "* Fixed paths and name for "$newuser" in desktop icons and background..."
cd /home/$newuser/;chown $newuser:$newuser Desktop Desktop/* -R;cd ~
cd /home/$newuser/;chown $newuser:$newuser .config .config/* -R;cd ~
echo "* Ownership and permissions of new folders and files fixed..."
cd /home/;chmod 770 $newuser;cd ~
echo "* Enforced privacy on user's home folder (new perms: 770)..."
echo "* uid number of this new user: "$newuserid
echo "...remember to create this user in other servers or computers sharing the same /home with the command:"
echo "sudo adduser --uid "$newuserid" --gid "$newuserid" "$newuser
echo "...We are done! :-)"
# End of file