gravity-sync/prep/gs-install.sh
Michael Stanclift 6551ae88c7
3.1.0 (#105)
* Begin work on Docker support

* rewrite permission detection

* wrong else

* Change pihole detection based on sudo results

* Write out to devnull

* nosodo handle

* AND then

* scanning

* nosudo more

* clearer wording on failures

* headers

* handle nosudo on docker detection better

* SUDO sudo

* AND THEN

* status report rewrite

* link

* alert on no local install detected

* yellow headers like the rest of GS

* semi critical issues

* purple instead of red

* clean up output of sudo detection

* give me space

* Auto run config script

* added logo

* center logo

* move intro

* trying dev/tty

* advanced config generate

* !=

* logic is hard

* new logo

* image

* fonts

* svg image

* remove h1

* use rihole variable

* New root check

* better method of checking sudo

* remove messages

* rihole

* attempting realpath

* GS_FILEPATH

* remove $HOME call

* remove config requirement for updates

* no config for updates

* all the variables

* all kinds of variable replacements

* double quotes

* it’s like I’ve forgotten how to write this stuff

* removals

* updated requirements

* variable rearrangement

* validation check for docker

* riholes

* placeholder

* more riholes

* even more riholes

* docker examples

* docker rewrite

* docker docker docker

* docker custom checks

* update from anywhere

* correct validation error

* check for current owner only if local install

* give me space

* stuff

* more stuff

* bash alias creation

* cleanup installer

* fix .sh

* config errors, remove sshpass validation

* skip directories if done

* limit config script

* fix for changes when both targets have changed

* RIHOLE

* cleanup warning messages

* stop sign

* big red

* documenting new variables

* master

Co-authored-by: Michael Stanclift <vmstan@sovereign.vmstan.net>
Co-authored-by: Michael Stanclift <vmstan@sovereign.local>
2020-10-19 13:48:23 -05:00

210 lines
6.6 KiB
Bash

# GRAVITY SYNC BY VMSTAN #####################
# gs-install.sh ##############################
# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
# This code will be called from a curl call via installation instructions
# Run this script on your primary Pi-hole to aid in preparing for Gravity Sync installation.
set -e
# Script Colors
RED='\033[0;91m'
GREEN='\033[0;92m'
CYAN='\033[0;96m'
YELLOW='\033[0;93m'
PURPLE='\033[0;95m'
BLUE='\033[0;94m'
BOLD='\033[1m'
NC='\033[0m'
# Variables
CROSSCOUNT="0"
PHFAILCOUNT="0"
CURRENTUSER=$(whoami)
# Header
echo -e "========================================================"
echo -e "${YELLOW}Gravity Sync by ${BLUE}@vmstan${YELLOW} - Online Installation${NC}"
echo -e "${CYAN}https://github.com/vmstan/gravity-sync${NC}"
echo -e "========================================================"
# echo -e "Initalizing Short Range Sensors"
# Check Root
echo -e "[${YELLOW}i${NC}] ${YELLOW}Validating System Authorization${NC}"
if [ ! "$EUID" -ne 0 ]
then
echo -e "[${GREEN}${NC}] Current User (${CURRENTUSER}) is ROOT"
LOCALADMIN="root"
else
if hash sudo 2>/dev/null
then
echo -e "[${GREEN}${NC}] Sudo Utility Detected"
# Check Sudo
sudo --validate
if [ "$?" != "0" ]
then
echo -e "[${RED}${NC}] Current User (${CURRENTUSER}) Cannot SUDO"
CROSSCOUNT=$((CROSSCOUNT+1))
LOCALADMIN="nosudo"
else
echo -e "[${GREEN}${NC}] Current User (${CURRENTUSER}) Has SUDO Powers"
LOCALADMIN="sudo"
fi
else
echo -e "[${RED}${NC}] Sudo Utility Not Detected"
CROSSCOUNT=$((CROSSCOUNT+1))
LOCALADMIN="nosudo"
fi
if [ "$LOCALADMIN" != "sudo" ]
then
echo -e "[${RED}${NC}] Current User (${CURRENTUSER}) Cannot SUDO"
CROSSCOUNT=$((CROSSCOUNT+1))
LOCALADMIN="nosudo"
fi
fi
echo -e "[${YELLOW}i${NC}] ${YELLOW}Scanning for Required Components${NC}"
# Check OpenSSH
if hash ssh 2>/dev/null
then
echo -e "[${GREEN}${NC}] OpenSSH Binaries Detected"
else
echo -e "[${RED}${NC}] OpenSSH Binaries Not Installed"
CROSSCOUNT=$((CROSSCOUNT+1))
fi
# Check Rsync
if hash rsync 2>/dev/null
then
echo -e "[${GREEN}${NC}] RSYNC Binaries Detected"
else
echo -e "[${RED}${NC}] RSYNC Binaries Not Installed"
CROSSCOUNT=$((CROSSCOUNT+1))
fi
# Check Sudo
if hash sudo 2>/dev/null
then
echo -e "[${GREEN}${NC}] SUDO Binaries Detected"
else
echo -e "[${RED}${NC}] SUDO Binaries Not Installed"
CROSSCOUNT=$((CROSSCOUNT+1))
fi
# Check Crontab
if hash crontab 2>/dev/null
then
echo -e "[${GREEN}${NC}] CRONTAB Binaries Detected"
else
echo -e "[${RED}${NC}] CRONTAB Binaries Not Installed"
CROSSCOUNT=$((CROSSCOUNT+1))
fi
# Check SQLITE3
if hash sqlite3 2>/dev/null
then
echo -e "[${GREEN}${NC}] SQLITE3 Binaries Detected"
else
echo -e "[${RED}${NC}] SQLITE3 Binaries Not Installed"
CROSSCOUNT=$((CROSSCOUNT+1))
fi
# Check GIT
if hash git 2>/dev/null
then
echo -e "[${GREEN}${NC}] GIT Binaries Detected"
else
echo -e "[${RED}${NC}] GIT Binaries Not Installed"
CROSSCOUNT=$((CROSSCOUNT+1))
fi
echo -e "[${YELLOW}i${NC}] ${YELLOW}Performing Warp Core Diagnostics${NC}"
# Check Pihole
if hash pihole 2>/dev/null
then
echo -e "[${GREEN}${NC}] Local Pi-hole Install Detected"
else
echo -e "[${PURPLE}!${NC}] ${PURPLE}No Local Pi-hole Install Detected${NC}"
# echo -e "[${PURPLE}!${NC}] ${PURPLE}Attempting To Compensate${NC}"
if hash docker 2>/dev/null
then
echo -e "[${GREEN}${NC}] Docker Binaries Detected"
if [ "$LOCALADMIN" == "sudo" ]
then
FTLCHECK=$(sudo docker container ls | grep 'pihole/pihole')
elif [ "$LOCALADMIN" == "nosudo" ]
then
echo -e "[${PURPLE}!${NC}] ${PURPLE}No Docker Pi-hole Container Detected (unable to scan)${NC}"
# CROSSCOUNT=$((CROSSCOUNT+1))
PHFAILCOUNT=$((PHFAILCOUNT+1))
else
FTLCHECK=$(docker container ls | grep 'pihole/pihole')
fi
if [ "$LOCALADMIN" != "nosudo" ]
then
if [ "$FTLCHECK" != "" ]
then
echo -e "[${GREEN}${NC}] Pi-Hole Docker Container Detected"
else
echo -e "[${PURPLE}!${NC}] ${PURPLE}No Docker Pi-hole Container Detected${NC}"
# CROSSCOUNT=$((CROSSCOUNT+1))
PHFAILCOUNT=$((PHFAILCOUNT+1))
fi
fi
else
# echo -e "[${RED}✗${NC}] No Local Pi-hole Install Detected"
echo -e "[${PURPLE}!${NC}] ${PURPLE}No Docker Pi-hole Alternative Detected${NC}"
# CROSSCOUNT=$((CROSSCOUNT+1))
PHFAILCOUNT=$((PHFAILCOUNT+1))
fi
fi
if [ "$PHFAILCOUNT" != "0" ]
then
echo -e "[${RED}${NC}] No Usable Pi-hole Install Detected"
CROSSCOUNT=$((CROSSCOUNT+1))
fi
echo -e "[${YELLOW}i${NC}] ${YELLOW}Status Report${NC}"
# Combine Outputs
if [ "$CROSSCOUNT" != "0" ]
then
echo -e "[${RED}${NC}] ${RED}${CROSSCOUNT} Critical Issues Detected${NC}"
echo -e "[${PURPLE}!${NC}] ${PURPLE}Please Correct Failed Components${NC}"
echo -e "[${YELLOW}i${NC}] ${PURPLE}Installation Exiting (without changes)${NC}"
else
echo -e "[${YELLOW}i${NC}] ${YELLOW}Executing Gravity Sync Deployment${NC}"
if [ "$LOCALADMIN" == "sudo" ]
then
echo -e "[${BLUE}>${NC}] Creating Sudoers.d File"
touch /tmp/gs-nopasswd.sudo
echo -e "${CURRENTUSER} ALL=(ALL) NOPASSWD: ALL" > /tmp/gs-nopasswd.sudo
sudo install -m 0440 /tmp/gs-nopasswd.sudo /etc/sudoers.d/gs-nopasswd
fi
if [ "$GS_INSTALL" != "secondary" ]
then
echo -e "[${YELLOW}i${NC}] Gravity Sync Preperation Complete"
echo -e "[${YELLOW}i${NC}] Execute on Installer on Secondary"
echo -e "[${YELLOW}i${NC}] Check Documentation for Instructions"
echo -e "[${YELLOW}i${NC}] Installation Exiting (without changes)"
else
echo -e "[${BLUE}>${NC}] Creating Gravity Sync Directories"
git clone https://github.com/vmstan/gravity-sync.git
echo -e "[${BLUE}>${NC}] Starting Gravity Sync Configuration"
echo -e "========================================================"
sh gravity-sync/gravity-sync.sh configure < /dev/tty
# echo -e "[${YELLOW}i${NC}] This host is now prepared to configure Gravity Sync!"
# echo -e "[${YELLOW}i${NC}] Please run './gravity-sync configure' from $HOME/gravity-sync"
# echo -e "[${YELLOW}i${NC}] Visit https://github.com/vmstan/gravity-sync for more instructions."
fi
fi
exit