From eec49c9c2a90f452645e7167b269f0cd226261fd Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Wed, 13 Apr 2022 09:37:34 -0500 Subject: [PATCH] 4.0.2 (#330) * Start 4.0.2 * automate with options * change random range * Use tmp to stash service timers * make redirect silent * sed not tee * space * simple * Add ssh migration * shuf not random * quad * 4.0.2 Signoff --- README.md | 6 ++-- VERSION | 2 +- gravity-sync | 92 ++++++++++++++++++++++++++++++++++--------------- gravity-sync.sh | 10 ++++++ 4 files changed, 79 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index fcdc058..b9d6b87 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ### -What is better than a [Pi-hole](https://github.com/pi-hole/pi-hole) blocking trackers, advertisements, and other malicious domains on your network? That's right, **two** Pi-hole blocking all that junk on your network! +What is better than a [Pi-hole](https://github.com/pi-hole/pi-hole) blocking trackers, advertisements, and other malicious domains on your network? That's right, **two** Pi-hole blocking all that junk on your network! - [Seriously. Why two Pi-hole?](https://github.com/vmstan/gravity-sync/wiki/Frequent-Questions#why-do-i-need-more-than-one-pi-hole) @@ -40,8 +40,8 @@ Gravity Sync will **not**: 1. [Review System Requirements](https://github.com/vmstan/gravity-sync/wiki/System-Requirements) 2. [Install Gravity Sync](https://github.com/vmstan/gravity-sync/wiki/Installing) 3. [Configure Gravity Sync](https://github.com/vmstan/gravity-sync/wiki/Installing#configuration) -4. [Execute Gravity Sync](https://github.com/vmstan/gravity-sync/wiki/Installing#execution) -5. [Automate Gravity Sync](https://github.com/vmstan/gravity-sync/wiki/Installing#automation) +4. [Execute Gravity Sync](https://github.com/vmstan/gravity-sync/wiki/Engaging) +5. [Automate Gravity Sync](https://github.com/vmstan/gravity-sync/wiki/Automation) ## Disclaimer diff --git a/VERSION b/VERSION index cc868b6..4bac418 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.1 \ No newline at end of file +4.0.2 \ No newline at end of file diff --git a/gravity-sync b/gravity-sync index 840fc77..440d63f 100755 --- a/gravity-sync +++ b/gravity-sync @@ -4,7 +4,7 @@ GS_RUN_START=$SECONDS # GRAVITY SYNC BY VMSTAN ##################### PROGRAM='Gravity Sync' -GS_VERSION='4.0.1' +GS_VERSION='4.0.2' # For documentation or the changelog/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 @@ -1977,45 +1977,83 @@ function task_automate { MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" echo_good + sudo cp ${GS_LOCAL_REPO}/templates/gravity-sync.service ${OS_TMP}/gravity-sync.service + sudo cp ${GS_LOCAL_REPO}/templates/gravity-sync.timer ${OS_TMP}/gravity-sync.timer + MESSAGE="Customizing service file username" + echo_stat OS_CURRENT_USER=$(whoami) - sudo sed -i "/User=unknown/c\User=${OS_CURRENT_USER}" ${GS_LOCAL_REPO}/templates/gravity-sync.service + sudo sed -i "/User=unknown/c\User=${OS_CURRENT_USER}" ${OS_TMP}/gravity-sync.service error_validate MESSAGE="Customizing service file executable path" - sudo sed -i "/ExecStart=/c\ExecStart=${GS_FILEPATH}" ${GS_LOCAL_REPO}/templates/gravity-sync.service + echo_stat + sudo sed -i "/ExecStart=/c\ExecStart=${GS_FILEPATH}" ${OS_TMP}/gravity-sync.service error_validate - MESSAGE="Randomizing service timers" - ACTIVE_REP=$((( RANDOM % 4 ) + 1 )) - RANDOM_REP=$((( RANDOM % 8 ) + 2 )) - sudo sed -i "/OnUnitInactiveSec=5m/c\OnUnitInactiveSec=${ACTIVE_REP}m" ${GS_LOCAL_REPO}/templates/gravity-sync.timer - sudo sed -i "/RandomizedDelaySec=5m/c\RandomizedDelaySec=${RANDOM_REP}m" ${GS_LOCAL_REPO}/templates/gravity-sync.timer + if [ "${GS_SYSLOG_REDIRECT}" != '' ]; then + MESSAGE="Customizing standard output location" + echo_stat + sudo sed -i "/Type=simple/a\StandardOutput=file:${GS_SYSLOG_REDIRECT}" ${OS_TMP}/gravity-sync.service + sudo sed -i "/Type=simple/a\StandardError=file:${GS_SYSLOG_REDIRECT}" ${OS_TMP}/gravity-sync.service + error_validate + fi + + if [ "${INPUT_SPEED}" == 'slow' ] || [ "${INPUT_SPEED}" == 'hour' ]; then + MESSAGE="Randomizing service timers (hour)" + echo_stat + ACTIVE_REP=$(shuf -i 50-55 -n1) + RANDOM_REP=$(shuf -i 7-10 -n1) + elif [ "${INPUT_SPEED}" == 'half' ]; then + MESSAGE="Randomizing service timers (half)" + echo_stat + ACTIVE_REP=$(shuf -i 25-30 -n1) + RANDOM_REP=$(shuf -i 5-7 -n1) + elif [ "${INPUT_SPEED}" == 'quad' ]; then + MESSAGE="Randomizing service timers (quad)" + echo_stat + ACTIVE_REP=$(shuf -i 12-15 -n1) + RANDOM_REP=$(shuf -i 3-5 -n1) + else + MESSAGE="Randomizing service timers" + echo_stat + ACTIVE_REP=$(shuf -i 3-10 -n1) + RANDOM_REP=$(shuf -i 2-5 -n1) + fi + + sudo sed -i "/OnUnitInactiveSec=5m/c\OnUnitInactiveSec=${ACTIVE_REP}m" ${OS_TMP}/gravity-sync.timer + sudo sed -i "/RandomizedDelaySec=5m/c\RandomizedDelaySec=${RANDOM_REP}m" ${OS_TMP}/gravity-sync.timer error_validate if systemctl is-active --quiet gravity-sync.timer; then MESSAGE="Stopping existing systemd service" + echo_stat sudo systemctl stop gravity-sync error_validate fi MESSAGE="Moving systemd timer into place" - sudo cp ${GS_LOCAL_REPO}/templates/gravity-sync.timer ${OS_DAEMON_PATH} + echo_stat + sudo cp ${OS_TMP}/gravity-sync.timer ${OS_DAEMON_PATH} error_validate MESSAGE="Moving systemd service into place" - sudo cp ${GS_LOCAL_REPO}/templates/gravity-sync.service ${OS_DAEMON_PATH} + echo_stat + sudo cp ${OS_TMP}/gravity-sync.service ${OS_DAEMON_PATH} error_validate MESSAGE="Reloading systemd daemon" + echo_stat sudo systemctl daemon-reload --quiet error_validate MESSAGE="Enabling ${PROGRAM} timer" + echo_stat sudo systemctl enable gravity-sync.timer --quiet error_validate MESSAGE="Starting ${PROGRAM} service" + echo_stat sudo systemctl start gravity-sync --quiet error_validate @@ -2154,7 +2192,7 @@ function list_gs_arguments { echo -e "Setup Options:" echo -e " ${YELLOW}config${NC} Creates a new ${PROGRAM} configuration file" echo -e " ${YELLOW}version${NC} Lists the installed version of ${PROGRAM} and checks for updates" - echo -e " ${YELLOW}upgrade${NC} Upgrades ${PROGRAM} to the latest available version on GitHub" + echo -e " ${YELLOW}update${NC} Upgrades ${PROGRAM} to the latest available version on GitHub" echo -e " ${YELLOW}dev${NC} Sets upgrade command to use a development version of ${PROGRAM} (toggle on/off)" echo -e " ${YELLOW}sudo${NC} Enables password-less sudo for current user" echo -e " ${YELLOW}purge${NC} Uninstalls ${PROGRAM} from this system" @@ -2180,22 +2218,22 @@ function list_gs_arguments { # SCRIPT EXECUTION ########################### case "${1}" in - "" | "smart" | "sync" ) task_smart;; - "pull" ) task_pull;; - "push" ) task_push;; - "compare" ) task_compare;; - "config" | "conf" | "configure" ) INPUT_SSH=$2; task_configure;; - "auto" | "automate" ) task_automate;; - "disable" | "stop" ) task_disable_automate;; - "monitor" | "follow" ) task_monitor;; - "purge" | "uninstall" | "remove" ) task_purge;; - "sudo" ) task_sudo;; - "version" | "ver" ) task_version;; - "info" ) task_info;; - "update" | "upgrade" | "up" ) task_update;; - "dev" | "beta" ) task_dev;; - "logs" | "log" ) task_logs;; - * ) task_invalid;; + "" | "smart" | "sync" ) task_smart;; + "pull" ) task_pull;; + "push" ) task_push;; + "compare" ) task_compare;; + "config" | "conf" | "configure" ) INPUT_SSH=$2; task_configure;; + "auto" | "automate" ) INPUT_SPEED=$2 task_automate;; + "disable" | "stop" ) task_disable_automate;; + "monitor" | "follow" ) task_monitor;; + "purge" | "uninstall" | "remove" ) task_purge;; + "sudo" ) task_sudo;; + "version" | "ver" ) task_version;; + "info" ) task_info;; + "update" | "upgrade" | "up" ) task_update;; + "dev" | "beta" ) task_dev;; + "logs" | "log" ) task_logs;; + * ) task_invalid;; esac # END OF SCRIPT ############################## diff --git a/gravity-sync.sh b/gravity-sync.sh index 77f2bd0..cb39ef7 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -192,6 +192,8 @@ function upgrade_to_4 { DOCKER_CON='' ROCKER_CON='' + SSH_PORT='' + MESSAGE="Reviewing old configuration file settings" echo_stat source settings/gravity-sync.conf @@ -221,6 +223,14 @@ function upgrade_to_4 { sudo sed -i "/REMOTE_USER=''/c\REMOTE_USER='${REMOTE_USER}'" /etc/gravity-sync/gravity-sync.conf error_validate + if [ "${SSH_PORT}" != "" ]; then + GS_SSH_PORT=${SSH_PORT} + MESSAGE="Migrating target host SSH settings" + echo_stat + echo -e "GS_SSH_PORT='${GS_SSH_PORT}" | sudo tee -a /etc/gravity-sync/gravity-sync.conf 1> /dev/null + error_validate + fi + if [ "${LOCAL_PIHOLE_DIRECTORY}" == '' ] || [ "${LOCAL_PIHOLE_DIRECTORY}" == '/etc/pihole' ]; then MESSAGE="Defaulting local Pi-hole directory setting" echo_good_clean