#!/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)` # Check for custom version 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 fi # Supported: 22.04 Jammy and 20.04 Focal if [[ $distr != "Ubuntu" ]] || ! [[ $osver =~ ^(bionic|focal|jammy)$ ]]; then echo "$(tput setaf 1)" echo "[ERROR] This OS is not supported by Webinoly and could not work properly. $(tput dim)(${distr} '${osver}')" echo "$(tput sgr0)" sudo rm weby exit 1 # 18.04 Bionic can be installed before 1.17.0 elif [[ $osver == "bionic" && $1 != "upd" && -n $ver && $(echo ${ver//'*'} | sed 's/\.//g') =~ ^[0-9]+$ && $(echo ${ver//'*'} | sed 's/\.//g') -ge 1170 ]]; then echo "$(tput setaf 1)" echo "[ERROR] Ubuntu 18.04 is not supported on this version of Webinoly!" echo "$(tput sgr0)" sudo rm weby exit 1 elif [[ $osver == "bionic" && $1 != "upd" && -n $ver && $(echo ${ver//'*'} | sed 's/\.//g') =~ ^[0-9]+$ && $(echo ${ver//'*'} | sed 's/\.//g') -lt 1170 ]]; then echo "$(tput setaf 1)" echo "[WARNING] You should consider a newer Ubuntu version! $(tput dim)(20.04 or 22.04 are recommended instead)" echo "$(tput sgr0)" # 18.04 Bionic just for updates, no new installations after 1.17.0 elif [[ $osver == "bionic" && $1 != "upd" ]]; then echo "$(tput setaf 1)" echo "[ERROR] Ubuntu 18.04 is not supported for new installations! $(tput dim)(20.04 or 22.04 are recommended instead)" echo "$(tput sgr0)" sudo rm weby exit 1 # 22.04 Jammy is supported only after 1.16.6 elif [[ $osver == "jammy" && -n $ver && $(echo ${ver//'*'} | sed 's/\.//g') =~ ^[0-9]+$ && $(echo ${ver//'*'} | sed 's/\.//g') -lt 1166 ]]; then #jammy - 1.16.6 #focal - 1.12.0 #bionic - 1.4.2 echo "$(tput setaf 1)" echo "[ERROR] Ubuntu 22.04 (Jammy) is not supported by this version!" echo "$(tput sgr0)" sudo rm weby exit 1 fi # Check for sudo/root privileges if [[ $(whoami) != "root" ]]; then echo "$(tput setaf 1)Please run this script as root or using sudo.$(tput sgr0)" sudo rm weby exit 1 fi # Prevent "compulsive" re-installation, force the use of the 'update' command. if [[ -f /opt/webinoly/webinoly.conf && $1 != "upd" && $2 != "-ver=alpha" ]]; then echo "$(tput setaf 2)Webinoly is already installed on your server!" echo "$(tput setaf 6)To update use the proper command:$(tput dim) sudo webinoly -update $(tput sgr0)" sudo rm weby exit 0 elif [[ ! -f /opt/webinoly/webinoly.conf && $1 == "upd" ]]; then echo "$(tput setaf 1)Webinoly cannot be updated because it's not installed or not found.$(tput sgr0)" sudo rm weby exit 0 fi # Diplay menu to select type of server if [[ $1 == "upd" ]]; then setup=0 update="&update=true" elif [[ $1 == "-clean" ]]; then setup=0 elif [[ $1 == "-nginx" ]]; then setup=1 elif [[ $1 == "-php" ]]; then setup=2 elif [[ $1 == "-lemp" ]]; then setup=3 elif [[ -z $1 ]]; then setup=3 elif ! [[ $1 -ge 0 && $1 -le 3 && $1 =~ ^[0-9]+$ ]]; then echo "$(tput setaf 6)" echo " 1 - HTML Server" echo " 2 - PHP Server" echo " 3 - LEMP Server (Default)" echo " 0 - Clean (Only app)" echo "" read -p "$(tput setaf 2)Select the desired option to configure your server: $(tput sgr0)" setup echo "" setup=${setup:-3} [[ $setup -ge 0 && $setup -le 3 && $setup =~ ^[0-9]+$ ]] || setup=0 else setup=$1 fi # Download and install Webinoly if [[ -n $ver ]]; then # 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}') code="${code##*$'\n'}" # Get the last code (redirections) if [[ $code == 200 ]]; then sudo wget --timeout=15 -t 1 -qrO $HOME/webinoly.tar https://qrok.es/webinoly?version=$ver [[ $ver == "beta" ]] && echo "$(tput setaf 1)[WARNING] You are installing a BETA version of Webinoly and it's not recommended for production enviroments.$(tput sgr0)" type="Custom" else echo "$(tput setaf 1)[ERROR] Version not found or not available! ($code) $(tput sgr0)" sudo rm weby exit 1 fi else sudo wget --timeout=15 -t 1 --referer="https://webinoly.com/?option=${setup}${update}" -qrO $HOME/webinoly.tar https://qrok.es/wytar fi if [[ ! -s $HOME/webinoly.tar ]]; then echo "$(tput setaf 1)[ERROR] Downloading Webinoly failed!$(tput sgr0)" sudo rm weby exit 1 else echo "$(tput dim)Downloading... Successful!" echo "$(tput sgr0)" fi sudo mkdir -p /opt/webinoly sudo tar -xf $HOME/webinoly.tar -C /opt/webinoly sudo mkdir -p /opt/webinoly/templates/source 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-* sudo chmod 755 /opt/webinoly/usr/* sudo mv /opt/webinoly/usr/* /usr/bin/ source /opt/webinoly/lib/general # Check for uninstalled Webinoly conf file if [[ -f $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 tar -Pxf $HOME/.webinoly-conf-restore_dont-remove -C / sudo rm -rf $HOME/.webinoly-conf-restore_dont-remove sudo webinoly -verify=critical fi # Check if new installation if [[ -f /opt/webinoly/webinoly.conf ]]; then oldapp=$(conf_read app-version) oldver=$(conf_read server-version) newver=$svr_version echo "${gre}${dim}Webinoly Configuration file was found, so we will use it!${end}" # Reinstall after uninstalled! (Can be considered new) if [[ -z $update ]] && ! [[ $ver =~ ^(alpha|beta)$ ]]; then new_install="true" echo "${blu}${dim}It seems like you're reinstalling Webinoly! (Upgrading from: ${oldapp})${end} ${blu}${bol}Welcome back!!!${end}" # Downgrade! elif [[ -n $update && $type == "Custom" ]]; then echo "${blu}Updating to the latest version is always recommended! ${dim}(Downgrade to: ${ver})${end}" fi elif [[ $type == "Custom" ]]; then echo "${blu}Custom version installed: ${ver}${end}" else new_install="true" fi # Write app version webyversion=$app_version conf_write app-version $webyversion if [[ $ver =~ ^(alpha|beta)$ ]]; then conf_write branch $ver echo "${blu}${bol}This is a testing version, please don't use it in production!${end}" fi # Ping to Webinoly Stats if [[ $statskip != "true" ]]; then opt=$setup branch="Public" if [[ $new_install == "true" ]]; then type="New" elif [[ $ver == "beta" ]]; then type="Beta" elif [[ -n $update && $type == "Custom" ]]; then type="Downgrade" webyversion=$(wget --timeout=10 -t 1 -qO- https://api.webinoly.com/check?text=true) opt=$ver elif [[ -n $update && -n $oldapp ]]; then type="Updates" opt=$oldapp elif [[ $type == "Custom" ]]; then webyversion=$(wget --timeout=10 -t 1 -qO- https://api.webinoly.com/check?text=true) opt=$ver else type="Error" conf_write init-error-flag true echo "${red}[ERROR] Installation method not recognized!${end}" fi wget https://api.webinoly.com/stats/?install=${branch}:${webyversion}:${type}:${opt} --referer="Webinoly-Internal-Verified-Stats" --spider --timeout=15 -t 1 -q fi # Update stack! [[ -n $oldver && ${newver//.} -gt ${oldver//.} ]] && source /opt/webinoly/lib/update [[ -f /usr/bin/duply && -f /opt/webinoly/templates/general/duply ]] && sudo cp /opt/webinoly/templates/general/duply /usr/bin/ && sudo chmod 755 /usr/bin/duply # Stack installation [[ $setup == 1 ]] && stack -nginx [[ $setup == 2 ]] && stack -php=nginx [[ $setup == 3 ]] && stack -lemp # Verify installation! if [[ $setup != [123] && -n $update && -n $oldapp ]]; then sudo webinoly -verify=critical -check-for-updates elif [[ $setup != [123] ]]; then sudo webinoly -verify=critical fi # Message Center if [[ -z $(conf_read stack-build-error-flag) && $type != "Error" ]]; then # We use $type instead of dynvar to not make it persistant! if [[ $new_install == "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' ${end}" fi if [[ -z $update ]]; then echo "" echo "${blu}${bol}Don't like our defaults? Every part of Webinoly is overridable!${end}" echo "${blu}- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " echo "${blu}Please, read the documentation:${end}${dim} https://webinoly.com/documentation/${end}" echo "${blu}Be sure your firewall ports are correctly set:${end}${dim} https://webinoly.com/install/${end}" echo "${blu}Configuration file is here:${end}${dim} /opt/webinoly/webinoly.conf${end}" echo "" fi [[ $setup == 0 ]] && echo "${gre}${dim}Webinoly has been successfully installed!!!${end}" [[ $setup == 1 ]] && echo "${gre}${dim}Nginx and some other useful tools have been installed successfully! ${end}" [[ $setup == 2 ]] && echo "${gre}${dim}Nginx, PHP and some other useful tools have been installed successfully! ${end}" [[ $setup == 3 ]] && echo "${gre}${dim}Nginx, PHP, MySQL (MariaDB) and some other useful tools have been installed successfully! ${end}" echo "${blu}" echo "****************************************************************************" echo "************************ D O N A T I O N S *************************" echo "*** ${bol}If you like Webinoly, buy me a coffee or beer to show support.${end}${blu} ***" echo "****************************************************************************" echo "************* Bitcoin: ${end}${dim}1E3Ybo5UcvaAr1MoK4nBnMRFFY9aEMiku3 ${end}${blu}**********" echo "******* GitHub Sponsors:${end}${dim} https://github.com/sponsors/QROkes ${end}${blu}**********" echo "*************** PayPal:${end}${dim} https://www.paypal.me/qrokes ${end}${blu}****************" echo "****************************************************************************" echo "*** ${end}${dim}Your regular donations is what keep this project moving forward.${end}${blu} ***" echo "****************************************************************************" echo "${end}" else echo "${red}[ERROR] Sorry, unexpected error during installation and building stack process!${end}" fi # Remove Installation File sudo rm weby app_purge