From 0bf44f55cca2021c2b5047549df73fc24c42d14b Mon Sep 17 00:00:00 2001 From: Roen Wainscoat <13713430+roenw@users.noreply.github.com> Date: Thu, 10 Sep 2020 20:33:17 -1000 Subject: [PATCH] Install script restart pihole-FTL, created bash update script --- install.sh | 25 ++++---- update.sh | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+), 11 deletions(-) create mode 100644 update.sh diff --git a/install.sh b/install.sh index 8ad7be0..e67ef1d 100644 --- a/install.sh +++ b/install.sh @@ -128,15 +128,9 @@ move_to_latest_tag() { printf "${SYM_CHECK} Latest stable version $VERSION checked out.\\n" } -copy_sample_config() { - CFPATH=${WEBROOT}config.php - if test -f "$CFPATH"; then - printf "${SYM_INFO} ${CL_YELLOW}WARN:${CL_BLANK} The config file ${CFPATH} already exists and we do not want to overwrite it. Please manually copy the default to that path if you want to use the new version.\\n" - else - CFDEPATH=${WEBROOT}config-sample.php - sudo cp ${CFDEPATH} ${CFPATH} - printf "${SYM_CHECK} Installed a new default configuration file.\\n" - fi +restart_pihole_ftl() { + printf "${SYM_INFO} Restarting pihole-FTL.service. This shouldn't take long.\\n" + sudo pihole restartdns } if [[ $EUID -ne 0 ]]; then @@ -179,8 +173,6 @@ else exit; fi -copy_sample_config; - if [[ $(ps aux | grep -v 'grep' | grep ${PHPUSER}) ]]; then printf "${SYM_INFO} We think that the php user is ${PHPUSER}, but this is just a guess. Please update the PHPUSER variable in this file if this is wrong.\\n" else @@ -219,6 +211,17 @@ else ERR=true fi +while true; do + printf "\\n" + read -p "To complete installation, pihole-FTL.service should be restarted. Is this ok? [Y/n] " yn + case $yn in + [Yy]* ) restart_pihole_ftl; break;; + [Nn]* ) break;; + * ) restart_pihole_ftl; break;; + esac +done + + if [ -z ${ERR} ]; then printf "${SYM_CHECK}${CL_GREEN} PiPass installation completed without significant errors.\\n" else diff --git a/update.sh b/update.sh new file mode 100644 index 0000000..d0efb65 --- /dev/null +++ b/update.sh @@ -0,0 +1,170 @@ +#!/bin/bash +# PiPass installer for v>=1.3.5 + +CL_BLANK='\e[0m' +CL_GREEN='\e[1;32m' +CL_RED='\e[1;31m' +CL_YELLOW='\e[1;93m' +SYM_CHECK="[${CL_GREEN}✓${CL_BLANK}]" +SYM_X="[${CL_RED}✗${CL_BLANK}]" +SYM_QUESTION="[${CL_YELLOW}?${CL_BLANK}]" +SYM_INFO="[i]" + +# Global variables + +PKGMAN=apt +WEBROOT=/var/www/html/ +BLOCKPAGE_REPO_URL=https://github.com/pipass/blockpage.git + +# Function declarations + +command_exists() { + local check_command="$1" + command -v "${check_command}" >/dev/null 2>&1 +} + +update_system() { + get_package_manager() { + if command_exists apt; then + PKGMAN=apt + elif command_exists dnf; then + PKGMAN=dnf + else + printf "${SYM_INFO} ${CL_YELLOW}WARN:${CL_BLANK} We couldn't reliabliy determine your package manager. The installer will not attempt to install dependencies.\\n" + fi + } + + get_package_manager + if [ "$PKGMAN" = "apt" ]; then + sudo apt update > pipass-update-stdout.log 2> pipass-update-err.log; + sudo apt -y upgrade > pipass-update-stdout.log 2> pipass-update-err.log; + elif [ "$PKGMAN" = "dnf" ]; then + sudo dnf -y update > pipass-update-stdout.log 2> pipass-update-err.log; + fi +} + +dependencies_install() { + # git + if command_exists git; then + printf "\\n${SYM_CHECK} git is installed.\\n" + else + printf "\\n${SYM_X} git is not installed.\\n" + if [ "$PKGMAN" = "apt" ]; then + sudo apt install -y git > pipass-update-stdout.log 2> pipass-update-err.log; + elif [ "$PKGMAN" = "dnf" ]; then + sudo dnf install -y git > pipass-update-stdout.log 2> pipass-update-err.log; + fi + fi + + # php + if command_exists php; then + printf "${SYM_CHECK} php is installed.\\n" + else + printf "${SYM_X} php is not installed.\\n" + if [ "$PKGMAN" = "apt" ]; then + sudo apt install -y php php-curl > pipass-update-stdout.log 2> pipass-update-err.log; + elif [ "$PKGMAN" = "dnf" ]; then + sudo dnf install -y php php-curl > pipass-update-stdout.log 2> pipass-update-err.log; + fi + fi + + # php7.3/4-curl + if [ "$PKGMAN" = "apt" ]; then + if (apt list --installed | grep php-curl) > pipass-update-stdout.log 2> pipass-update-err.log; then + printf "${SYM_CHECK} php-curl is installed.\\n" + else + printf "${SYM_X} php-curl is not installed.\\n" + sudo apt install -y php-curl > pipass-update-stdout.log 2> pipass-update-err.log; + fi + + elif [ "$PKGMAN" = "dnf" ]; then + if dnf list installed | egrep "php7.3-curl|php-7.4-curl" > pipass-update-stdout.log 2> pipass-update-err.log; then + printf "${SYM_CHECK} php-curl is installed.\\n" + else + printf "${SYM_X} php-curl is not installed.\\n" + sudo dnf install -y php-curl > pipass-update-stdout.log 2> pipass-update-err.log; + fi + fi + + # curl + if command_exists curl; then + printf "${SYM_CHECK} curl is installed.\\n" + else + printf "${SYM_X} curl is not installed.\\n" + if [ "$PKGMAN" = "apt" ]; then + sudo apt install -y curl > pipass-update-stdout.log 2> pipass-update-err.log; + elif [ "$PKGMAN" = "dnf" ]; then + sudo dnf install -y curl > pipass-update-stdout.log 2> pipass-update-err.log; + fi + fi +} + +update_pipass() { + cd $WEBROOT + + # Copy config file + printf "${SYM_INFO} Making a copy of your current configuration file in case anything goes wrong.\\n" + sudo cp config.php config.update-backup.php + + # Remove old origin and add new + printf "${SYM_INFO} Re-adding git upstream since its URL was moved.\\n" + sudo git remote remove origin + printf "${SYM_CHECK} Removed old repository from system.\\n" + + sudo git remote add origin $BLOCKPAGE_REPO_URL + printf "${SYM_CHECK} Added new repository to system.\\n" + + sudo git reset --hard + printf "${SYM_CHECK} Forcibly removed local changes to source code and updated to current version tagged upstream copy.\\n" + + VERSION=$(curl https://raw.githubusercontent.com/PiPass/bin/master/currentversion) + printf "${SYM_INFO} The latest stable version is $VERSION.\\n" + + printf "${SYM_INFO} Downloading lastest source code from upstream.\\n" + sudo git pull origin master + printf "${SYM_CHECK} Downloaded complete.\\n" + + sudo git checkout tags/v$VERSION + printf "${SYM_CHECK} Checked out latest stable version.\\n" + printf "${SYM_CHECK} Nice! Your PiPass installation is now on v$VERSION.\\n" +} + +if [[ $EUID -ne 0 ]]; then + printf "${SYM_X} ${CL_RED}FATAL:${CL_BLANK} The updater must be run with root permissions\\n" + exit 1; +fi + +while true; do + printf "\\n" + read -p "To ensure compatibility, the system should be updated. Is this ok? [Y/n] " yn + case $yn in + [Yy]* ) update_system; break;; + [Nn]* ) break;; + * ) update_system; break;; + esac +done + +while true; do + printf "\\n" + read -p "The updater will now check for and install dependencies. Is this ok? [Y/n] " yn + case $yn in + [Yy]* ) dependencies_install; break;; + [Nn]* ) break;; + * ) update_system; break;; + esac +done + +if [ -d "$WEBROOT" ]; then + printf "\\n" + read -p "Changes to ALL PIPASS FILES will be overwritten (except local config file, PiPass.ini) with the update. Really continue? [Y/n] " yn + while true; do + case $yn in + [Yy]* ) update_pipass; break;; + [Nn]* ) exit;; + * ) update_pipass; break;; + esac + done +else + printf "${SYM_INFO} ${CL_YELLOW}WARN:${CL_BLANK} We couldn't reliabliy determine your webroot. Please manually modify the \"WEBROOT\" variable in the script and re-run. Sometimes, this can happen if there is no webserver installed. The updater will exit now.\\n" + exit; +fi \ No newline at end of file