Skip to content

Commit

Permalink
Install script restart pihole-FTL, created bash update script
Browse files Browse the repository at this point in the history
  • Loading branch information
roenw committed Sep 11, 2020
1 parent d345af8 commit 0bf44f5
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 11 deletions.
25 changes: 14 additions & 11 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
170 changes: 170 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0bf44f5

Please sign in to comment.