-
Notifications
You must be signed in to change notification settings - Fork 0
/
personalize.sh
executable file
·67 lines (56 loc) · 2.04 KB
/
personalize.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
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
#
# Personalize the Node.JS Appliance by adding a new user account, generate
# openssh server keys if they don't exist and creating ~/.ssh/authorized_keys
MINPARAMS=3
if [ $# -lt $MINPARAMS ]; then
echo "%LARB-F-USAGE; Usage is:"
echo "; personalize.sh <Full Name> <Login Name> <Password>"
echo "; where:"
echo "; Full Name - the user's given name"
echo "; Login Name - the user's unix login name"
echo "; Password - the user's password."
exit 1
fi
FULLNAME=$1
USERNAME=$2
PASSWORD=$3
if [ ! -e /etc/ssh/ssh_host_dsa_key ]; then
echo "%LARB-I-OPENSSH; Generating new openssh server keys."
/usr/sbin/dpkg-reconfigure openssh-server
fi
echo "%LARB-I-UNIX; Adding Unix account for $USERNAME."
echo "$PASSWORD
$PASSWORD
" | /usr/sbin/adduser --gecos "$FULLNAME" --add_extra_groups $USERNAME
echo "%LARB-I-SAMBA; Adding Samba account for $USERNAME."
echo "$PASSWORD
$PASSWORD
" | /usr/bin/smbpasswd -a -s $USERNAME
if [ ! -e /home/$USERNAME/.ssh ]; then
echo "%LARB-I-SSHDIR; Creating user's ~/.ssh directory."
mkdir /home/$USERNAME/.ssh
chown $USERNAME /home/$USERNAME/.ssh
chgrp $USERNAME /home/$USERNAME/.ssh
chmod 700 /home/$USERNAME/.ssh
fi
echo "%LARB-I-LINKING; Adding symbolic links for nile and amazon."
if [ -L /etc/nginx/sites-enabled/nile.conf ]; then
rm /etc/nginx/sites-enabled/nile.conf
fi
ln -s /home/$USERNAME/Projects/nile/nile.conf /etc/nginx/sites-enabled/nile.conf
if [ -L /etc/nginx/sites-enabled/amazon.conf ]; then
rm /etc/nginx/sites-enabled/amazon.conf
fi
ln -s /home/$USERNAME/Projects/amazon/amazon.conf /etc/nginx/sites-enabled/amazon.conf
if [ -L /var/www/amazon ]; then
rm /var/www/amazon
fi
ln -s /home/$USERNAME/Projects/amazon/static /var/www/amazon
echo "%LARB-I-AUTHKEY; Adding authorized key to user's ~/.ssh/authorized_keys."
tr -d '\n\r' >> /home/$USERNAME/.ssh/authorized_keys
chown $USERNAME /home/$USERNAME/.ssh/authorized_keys
chgrp $USERNAME /home/$USERNAME/.ssh/authorized_keys
chmod 600 /home/$USERNAME/.ssh/authorized_keys
echo "%LARB-S-W00T; Personalization process completed."
exit 0