webinoly/weby
Cristhian Martínez Ochoa 7b89b1d98d small fix
better sudo/root check
2018-11-02 19:52:56 -07:00

152 lines
5.7 KiB
Bash

#!/bin/bash
# Webinoly Installation Script.
# Check OS support
distr=`echo $(lsb_release -i | cut -d':' -f 2)`
osver=`echo $(lsb_release -c | cut -d':' -f 2)`
if ! [[ $distr == "Ubuntu" && $osver =~ ^(xenial|bionic)$ ]]; then
echo "$(tput setaf 1)"
echo "****************************************************************************"
echo "**** This OS is not supported by Webinoly and could not work properly ****"
echo "****************************************************************************"
echo "$(tput sgr0)"
read -p "Press [Enter] key to Continue or [Ctrl+C] to Cancel..."
fi
# Check for sudo/root privileges
if ! $(groups $USERNAME | grep &>/dev/null '\bsudo\b' || groups $USERNAME | grep &>/dev/null '\broot\b'); then
echo "$(tput setaf 1)"
echo "**** [ERROR] sudo/root privileges are required to install Webinoly ****"
echo "$(tput sgr0)"
read -p "Press [Enter] key to Continue or [Ctrl+C] to Cancel..."
fi
# In case client is just Updating Webinoly and not fresh-installing we need accurate statistics.
[[ -n "$1" ]] && setup="$1" || setup=9
if [[ $setup == "upd" ]]; then
setup=0
update="&update=true"
else
update=""
fi
# Diplay menu to select type of server
while ! [[ $setup -ge 0 && $setup -le 3 && $setup =~ ^[0-9]+$ ]] 2>/dev/null
do
echo ""
echo " 1 - HTML Server"
echo " 2 - PHP Server"
echo " 3 - LEMP Server (Default)"
echo " 0 - Maybe later..."
echo ""
read -p "Select the desired option to configure your server: " setup
echo ""
echo "------------------------------------------------"
setup=${setup:-3}
done
# Download and install Webinoly
if [[ $2 == "-ver="* ]]; then
ver=$(echo "$2" | cut -d'=' -f 2 -s)
# Skip stadistics counters for dev and testing (custom version stats).
if [[ $(echo "${ver}" | rev | cut -c-1) == "*" || $ver == "alpha" ]]; then
ver=${ver//'*'}
statskip="true"
fi
# Be sure we have a valid server response for the requested version
code=$(wget --server-response --spider https://qrok.es/webinoly?version=$ver 2>&1 | awk '/^ HTTP/{print $2}')
# Get the last code (redirections)
code="${code##*$'\n'}"
echo "$(tput setaf 1)"
if [[ $code == 200 ]]; then
sudo wget --timeout=15 -t 1 -qrO $HOME/webinoly.tar https://qrok.es/webinoly?version=$ver
webyversion="$ver"
[[ $ver == "beta" ]] && echo "[WARNING] You are installing a BETA version of Webinoly and it's not recommended for production enviroments."
# Just for stadistics
[[ $statskip == "true" ]] || sudo wget --timeout=15 -t 1 --spider --referer="https://webinoly.com/?version=${ver}${update}" -q https://qrok.es/wyver
else
echo "[ERROR] Version not found or not available! ($code) $(tput sgr0)"
exit 1
fi
echo $(tput sgr0)
else
sudo wget --timeout=15 -t 1 --referer="https://webinoly.com/?option=${setup}${update}" -qrO $HOME/webinoly.tar https://qrok.es/wytar
fi
[[ ! -d /opt/webinoly ]] && sudo mkdir /opt/webinoly
sudo tar -xf $HOME/webinoly.tar -C /opt/webinoly
sudo find /opt/webinoly -type d -exec chmod 755 {} \;
sudo find /opt/webinoly -type f -exec chmod 644 {} \;
sudo chmod -f 744 /opt/webinoly/lib/ex-*
# Install plugins
sudo chmod 755 /opt/webinoly/plugins/*
sudo mv /opt/webinoly/plugins/* /usr/bin/
source /opt/webinoly/lib/install
# Check for uninstalled Webinoly conf file
if [[ -a $HOME/.webinoly-conf-restore_dont-remove ]]; then
echo "${gre}Seems like Webinoly was installed previously, we will try to recover your old configuration!${end}"
sudo mv $HOME/.webinoly-conf-restore_dont-remove /opt/webinoly/webinoly.conf
sudo webinoly -verify
[[ $? == 1 ]] && exit 1
fi
# Check for Server Conf Updates and Save Tools Port after library is available.
if [[ -a /opt/webinoly/webinoly.conf ]]; then
echo "${gre}Webinoly Configuration file was found, so we will use it!${end}"
# svr_version function was created at the same time as the first update of server-version. Not check before!
if declare -F svr_version > /dev/null 2>&1; then
newver=$(svr_version)
oldver=$(conf_read server-version)
[[ -n $oldver && ${newver//.} -gt ${oldver//.} ]] && source /opt/webinoly/lib/update
fi
else
[[ -n $2 && $2 != "-ver="* ]] && tools_port $2
# Compatibility with old versions - before v1.4.1 we used to declare the tools_port here.
[[ $2 == "-ver="* && webyversion == $ver && ${ver//.} -le 140 ]] && tools_port 22222
newinst="true"
fi
# Write app version
declare -F app_version > /dev/null 2>&1 && webyversion=$(app_version)
[[ -z $webyversion ]] && webyversion="undetermined"
conf_write app-version $webyversion
# Stack installation
[[ $setup -gt 0 && $setup -le 3 ]] && stack -nginx
[[ $setup -gt 1 && $setup -le 3 ]] && stack -php
[[ $setup == 3 ]] && stack -mysql
# Message Center
if [[ $newinst == "true" && $setup == 0 ]]; then
echo "${blu}You have chosen the option '0', it means that you have to manually build your own stack."
echo "But, don't worry! With Webinoly this is an easy task, just use the stack command, i.e. 'sudo stack -lemp'"
echo "${gre}"
echo "Webinoly has been successfully installed!!!"
fi
echo "${blu}"
echo "****************************************************************************"
echo "********************** D O N A T I O N S ***************************"
echo "*** If you like Webinoly, buy me a coffee or a beer to show support. ***"
echo "****************************************************************************"
echo "********** Bitcoin: 1E3Ybo5UcvaAr1MoK4nBnMRFFY9aEMiku3 *************"
echo "************ PayPal: https://www.paypal.me/qrokes *******************"
echo "****************************************************************************"
echo "*** Your regular donations is what keep this project moving forward. ***"
echo "****************************************************************************"
echo "${end}"
# Remove Installation File
sudo rm weby
app_purge