-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createserverhost
71 lines (65 loc) · 2.48 KB
/
createserverhost
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
#!/bin/bash
# By Adam ELAOUMARI under GNU General Public License v3.0
# Contact : adam[at]admlbs.fr
# Mosts comments are in french. If you have questions just e-mail me
LATEST_VERSION=$(curl -s 'https://uploads.admlbs.fr/version_apache')
ACTUAL_VERSION=1.1
SCRIPT_NAME=""
NEW_FILE=""
updater_check () {
if [ "$ACTUAL_VERSION" == "$LATEST_VERSION" ]
then echo "Already last version."
else
read -p "You do not have the latest version of the program. We advise you to update it as soon as possible. Type y to start the update. (y or n)" doit
case $doit in
n|N) echo -e "You refused to update the program." && exit ;;
y|Y) echo -e "\e[32mLoading updater.\e[0m" ;;
*) echo "Please type y (yes) or n (no)" && exit ;;
esac
curl --output
check_upgrade
fi
}
check_upgrade () {
[ -f "$NEW_FILE" ] && {
cp "$NEW_FILE" "$SCRIPT_NAME"
chmod 0777 "$SCRIPT_NAME"
rm -f "$NEW_FILE"
clear
echo "The script have been updated"
exit 0
}
}
#updater_check
SERVERHOSTURL=$(whiptail --title "Web Server Installer" --inputbox "What's the URL of the server host you want to add ? " 10 60 3>&1 1>&2 2>&3)
DIRECTORY=$(whiptail --title "Web Server Installer" --inputbox "Where are located the files of your new server host ? Example : /var/www/html. If this directory does not exist, the script will create the directory" 10 60 3>&1 1>&2 2>&3)
whiptail --title "Web Server Installer" --yesno "Here's the summary of your virtual host : Is that okay for you?
URL : $SERVERHOSTURL
DIRECTORY : $DIRECTORY" 20 80
installdone=$?
if [ $installdone = 0 ];
then
echo "everything's fine then, i'm working on your server host"
else
bash createserverhost.bash
fi
#cp /usr/bin/webserverinstaller /etc/apache2/sites-available/$SERVERHOSTURL.conf
#sed -i "s/example.com/$SERVERHOSTURL /g" /etc/apache2/sites-available/$SERVERHOSTURL.conf
#sed -i 's|var/www/example|$DIRECTORY|g' /etc/apache2/sites-available/$SERVERHOSTURL.conf
if cd $DIRECTORY 2> /dev/null; then echo " " ; else echo -e "\e[32mThe folder does not exist therefore it has been created.\e[0m" && mkdir -p $DIRECTORY ; fi
echo "#### $SERVERHOSTURL
<VirtualHost *:80>
ServerName $SERVERHOSTURL
DocumentRoot "$DIRECTORY"
<Directory $DIRECTORY>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>" > /etc/apache2/sites-available/$SERVERHOSTURL.conf
a2ensite $SERVERHOSTURL
service apache2 restart
clear
echo "Done. $SERVERHOSTURL is online."