all-bundled [rf1] installer

This commit is contained in:
Adrien Marquès 2018-06-10 18:10:24 +02:00
parent 683ef84ab3
commit bf01157cd9
1 changed files with 171 additions and 5 deletions

View File

@ -10,7 +10,28 @@
# git.xdrm.io # # git.xdrm.io #
#*************************# #*************************#
source ./format; S="20"
inline_progress(){
# 1. init arguments
text=""
size="$S"
sep=" "
# 2. extract text
test ! -z "$1" && text="$1";
# 3. extract size
test ! -z "$2" && test "`expr $2 + 0 2>/dev/null`" = "$2" && size="$2";
# 4. Write text
len="`echo -n \"$text\" | wc -m`";
echo -n "$text";
for i in `seq $len $size`; do echo -n "$sep"; done;
return;
}
@ -19,7 +40,6 @@ source ./format;
echo -e "\e[33m>\e[0m (1) required programs \e[33m<\e[0m" echo -e "\e[33m>\e[0m (1) required programs \e[33m<\e[0m"
requirements="curl git docker docker-compose make" requirements="curl git docker docker-compose make"
set_inline_progress_size "20";
for r in $requirements; do for r in $requirements; do
@ -128,9 +148,32 @@ else
http_installer=$(echo $candidates | awk "{print \$$install}") http_installer=$(echo $candidates | awk "{print \$$install}")
fi; fi;
echo;
echo "http_installer: $http_installer" # 5. configuration root dir
inline_progress " . config root";
http_root="/etc/$http_installer";
if [ -d "$http_root" ]; then
echo "ok";
else
echo "missing";
echo -e "\n\e[31m/!\\\\\e[0m cannot find configuration folder \e[33m$http_root\e[0m. aborting installation";
exit 1;
fi;
# 6. configuration structure
inline_progress " . config tree";
if [ -d "$http_root/sites-available" -a -d "$http_root/sites-enabled" ]; then
echo "ok";
else
echo "invalid";
echo -e "\n invalid configuration structure. You might have \e[33m$http_root/sites-available\e[0m containing";
echo -e "\e[31m/!\\\\\e[0m your configurations and $http_root/sites-enabled containing symbolic links";
echo -e " only for activated configurations. aborting installation";
exit 1;
fi;
# (4) information disclaimer # (4) information disclaimer
@ -165,12 +208,13 @@ echo -e " \e[34m(!)\e[0m the \e[34m<HOST>\e[0m \e[33mtest.google.co
# (5) prompt server variables # (5) prompt server variables
#--------------------------------------------------------# #--------------------------------------------------------#
echo; echo;
echo -e "\e[33m>\e[0m (5) variables \e[33m<\e[0m"; echo -e "\e[33m>\e[0m (5) redirection variables \e[33m<\e[0m";
# 1. Port # 1. Port
minport="1024" minport="1024"
maxport="49151" maxport="49151"
echo -e " * what port do you want docker to use ? (between $minport and $maxport)"; echo -e " * what port do you want docker to use ? (between $minport and $maxport)";
echo -e " ( values other than \e[33m8080\e[0m may be unstable )";
echo -en " \e[34m<PORT>\e[0m = "; echo -en " \e[34m<PORT>\e[0m = ";
read port; read port;
@ -193,4 +237,126 @@ if [ -z "$host" ]; then
echo; echo;
echo -e "\e[31m/!\\\\\e[0m invalid host. aborting installation" echo -e "\e[31m/!\\\\\e[0m invalid host. aborting installation"
exit 1; exit 1;
fi; fi;
# 3. Unlock permissions
echo -n " * sudo access ";
if sudo echo "granted"; then
echo -n "";
else
echo -e "\e[31m/!\\\\\e[0m permission issue. you must launch the installer with a sudoer. aborting installation"
exit 1;
fi;
# (6) pre-install: reverse-proxy
#--------------------------------------------------------#
echo;
echo -e "\e[33m>\e[0m (6) reverse proxy \e[33m<\e[0m";
# (1) LOCAL DNS #
inline_progress " . local dns";
# 1.1. remove previously generated + append new line
cat /etc/hosts | grep -vP "# generated by: ptut installer" > /tmp/installer_hosts;
echo -e "127.0.0.1\t$host\t# generated by: ptut installer" | sudo tee -a /tmp/installer_hosts >/dev/null;
sudo cp /etc/hosts /etc/hosts.backup;
sudo mv /tmp/installer_hosts /etc/hosts;
c2="$?";
# 1.2. manage errors
if [ "$c2" = "0" ]; then
echo "ok";
else
echo;
echo -e "\e[31m/!\\\\\e[0m cannot write to /etc/hosts. skipping this step."
fi;
inline_progress " * $http_installer"; echo;
# 1. Copy configuration
echo -n " - create proxy configuration ";
if [ "$http_installer" = "apache2" ]; then
echo """<VirtualHost *:80>
ServerName $host
ServerAlias www.$host
ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://127.0.0.1:$port/
ProxyPassReverse / http://127.0.0.1:$port/
</VirtualHost>""" | sudo tee $http_root/sites-available/$host.reverse-proxy > /dev/null;
elif [ "$http_installer" = "nginx" ]; then
echo """server {
listen 80;
server_name $host www.$host;
location / {
proxy_set_header Host \$host;
proxy_pass http://127.0.0.1:$port;
}
}""" | sudo tee $http_root/sites-available/$host.reverse-proxy > /dev/null;
fi;
# manage error
if [ "$?" = "0" ]; then
echo "ok";
else
echo "error";
echo -e "\n\e[31m/!\\\\\e[0m cannot write to $http_root/sites-availables/. aborting installation";
exit 1;
fi;
echo -n " - enable proxy ";
sudo ln -fs ../sites-available/$host.reverse-proxy $http_root/sites-enabled/$host.reverse-proxy;
echo "ok";
echo -n " - reload server ";
sudo systemctl is-active $http_installer || sudo systemctl start $http_installer;
sudo systemctl reload $http_installer;
echo "ok";
# (7) clone sources
#--------------------------------------------------------#
echo;
echo -e "\e[33m>\e[0m (7) fetching \e[33m<\e[0m";
# 1. Clone
inline_progress " . cloning";
git clone --recursive https://git.xdrm.io/ptut/virtenv.git $host;
if [ "$?" = "0" ]; then
echo "ok";
else
echo "error";
echo -e "\n\e[31m/!\\\\\e[0m cannot clone sources to ./$host. aborting installation";
exit 1;
fi;
# 2. Fetch database
inline_progress " . fetch data";
mkdir -p ./$host/metactl/persistent \
&& curl https://xdrm.io/script/ptut-database > ./$host/metactl/persistent/mariadb.sql;
if [ "$?" = "0" ]; then
echo "ok";
else
echo "error";
echo -e "\n\e[31m/!\\\\\e[0m cannot fetch data. aborting installation";
exit 1;
fi;
# (8) make installer
#--------------------------------------------------------#
echo;
echo -e "\e[33m>\e[0m (8) installer \e[33m<\e[0m";
make -C ./$host start;