-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·162 lines (142 loc) · 3.65 KB
/
install.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
print_usage(){
echo "Arguments : "
echo "[-s|--web-server] 'Apache'|'Nginx'"
echo "[-u|--update-packages]"
echo "[-a|--add-site] (config_files)"
}
#### STATIC VALUES #####
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
CURRENT_USER=$(who | awk 'NR==1{print $1}')
available_srv=(Apache Nginx)
# Loop though arguments
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
print_usage
exit 0;;
-s|--web-server)
if [[ $2 == -* ]]; then echo "Invalid [-s|--web-server] parameter"; exit 0; fi
if [[ ! "${available_srv[@]}" =~ "${2}" ]]; then echo -e "Only ${RED}Apache${NC} and ${RED}Nginx${NC} are possible as [-s|--web-server] parameter"; exit 0; fi
WEB_SERVER="$2"
shift 2;;
--secure)
SECURE=true
shift;;
-u|--update-packages)
UPDATE_PKG=true
shift;;
-a|--add-site)
shift
arr=("$@")
for item in "${arr[@]}";
do
if [[ $item == -* ]]; then break; fi
if [[ $item == *.conf ]]; then CONFIG_FILE+=($item); fi
done
shift ${#CONFIG_FILE[@]};;
*)
shift;;
esac
done
echo "#### RESUMING OPTIONS ####"
echo "WEB_SERVER : " $WEB_SERVER
echo "UPDATE_PKG : " $UPDATE_PKG
echo "CONFIG_FILES : "
for file in "${CONFIG_FILE[@]}";
do
echo " > $file"
done
echo
echo "#### PROCESSING ####"
# Updating packages
if [ $UPDATE_PKG ];
then
echo "Updating Packages ..."
apt -qq update && apt -qq -y upgrade
fi
# Install WebServer & Firewall
if [ -n "$WEB_SERVER" ];
then
echo "Installing $WEB_SERVER ..."
case $WEB_SERVER in
Apache)
./bin/apache.sh --install
./bin/setup-firewall.sh $WEB_SERVER $SECURE;;
Nginx)
./bin/nginx.sh --install
./bin/setup-firewall.sh $WEB_SERVER $SECURE;;
esac
fi
# Install SITES
for file in "${CONFIG_FILE[@]}";
do
source $file
echo
echo -e "installing ${GREEN}$DOMAIN${NC} ..."
echo "---> Creating folder"
mkdir -p $ROOT_PATH
# Clone Github
if $GITHUB;
then
echo "Cloning $GITHUB_REPO to $ROOT_PATH ..."
./bin/clone-github.sh -r $GITHUB_REPO -p $ROOT_PATH
fi
# Install Environnement
case $ENVIRONNEMENT in
NodeJS)
./bin/server-block.sh --add $WEB_SERVER --path $ROOT_PATH --domain $DOMAIN --proxy $PORT
./bin/nodejs.sh --install --start --path $ROOT_PATH;;
Wordpress)
./bin/server-block.sh --add $WEB_SERVER --path $ROOT_PATH --domain $DOMAIN
./bin/wordpress.sh --install --path $ROOT_PATH --domain $DOMAIN;;
Static)
./bin/server-block.sh --add $WEB_SERVER --path $ROOT_PATH --domain $DOMAIN
./bin/static.sh $ROOT_PATH;;
*)
echo -e "${RED}$ENVIRONNEMENT${NC} environnement not available"
echo -e "Aborting, evaluating next"
continue;;
esac
# Installing Additional Libraries (Mongoose|SQL)
# Updating packages
if [ $MONGOOSE ];
then
./bin/mongoose.sh --install --db-name $MONGOOSE_DB_NAME --user $MONGOOSE_USER --pass $MONGOOSE_PASSWORD
fi
#Setup Folder security
echo "---> Setting folder security"
chown -R $CURRENT_USER:$CURRENT_USER $ROOT_PATH
chmod -R 755 $ROOT_PATH
# Setup SSL Certificate
if $SSL;
then
echo -e "Setting up SSL for ${GREEN}$DOMAIN${NC} ..."
./bin/setup-ssl.sh $WEB_SERVER $DOMAIN
fi
# Start Environnement
case $ENVIRONNEMENT in
NodeJS)
echo "Starting NodeJS $ROOT_PATH"
./bin/nodejs.sh --start --path $ROOT_PATH;;
*)
echo "Nothing to start";;
esac
done
# Restarting WebServer
if [ -n "$WEB_SERVER" ];
then
echo "Restarting $WEB_SERVER ..."
case $WEB_SERVER in
Apache)
./bin/apache.sh --reload;;
Nginx)
./bin/nginx.sh --reload;;
esac
fi
echo "Done Installing."
./bin/server-info.sh