gravity-sync/gravity-sync.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

187 lines
5.3 KiB
Bash
Executable File

#!/bin/bash
SCRIPT_START=$SECONDS
# GRAVITY SYNC BY VMSTAN #####################
PROGRAM='Gravity Sync'
VERSION='3.1.0'
# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
# Requires Pi-Hole 5.x or higher already be installed, for help visit https://pi-hole.net
# REQUIRED SETTINGS ##########################
# Run './gravity-sync.sh config' to get started, it will customize the script for your environment
# You should not to change the values of any variables here here to customize your install
# Add replacement variables to gravity-sync.conf, which will overwrite these defaults.
# STANDARD VARIABLES #########################
# Installation Types
PH_IN_TYPE='default' # Pi-hole install type, `default` or `docker` (local)
RH_IN_TYPE='default' # Pi-hole install type, `default` or `docker` (remote)
# Pi-hole Folder/File Customization
PIHOLE_DIR='/etc/pihole' # default Pi-hole data directory (local)
RIHOLE_DIR='/etc/pihole' # default Pi-hole data directory (remote)
PIHOLE_BIN='/usr/local/bin/pihole' # default Pi-hole binary directory (local)
RIHOLE_BIN='/usr/local/bin/pihole' # default Pi-hole binary directory (remote)
DOCKER_BIN='/usr/bin/docker' # default Docker binary directory (local)
ROCKER_BIN='/usr/bin/docker' # default Docker binary directory (remote)
FILE_OWNER='pihole:pihole' # default Pi-hole file owner and group (local)
RILE_OWNER='pihole:pihole' # default Pi-hole file owner and group (remote)
DOCKER_CON='pihole' # default Pi-hole Docker container name (local)
ROCKER_CON='pihole' # default Pi-hole Docker container name (remote)
GRAVITY_FI='gravity.db' # default Pi-hole database file
CUSTOM_DNS='custom.list' # default Pi-hole local DNS lookups
# Interaction Customization
VERIFY_PASS='0' # replace in gravity-sync.conf to overwrite
SKIP_CUSTOM='0' # replace in gravity-sync.conf to overwrite
DATE_OUTPUT='0' # replace in gravity-sync.conf to overwrite
PING_AVOID='0' # replace in gravity-sync.conf to overwrite
ROOT_CHECK_AVOID='0' # replace in gravity-sync.conf to overwrite
# Backup Customization
BACKUP_RETAIN='7' # replace in gravity-sync.conf to overwrite
# SSH Customization
SSH_PORT='22' # default SSH port
SSH_PKIF='.ssh/id_rsa' # default local SSH key
# GS Folder/File Locations
GS_FILEPATH=$(realpath $0) # auto determined - do not change!
LOCAL_FOLDR=$(dirname $GS_FILEPATH) # auto determined - do not change!
CONFIG_FILE='gravity-sync.conf' # must exist with primary host/user configured
GS_FILENAME='gravity-sync.sh' # must exist because it's this script
BACKUP_FOLD='backup' # must exist as subdirectory in LOCAL_FOLDR
LOG_PATH="${LOCAL_FOLDR}" # replace in gravity-sync.conf to overwrite
SYNCING_LOG='gravity-sync.log' # replace in gravity-sync.conf to overwrite
CRONJOB_LOG='gravity-sync.cron' # replace in gravity-sync.conf to overwrite
HISTORY_MD5='gravity-sync.md5' # replace in gravity-sync.conf to overwrite
# OS Settings
BASH_PATH='/bin/bash' # default OS bash path
##############################################
### NEVER CHANGE ANYTHING BELOW THIS LINE! ###
##############################################
# Import Color/Message Includes
source ${LOCAL_FOLDR}/includes/gs-colors.sh
# FUNCTION DEFINITIONS #######################
# Core Functions
source ${LOCAL_FOLDR}/includes/gs-core.sh
# Gravity Replication Functions
source ${LOCAL_FOLDR}/includes/gs-compare.sh
source ${LOCAL_FOLDR}/includes/gs-pull.sh
source ${LOCAL_FOLDR}/includes/gs-push.sh
source ${LOCAL_FOLDR}/includes/gs-smart.sh
source ${LOCAL_FOLDR}/includes/gs-restore.sh
source ${LOCAL_FOLDR}/includes/gs-backup.sh
# Hashing & SSH Functions
source ${LOCAL_FOLDR}/includes/gs-hashing.sh
source ${LOCAL_FOLDR}/includes/gs-ssh.sh
# Logging Functions
source ${LOCAL_FOLDR}/includes/gs-logging.sh
# Validation Functions
source ${LOCAL_FOLDR}/includes/gs-validate.sh
source ${LOCAL_FOLDR}/includes/gs-intent.sh
source ${LOCAL_FOLDR}/includes/gs-root.sh
# Configuration Management
source ${LOCAL_FOLDR}/includes/gs-config.sh
source ${LOCAL_FOLDR}/includes/gs-update.sh
source ${LOCAL_FOLDR}/includes/gs-automate.sh
source ${LOCAL_FOLDR}/includes/gs-purge.sh
# Exit Codes
source ${LOCAL_FOLDR}/includes/gs-exit.sh
# SCRIPT EXECUTION ###########################
case $# in
0)
start_gs
task_smart ;;
1)
case $1 in
smart|sync)
start_gs
task_smart ;;
pull)
start_gs
task_pull ;;
push)
start_gs
task_push ;;
restore)
start_gs
task_restore ;;
version)
start_gs_noconfig
task_version ;;
update|upgrade)
start_gs_noconfig
task_update ;;
dev|devmode|development|develop)
start_gs_noconfig
task_devmode ;;
logs|log)
start_gs
task_logs ;;
compare)
start_gs
task_compare ;;
cron)
start_gs
task_cron ;;
config|configure)
start_gs_noconfig
task_configure ;;
auto|automate)
start_gs
task_automate ;;
backup)
start_gs
task_backup ;;
purge)
start_gs
task_purge ;;
sudo)
start_gs
task_sudo ;;
*)
start_gs
task_invalid ;;
esac
;;
2)
case $1 in
auto|automate)
start_gs
task_automate ;;
esac
;;
3)
case $1 in
auto|automate)
start_gs
task_automate $2 $3 ;;
esac
;;
*)
start_gs
task_invalid ;;
esac
# END OF SCRIPT ##############################