From cd8d6b65fbce4d072cfeb58af1c976a9da0386c5 Mon Sep 17 00:00:00 2001 From: "Martin F. Schumann" Date: Sun, 31 Jan 2021 19:29:47 +0100 Subject: [PATCH 1/2] add support for pihole running in a podman container --- gravity-sync.conf.example | 10 ++++--- gravity-sync.sh | 10 ++++--- includes/gs-config.sh | 60 ++++++++++++++++++++++++++++----------- includes/gs-core.sh | 10 +++++-- includes/gs-update.sh | 21 ++++++++++++-- includes/gs-validate.sh | 9 ++++++ prep/gs-install.sh | 27 ++++++++++++++++++ 7 files changed, 118 insertions(+), 29 deletions(-) diff --git a/gravity-sync.conf.example b/gravity-sync.conf.example index 2b7547bf..c883d864 100644 --- a/gravity-sync.conf.example +++ b/gravity-sync.conf.example @@ -9,8 +9,8 @@ REMOTE_USER='pi' # STANDARD VARIABLES ######################### ### Installation Types -# PH_IN_TYPE='' # Pi-hole install type, `default` or `docker` (local) -# RH_IN_TYPE='' # Pi-hole install type, `default` or `docker` (remote) +# PH_IN_TYPE='' # Pi-hole install type, `default`, `docker`, or `podman` (local) +# RH_IN_TYPE='' # Pi-hole install type, `default`, `docker`, or `podman` (remote) ### Pi-hole Folder/File Customization # PIHOLE_DIR='' # default Pi-hole data directory (local) @@ -21,10 +21,12 @@ REMOTE_USER='pi' # RIHOLE_BIN='' # default Pi-hole binary directory (remote) # DOCKER_BIN='' # default Docker binary directory (local) # ROCKER_BIN='' # default Docker binary directory (remote) +# PODMAN_BIN='' # default Podman binary directory (local) +# RODMAN_BIN='' # default Podman binary directory (remote) # FILE_OWNER='' # default Pi-hole file owner and group (local) # RILE_OWNER='' # default Pi-hole file owner and group (remote) -# DOCKER_CON='' # default Pi-hole Docker container name (local) -# ROCKER_CON='' # default Pi-hole Docker container name (remote) +# CON_NAME='' # default Pi-hole container name (local) +# RON_NAME='' # default Pi-hole container name (remote) # GRAVITY_FI='' # default Pi-hole database file # CUSTOM_DNS='' # default Pi-hole local DNS lookups diff --git a/gravity-sync.sh b/gravity-sync.sh index 0763bcc7..279d184f 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -17,8 +17,8 @@ VERSION='3.2.4' # 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) +PH_IN_TYPE='default' # Pi-hole install type, `default`, `docker`, or `podman` (local) +RH_IN_TYPE='default' # Pi-hole install type, `default`, `docker`, or `podman` (remote) # Pi-hole Folder/File Customization PIHOLE_DIR='/etc/pihole' # default Pi-hole data directory (local) @@ -29,10 +29,12 @@ 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) +PODMAN_BIN='/usr/bin/podman' # default Podman binary directory (local) +RODMAN_BIN='/usr/bin/podman' # default Podman 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) +CON_NAME='pihole' # default Pi-hole container name (local) +RON_NAME='pihole' # default Pi-hole container name (remote) GRAVITY_FI='gravity.db' # default Pi-hole database file CUSTOM_DNS='custom.list' # default Pi-hole local DNS lookups diff --git a/includes/gs-config.sh b/includes/gs-config.sh index b4a50faf..d3dc7bfd 100644 --- a/includes/gs-config.sh +++ b/includes/gs-config.sh @@ -37,7 +37,8 @@ function config_generate { error_validate docker_detect - if [ "${DOCKERREADY}" == "1" ] + podman_detect + if [ "${DOCKERREADY}" == "1" ] || [ "${PODMANREADY}" == "1" ] then MESSAGE="Advanced Configuration Required" echo_info @@ -109,28 +110,35 @@ function config_generate { ## Advanced Configuration Options function advanced_config_generate { - MESSAGE="Local Pi-hole in Docker Container? (Leave blank for default 'No')" + MESSAGE="Local Pi-hole in Container? (Allowed: 'docker' or 'podman'. Leave blank for default 'No')" echo_need read INPUT_PH_IN_TYPE INPUT_PH_IN_TYPE="${INPUT_PH_IN_TYPE:-N}" if [ "${INPUT_PH_IN_TYPE}" != "N" ] then - MESSAGE="Saving Local Docker Setting to ${CONFIG_FILE}" + if [ "${INPUT_PH_IN_TYPE}" != "docker" ] && [ "${INPUT_PH_IN_TYPE}" != "podman" ] + then + MESSAGE="Local Container Type must either be 'docker' or 'podman'" + echo_warn + exit_withchanges + fi + + MESSAGE="Saving Local Container Type Setting to ${CONFIG_FILE}" echo_stat - sed -i "/# PH_IN_TYPE=''/c\PH_IN_TYPE='docker'" ${LOCAL_FOLDR}/${CONFIG_FILE} + sed -i "/# PH_IN_TYPE=''/c\PH_IN_TYPE='${INPUT_PH_IN_TYPE}'" ${LOCAL_FOLDR}/${CONFIG_FILE} error_validate - MESSAGE="Local Docker Container Name? (Leave blank for default 'pihole')" + MESSAGE="Local Container Name? (Leave blank for default 'pihole')" echo_need - read INPUT_DOCKER_CON - INPUT_DOCKER_CON="${INPUT_DOCKER_CON:-pihole}" + read INPUT_CON_NAME + INPUT_CON_NAME="${INPUT_CON_NAME:-pihole}" - if [ "${INPUT_DOCKER_CON}" != "pihole" ] + if [ "${INPUT_CON_NAME}" != "pihole" ] then MESSAGE="Saving Local Container Name to ${CONFIG_FILE}" echo_stat - sed -i "/# DOCKER_CON=''/c\DOCKER_CON='${INPUT_DOCKER_CON}'" ${LOCAL_FOLDR}/${CONFIG_FILE} + sed -i "/# CON_NAME=''/c\CON_NAME='${INPUT_CON_NAME}'" ${LOCAL_FOLDR}/${CONFIG_FILE} error_validate fi @@ -174,28 +182,34 @@ function advanced_config_generate { error_validate fi - MESSAGE="Remote Pi-hole in Docker Container? (Leave blank for default 'No')" + MESSAGE="Remote Pi-hole in Container? (Allowed: 'docker' or 'podman'. Leave blank for default 'No')" echo_need read INPUT_RH_IN_TYPE INPUT_RH_IN_TYPE="${INPUT_RH_IN_TYPE:-N}" if [ "${INPUT_RH_IN_TYPE}" != "N" ] then - MESSAGE="Saving Remote Docker Setting to ${CONFIG_FILE}" + if [ "${INPUT_RH_IN_TYPE}" != "docker" ] && [ "${INPUT_RH_IN_TYPE}" != "podman" ] + then + MESSAGE="Remote Container Type must either be 'docker' or 'podman'" + echo_warn + exit_withchanges + fi + MESSAGE="Saving Remote Container Type Setting to ${CONFIG_FILE}" echo_stat - sed -i "/# RH_IN_TYPE=''/c\RH_IN_TYPE='docker'" ${LOCAL_FOLDR}/${CONFIG_FILE} + sed -i "/# RH_IN_TYPE=''/c\RH_IN_TYPE='${INPUT_RH_IN_TYPE}'" ${LOCAL_FOLDR}/${CONFIG_FILE} error_validate - MESSAGE="Remote Docker Container Name? (Leave blank for default 'pihole')" + MESSAGE="Remote Container Name? (Leave blank for default 'pihole')" echo_need - read INPUT_ROCKER_CON - INPUT_ROCKER_CON="${INPUT_ROCKER_CON:-pihole}" + read INPUT_RON_NAME + INPUT_RON_NAME="${INPUT_RON_NAME:-pihole}" - if [ "${INPUT_ROCKER_CON}" != "pihole" ] + if [ "${INPUT_RON_NAME}" != "pihole" ] then MESSAGE="Saving Remote Container Name to ${CONFIG_FILE}" echo_stat - sed -i "/# ROCKER_CON=''/c\ROCKER_CON='${INPUT_ROCKER_CON}'" ${LOCAL_FOLDR}/${CONFIG_FILE} + sed -i "/# RON_NAME=''/c\RON_NAME='${INPUT_RON_NAME}'" ${LOCAL_FOLDR}/${CONFIG_FILE} error_validate fi @@ -423,6 +437,18 @@ function docker_detect { fi } +## Detect Podman +function podman_detect { + if hash podman 2>/dev/null + then + FTLCHECK=$(sudo podman container ls | grep 'pihole/pihole') + if [ "$FTLCHECK" != "" ] + then + PODMANREADY="1" + fi + fi +} + ## Create Bash Alias function create_alias { MESSAGE="Creating Bash Alias" diff --git a/includes/gs-core.sh b/includes/gs-core.sh index 385e36bf..8a167dca 100644 --- a/includes/gs-core.sh +++ b/includes/gs-core.sh @@ -51,7 +51,10 @@ function ph_type { PH_EXEC="${PIHOLE_BIN}" elif [ "$PH_IN_TYPE" == "docker" ] then - PH_EXEC="${DOCKER_BIN} exec ${DOCKER_CON} pihole" + PH_EXEC="${DOCKER_BIN} exec ${CON_NAME} pihole" + elif [ "$PH_IN_TYPE" == "podman" ] + then + PH_EXEC="${PODMAN_BIN} exec ${CON_NAME} pihole" fi if [ "$RH_IN_TYPE" == "default" ] @@ -59,7 +62,10 @@ function ph_type { RH_EXEC="${RIHOLE_BIN}" elif [ "$RH_IN_TYPE" == "docker" ] then - RH_EXEC="${ROCKER_BIN} exec ${ROCKER_CON} pihole" + RH_EXEC="${ROCKER_BIN} exec ${RON_NAME} pihole" + elif [ "$RH_IN_TYPE" == "podman" ] + then + RH_EXEC="${RODMAN_BIN} exec ${RON_NAME} pihole" fi } diff --git a/includes/gs-update.sh b/includes/gs-update.sh index dc8eca15..92209b44 100644 --- a/includes/gs-update.sh +++ b/includes/gs-update.sh @@ -97,6 +97,9 @@ function show_info() { elif [ "${PH_IN_TYPE}" == "docker" ] then docker exec -it pihole pihole -v + elif [ "${PH_IN_TYPE}" == "podman" ] + then + podman exec -it pihole pihole -v fi uname -srm @@ -112,6 +115,12 @@ function show_info() { then docker --version fi + + if hash podman 2>/dev/null + then + podman --version + fi + echo -e "" echo -e "${YELLOW}Local/Secondary Instance Settings${NC}" @@ -125,8 +134,12 @@ function show_info() { echo -e "Local Pi-hole Binary Directory: ${PIHOLE_BIN}" elif [ "${PH_IN_TYPE}" == "docker" ] then - echo -e "Local Pi-hole Container Name: ${DOCKER_CON}" + echo -e "Local Pi-hole Container Name: ${CON_NAME}" echo -e "Local Docker Binary Directory: ${DOCKER_BIN}" + elif [ "${PH_IN_TYPE}" == "podman" ] + then + echo -e "Local Pi-hole Container Name: ${CON_NAME}" + echo -e "Local Podman Binary Directory: ${PODMAN_BIN}" fi echo -e "Local File Owner Settings: ${FILE_OWNER}" @@ -194,8 +207,12 @@ function show_info() { echo -e "Remote Pi-hole Binary Directory: ${RIHOLE_BIN}" elif [ "${RH_IN_TYPE}" == "docker" ] then - echo -e "Remote Pi-hole Container Name: ${ROCKER_CON}" + echo -e "Remote Pi-hole Container Name: ${RON_NAME}" echo -e "Remote Docker Binary Directory: ${ROCKER_BIN}" + elif [ "${RH_IN_TYPE}" == "podman" ] + then + echo -e "Remote Pi-hole Container Name: ${RON_NAME}" + echo -e "Remote Podman Binary Directory: ${RODMAN_BIN}" fi echo -e "Remote File Owner Settings: ${RILE_OWNER}" diff --git a/includes/gs-validate.sh b/includes/gs-validate.sh index ba981ea5..eca9b6e1 100644 --- a/includes/gs-validate.sh +++ b/includes/gs-validate.sh @@ -46,6 +46,15 @@ function validate_ph_folders { echo_fail exit_nochange fi + elif [ "$PH_IN_TYPE" == "podman" ] + then + FTLCHECK=$(sudo podman container ls | grep 'pihole/pihole') + if [ "$FTLCHECK" == "" ] + then + MESSAGE="Unable to Validate that Pi-Hole is Installed" + echo_fail + exit_nochange + fi fi if [ ! -d ${PIHOLE_DIR} ] diff --git a/prep/gs-install.sh b/prep/gs-install.sh index 34056e8a..d7f61b12 100644 --- a/prep/gs-install.sh +++ b/prep/gs-install.sh @@ -155,6 +155,33 @@ else PHFAILCOUNT=$((PHFAILCOUNT+1)) fi fi + elif hash podman 2>/dev/null + then + echo -e "[${GREEN}✓${NC}] Podman Binaries Detected" + + if [ "$LOCALADMIN" == "sudo" ] + then + FTLCHECK=$(sudo podman container ls | grep 'pihole/pihole') + elif [ "$LOCALADMIN" == "nosudo" ] + then + echo -e "[${PURPLE}!${NC}] ${PURPLE}No Podman Pi-hole Container Detected (unable to scan)${NC}" + # CROSSCOUNT=$((CROSSCOUNT+1)) + PHFAILCOUNT=$((PHFAILCOUNT+1)) + else + FTLCHECK=$(podman container ls | grep 'pihole/pihole') + fi + + if [ "$LOCALADMIN" != "nosudo" ] + then + if [ "$FTLCHECK" != "" ] + then + echo -e "[${GREEN}✓${NC}] Pi-Hole Podman Container Detected" + else + echo -e "[${PURPLE}!${NC}] ${PURPLE}No Podman 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}" From fdd0d313b619f50fa49511b1aa1ce4a2c907b53a Mon Sep 17 00:00:00 2001 From: "Martin F. Schumann" Date: Sun, 31 Jan 2021 19:45:38 +0100 Subject: [PATCH 2/2] revert renaming of DOCKER_CON to CON_NAME to avoid breaking existing installations --- gravity-sync.conf.example | 4 ++-- gravity-sync.sh | 4 ++-- includes/gs-config.sh | 16 ++++++++-------- includes/gs-core.sh | 8 ++++---- includes/gs-update.sh | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gravity-sync.conf.example b/gravity-sync.conf.example index c883d864..cc305d48 100644 --- a/gravity-sync.conf.example +++ b/gravity-sync.conf.example @@ -25,8 +25,8 @@ REMOTE_USER='pi' # RODMAN_BIN='' # default Podman binary directory (remote) # FILE_OWNER='' # default Pi-hole file owner and group (local) # RILE_OWNER='' # default Pi-hole file owner and group (remote) -# CON_NAME='' # default Pi-hole container name (local) -# RON_NAME='' # default Pi-hole container name (remote) +# DOCKER_CON='' # default Pi-hole container name (local) +# ROCKER_CON='' # default Pi-hole container name (remote) # GRAVITY_FI='' # default Pi-hole database file # CUSTOM_DNS='' # default Pi-hole local DNS lookups diff --git a/gravity-sync.sh b/gravity-sync.sh index 279d184f..41aa95cf 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -33,8 +33,8 @@ PODMAN_BIN='/usr/bin/podman' # default Podman binary directory (local) RODMAN_BIN='/usr/bin/podman' # default Podman 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) -CON_NAME='pihole' # default Pi-hole container name (local) -RON_NAME='pihole' # default Pi-hole container name (remote) +DOCKER_CON='pihole' # default Pi-hole container name (local) +ROCKER_CON='pihole' # default Pi-hole container name (remote) GRAVITY_FI='gravity.db' # default Pi-hole database file CUSTOM_DNS='custom.list' # default Pi-hole local DNS lookups diff --git a/includes/gs-config.sh b/includes/gs-config.sh index d3dc7bfd..1bb56698 100644 --- a/includes/gs-config.sh +++ b/includes/gs-config.sh @@ -131,14 +131,14 @@ function advanced_config_generate { MESSAGE="Local Container Name? (Leave blank for default 'pihole')" echo_need - read INPUT_CON_NAME - INPUT_CON_NAME="${INPUT_CON_NAME:-pihole}" + read INPUT_DOCKER_CON + INPUT_DOCKER_CON="${INPUT_DOCKER_CON:-pihole}" - if [ "${INPUT_CON_NAME}" != "pihole" ] + if [ "${INPUT_DOCKER_CON}" != "pihole" ] then MESSAGE="Saving Local Container Name to ${CONFIG_FILE}" echo_stat - sed -i "/# CON_NAME=''/c\CON_NAME='${INPUT_CON_NAME}'" ${LOCAL_FOLDR}/${CONFIG_FILE} + sed -i "/# DOCKER_CON=''/c\DOCKER_CON='${INPUT_DOCKER_CON}'" ${LOCAL_FOLDR}/${CONFIG_FILE} error_validate fi @@ -202,14 +202,14 @@ function advanced_config_generate { MESSAGE="Remote Container Name? (Leave blank for default 'pihole')" echo_need - read INPUT_RON_NAME - INPUT_RON_NAME="${INPUT_RON_NAME:-pihole}" + read INPUT_ROCKER_CON + INPUT_ROCKER_CON="${INPUT_ROCKER_CON:-pihole}" - if [ "${INPUT_RON_NAME}" != "pihole" ] + if [ "${INPUT_ROCKER_CON}" != "pihole" ] then MESSAGE="Saving Remote Container Name to ${CONFIG_FILE}" echo_stat - sed -i "/# RON_NAME=''/c\RON_NAME='${INPUT_RON_NAME}'" ${LOCAL_FOLDR}/${CONFIG_FILE} + sed -i "/# ROCKER_CON=''/c\ROCKER_CON='${INPUT_ROCKER_CON}'" ${LOCAL_FOLDR}/${CONFIG_FILE} error_validate fi diff --git a/includes/gs-core.sh b/includes/gs-core.sh index 8a167dca..6dd57c1e 100644 --- a/includes/gs-core.sh +++ b/includes/gs-core.sh @@ -51,10 +51,10 @@ function ph_type { PH_EXEC="${PIHOLE_BIN}" elif [ "$PH_IN_TYPE" == "docker" ] then - PH_EXEC="${DOCKER_BIN} exec ${CON_NAME} pihole" + PH_EXEC="${DOCKER_BIN} exec ${DOCKER_CON} pihole" elif [ "$PH_IN_TYPE" == "podman" ] then - PH_EXEC="${PODMAN_BIN} exec ${CON_NAME} pihole" + PH_EXEC="${PODMAN_BIN} exec ${DOCKER_CON} pihole" fi if [ "$RH_IN_TYPE" == "default" ] @@ -62,10 +62,10 @@ function ph_type { RH_EXEC="${RIHOLE_BIN}" elif [ "$RH_IN_TYPE" == "docker" ] then - RH_EXEC="${ROCKER_BIN} exec ${RON_NAME} pihole" + RH_EXEC="${ROCKER_BIN} exec ${ROCKER_CON} pihole" elif [ "$RH_IN_TYPE" == "podman" ] then - RH_EXEC="${RODMAN_BIN} exec ${RON_NAME} pihole" + RH_EXEC="${RODMAN_BIN} exec ${ROCKER_CON} pihole" fi } diff --git a/includes/gs-update.sh b/includes/gs-update.sh index 92209b44..add0534b 100644 --- a/includes/gs-update.sh +++ b/includes/gs-update.sh @@ -134,11 +134,11 @@ function show_info() { echo -e "Local Pi-hole Binary Directory: ${PIHOLE_BIN}" elif [ "${PH_IN_TYPE}" == "docker" ] then - echo -e "Local Pi-hole Container Name: ${CON_NAME}" + echo -e "Local Pi-hole Container Name: ${DOCKER_CON}" echo -e "Local Docker Binary Directory: ${DOCKER_BIN}" elif [ "${PH_IN_TYPE}" == "podman" ] then - echo -e "Local Pi-hole Container Name: ${CON_NAME}" + echo -e "Local Pi-hole Container Name: ${DOCKER_CON}" echo -e "Local Podman Binary Directory: ${PODMAN_BIN}" fi @@ -207,11 +207,11 @@ function show_info() { echo -e "Remote Pi-hole Binary Directory: ${RIHOLE_BIN}" elif [ "${RH_IN_TYPE}" == "docker" ] then - echo -e "Remote Pi-hole Container Name: ${RON_NAME}" + echo -e "Remote Pi-hole Container Name: ${ROCKER_CON}" echo -e "Remote Docker Binary Directory: ${ROCKER_BIN}" elif [ "${RH_IN_TYPE}" == "podman" ] then - echo -e "Remote Pi-hole Container Name: ${RON_NAME}" + echo -e "Remote Pi-hole Container Name: ${ROCKER_CON}" echo -e "Remote Podman Binary Directory: ${RODMAN_BIN}" fi