-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewUser.sh
More file actions
executable file
·89 lines (64 loc) · 1.62 KB
/
newUser.sh
File metadata and controls
executable file
·89 lines (64 loc) · 1.62 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
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
set -eu
servn='clubisen.fr'
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root"
exit 1
fi
if [ "$#" -ne 1 ]; then
echo "Usage : ./newUser username"
exit 1
fi
userDir='/home/'$1'/www/'
if id -u "$1" >/dev/null 2>&1; then
echo "user already exists"
exit 1
fi
echo "Creating user "$1"..."
useradd --create-home --skel=/etc/skel --shell=/bin/bash $1
echo "Creating home directory "$userDir" ..."
mkdir -p $userDir
read -p 'Clone git repo (optional): ' cloneUrl;
if [ ! -z "$cloneUrl" ]
then
git clone $cloneUrl $userDir
else
echo "Creating default index ..."
echo $1 > $userDir/index.html
fi
chown -R $1:www-data $userDir
chmod -R '644' $userDir
mkdir /var/log/apache2/$1/
echo "#### Virtual Host pour "$1.$servn"
<VirtualHost *:80>
ServerName $servn
ServerAlias $1.$servn
DocumentRoot $userDir
<Directory $userDir>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
CustomLog /var/log/apache2/$1/access.log combined
ErrorLog /var/log/apache2/$1/error.log
</VirtualHost>" > /etc/apache2/sites-available/$1.$servn.conf
if [ ! -f /etc/apache2/sites-available/$1.$servn.conf ]
then
echo "Virtual host wasn't created !"
exit 1
else
echo "Virtual host created !"
fi
echo "Creating symbolic link"
/bin/ln -s /etc/apache2/sites-available/$1.$servn.conf /etc/apache2/sites-enabled/$1.$servn.conf
echo "Restarting apache2 ..."
/etc/init.d/apache2 restart
apacheStatus=$(ps -ef | grep apache2 | grep -v grep)
if [ -z "$apacheStatus" ]
then
echo "Apache2 is not started"
exit 1
fi
echo "Apache 2 started !"
exit 0