-
Notifications
You must be signed in to change notification settings - Fork 0
/
createwebsite
131 lines (97 loc) · 3.41 KB
/
createwebsite
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
USERNAME=""
PASSWORD=""
PASSWORD_CONFIRM=""
DOMAIN_NAME=""
VALID_DOMAIN=0
echo "Domain, website, user and database setup"
while [ ${#USERNAME} -lt 5 ]; do
read -p 'Username: ' USERNAME
done
while [ $VALID_DOMAIN -eq 0 ]; do
read -p "Domain name: " DOMAIN_NAME
host $DOMAIN_NAME 2>&1 > /dev/null
if [ $? -eq 0 ]; then
VALID_DOMAIN=1
fi
done
while ! echo "$PASSWORD" | grep -P '(?=^.{8,255}$)(?=^[^\s]*$)(?=.*\d)(?=.*[A-Z])(?=.*[a-z])'
do
read -sp "Please enter a complex password: " PASSWORD
done
read -sp 'Confirm Password: ' PASSWORD_CONFIRM
if [ "$PASSWORD" != "$PASSWORD_CONFIRM" ]; then
echo "Password didn't match"
exit
fi
# each user will have website
useradd -m $USERNAME -p $PASSWORD
if [ $? -ne 0 ]; then
echo "Failed to add user, quitting"
exit
fi
mkdir -vp /home/$USERNAME/www/
chown -Rv $USERNAME:$USERNAME /home/$USERNAME/www/.
echo "Creating /etc/apache2/sites-available/001-$DOMAIN_NAME.conf"
cat <<EOT >> /etc/apache2/sites-available/001-$DOMAIN_NAME.conf
<VirtualHost *:80>
ServerName $DOMAIN_NAME
ServerAlias *.$DOMAIN_NAME
ServerAdmin webmaster@$DOMAIN_NAME
DocumentRoot /home/$USERNAME/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
Allow from all
</Directory>
<IfModule mpm_itk_module>
# AssignUserId user group
AssignUserId $USERNAME $USERNAME
</IfModule>
</VirtualHost>
EOT
ln -v -s /etc/apache2/sites-available/001-$DOMAIN_NAME.conf /etc/apache2/sites-enabled/001-$DOMAIN_NAME.conf
systemctl restart apache2
echo "Creating mysql username and database"
cat <<EOT >> /tmp/$DOMAIN_NAME.sql
create database $USERNAME;
create user '$USERNAME'@'localhost' identified by '$PASSWORD';
grant all privileges on $USERNAME.* to '$USERNAME'@'localhost';
flush privileges;
EOT
mysql -u root < /tmp/$DOMAIN_NAME.sql
echo "Installing wordpress into /home/$USERNAME/www/"
wget https://wordpress.org/latest.tar.gz -O /tmp/latest.tar.gz
tar xzf /tmp/latest.tar.gz -C /tmp/
mv /tmp/wordpress*/* /home/$USERNAME/www/
mkdir /home/$USERNAME/www/wp-content/TEMP
find /home/$USERNAME/www/ -type d -exec chmod 775 {} \;
find /home/$USERNAME/www/ -type f -exec chmod 664 {} \;
chown -R $USERNAME:$USERNAME /home/$USERNAME/
cat <<EOT >> /usr/share/roundcube/config/$DOMAIN_NAME.inc.php
<?php
\$config['default_host'] = 'localhost';
\$config['username_domain'] = '$DOMAIN_NAME';
EOT
chown -R www-data:www-data /usr/share/roundcube/config/$DOMAIN_NAME.inc.php
echo "$DOMAIN_NAME" >> /etc/postfix/vhosts
echo "$DOMAIN_NAME OK" >> /etc/postfix/recipient_domains
echo "$USERNAME: $USERNAME" >> /etc/postfix/aliases
postalias
newaliases
postmap /etc/postfix/recipient_domains
postmap /etc/postfix/vhosts
sed -i "/^mydestination/ s/$/ $DOMAIN_NAME mail.$DOMAINNAME/" /etc/postfix/main.cf
systemctl restart postfix
echo "$DOMAIN_NAME" >> /etc/dkimkeys/TrustedHosts
echo "*.$DOMAIN_NAME" >> /etc/dkimkeys/TrustedHosts
echo "*@$DOMAIN_NAME default._dkim.$DOMAIN_NAME" >> /etc/dkimkeys/SigningTable
echo "default._dkim.$DOMAIN_NAME $DOMAIN_NAME:default:/etc/dkimkeys/keys/default.private" >> /etc/dkimkeys/KeyTable
chown -R opendkim:opendkim /etc/dkimkeys/
systemctl restart opendkim
echo "Update your dns now to include DNS records for DKIM/DMARC"
echo "Cleaning up"
rm -rf /tmp/*