Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Support for pihole running in a podman container #138

Merged
merged 3 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions gravity-sync.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
# 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
Expand Down
10 changes: 6 additions & 4 deletions gravity-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
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
Expand Down
44 changes: 35 additions & 9 deletions includes/gs-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -109,19 +110,26 @@ 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}"
Expand Down Expand Up @@ -174,19 +182,25 @@ 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}"
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions includes/gs-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ function ph_type {
elif [ "$PH_IN_TYPE" == "docker" ]
then
PH_EXEC="${DOCKER_BIN} exec ${DOCKER_CON} pihole"
elif [ "$PH_IN_TYPE" == "podman" ]
then
PH_EXEC="${PODMAN_BIN} exec ${DOCKER_CON} pihole"
fi

if [ "$RH_IN_TYPE" == "default" ]
Expand All @@ -60,6 +63,9 @@ function ph_type {
elif [ "$RH_IN_TYPE" == "docker" ]
then
RH_EXEC="${ROCKER_BIN} exec ${ROCKER_CON} pihole"
elif [ "$RH_IN_TYPE" == "podman" ]
then
RH_EXEC="${RODMAN_BIN} exec ${ROCKER_CON} pihole"
fi
}

Expand Down
17 changes: 17 additions & 0 deletions includes/gs-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand All @@ -127,6 +136,10 @@ function show_info() {
then
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: ${DOCKER_CON}"
echo -e "Local Podman Binary Directory: ${PODMAN_BIN}"
fi

echo -e "Local File Owner Settings: ${FILE_OWNER}"
Expand Down Expand Up @@ -196,6 +209,10 @@ function show_info() {
then
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: ${ROCKER_CON}"
echo -e "Remote Podman Binary Directory: ${RODMAN_BIN}"
fi

echo -e "Remote File Owner Settings: ${RILE_OWNER}"
Expand Down
9 changes: 9 additions & 0 deletions includes/gs-validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} ]
Expand Down
27 changes: 27 additions & 0 deletions prep/gs-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down