-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateUser
More file actions
executable file
·115 lines (84 loc) · 3.43 KB
/
createUser
File metadata and controls
executable file
·115 lines (84 loc) · 3.43 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
INSTALL_PATH=/usr/local/createUser
SITEHOME_PATH=/usr/www
SKELETON_PATH=/etc/website_account_skeleton
VSFTPD_PATH=/etc/vsftpd
NGINXSA_PATH=/etc/nginx/sites-available
NGINXSE_PATH=/etc/nginx/sites-enabled
PHPFPM_PATH=/etc/php-fpm
HOSTNAME=$(/bin/hostname)
VER=$2
if test "$VER" == "" ; then
read -p "You did not supply 2nd argument, defaulting to PHP5.3 - Are you sure you want to proceed? " -n 1 -r
if [[ $REPLY =~ ^[Nn]$ ]] ; then
exit 2
fi
VER=php53
fi
if test "$1" == "" ; then
/bin/echo $'\a'Domain is required, e.g: $0 example.com
exit 1
fi
if [ -d "$SITEHOME_PATH/$1" ] ; then
/bin/echo $'\a'Home dir create would fail
exit 1
fi
/usr/bin/id $1 &> /dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
/bin/echo $'\a'User already exists
exit 1
fi
/usr/sbin/useradd -b $SITEHOME_PATH -s /sbin/nologin -k $SKELETON_PATH -m $1
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
/bin/echo $1 >> $VSFTPD_PATH/user_list
/bin/echo $1 >> $VSFTPD_PATH/chroot_list
/bin/sed s/TEMPLATE/$1/ $INSTALL_PATH/nginx-templates/template.conf > $NGINXSA_PATH/$1.conf
/bin/ln -s $NGINXSA_PATH/$1.conf $NGINXSE_PATH/
IPADDR=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
/bin/sed -i s/IPADDRESS/$IPADDR/ $NGINXSA_PATH/$1.conf
/bin/sed -i s/HOSTNAME/$HOSTNAME/ $NGINXSA_PATH/$1.conf
if test "$VER" == "php54" ; then
/bin/sed s/TEMPLATE/$1/ $INSTALL_PATH/php-fpm-templates/template.54.conf > $PHPFPM_PATH/php.$1.conf
/bin/sed s/TEMPLATE/$1/ $INSTALL_PATH/init-script-templates/template.54.init > /etc/init.d/php.$1
fi
if test "$VER" == "php53" ; then
/bin/sed s/TEMPLATE/$1/ $INSTALL_PATH/php-fpm-templates/template.53.conf > $PHPFPM_PATH/php.$1.conf
/bin/sed s/TEMPLATE/$1/ $INSTALL_PATH/init-script-templates/template.53.init > /etc/init.d/php.$1
fi
if test "$VER" == "php52" ; then
/bin/sed s/TEMPLATE/$1/ $INSTALL_PATH/php-fpm-templates/template.52.conf > $PHPFPM_PATH/php.$1.conf
/bin/sed s/TEMPLATE/$1/ $INSTALL_PATH/init-script-templates/template.52.init > /etc/init.d/php.$1
fi
if [ $(find $PHPFPM_PATH -type f -name "*.conf" | wc -l) > "0" ] ; then
CURRPORT=$(/bin/grep -ho ':9[[:digit:]]*' $PHPFPM_PATH/*.conf | sort | tail -n1 | awk -F: '{print $2}')
fi
if [ "$CURRPORT" = "" ] ; then
CURRPORT=9000
fi
NEXTPORT=$(($CURRPORT + 1))
/bin/sed -i s/PORT/$NEXTPORT/ $PHPFPM_PATH/php.$1.conf
/bin/sed -i s/PORT/$NEXTPORT/ $NGINXSA_PATH/$1.conf
/bin/sed -i s/TEMPLATE/$1/ $SITEHOME_PATH/$1/web/index.html
/bin/chmod +x /etc/init.d/php.$1
/bin/chmod og+rx $SITEHOME_PATH/$1
/sbin/chkconfig php.$1 on
/sbin/service php.$1 start
/sbin/service nginx reload
/sbin/service vsftpd reload
PASS=$(/usr/bin/mkpasswd $1)
DBNAME=${1//[^a-zA-Z0-9_]/}
DBNAME=${DBNAME:0:12}
/bin/mkdir $SITEHOME_PATH/$1/.ssh
/bin/chmod 700 $SITEHOME_PATH/$1/.ssh
/usr/bin/ssh-keygen -t rsa -b 4096 -N "" -f $SITEHOME_PATH/$1/.ssh/$1.key
/bin/chown -R $1: $SITEHOME_PATH/$1/.ssh
/usr/bin/mysql -uroot mysql -e "CREATE DATABASE $DBNAME"
/usr/bin/mysql -uroot mysql -e "GRANT ALL PRIVILEGES ON $DBNAME.* TO '$DBNAME'@'localhost' IDENTIFIED BY '$PASS'"
/bin/echo $'\a'Added MySQL database $DBNAME | tee -a $SITEHOME_PATH/$1/createUser.log
/bin/echo $'\a'Added MySQL user $DBNAME with password $PASS | tee -a $SITEHOME_PATH/$1/createUser.log
/bin/echo $'\a'Added System user $1 with password: $PASS | tee -a $SITEHOME_PATH/$1/createUser.log
exit 0
fi
exit 1