126 lines
3.7 KiB
Bash
126 lines
3.7 KiB
Bash
#!/bin/bash
|
|
#
|
|
|
|
# -e option instructs bash to immediately exit if any command [1] has a non-zero exit status
|
|
# We do not want users to end up with a partially working install, so we exit the script
|
|
# instead of continuing the installation with something broken
|
|
set -e
|
|
|
|
# Append common folders to the PATH to ensure that all basic commands are available.
|
|
# When using "su" an incomplete PATH could be passed:
|
|
export PATH+=':/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
|
|
|
|
######## VARIABLES #########
|
|
# For better maintainability, we store as much information that can change in variables
|
|
# This allows us to make a change in one place that can propagate to all instances of the variable
|
|
# These variables should all be GLOBAL variables, written in CAPS
|
|
# Local variables will be in lowercase and will exist only within functions
|
|
# It's still a work in progress, so you may see some variance in this guideline until it is complete
|
|
|
|
# Location for final installation log storage
|
|
installLogLoc="~/install.log"
|
|
|
|
# Root of the web server
|
|
webroot="/var/www/html"
|
|
|
|
GitUrl=""
|
|
|
|
LOCAL_REPO="/etc/.doweFiles"
|
|
# List of pihole scripts, stored in an array
|
|
FILES=(webmin.sh phpmyadmin_installation.sh mysql_installation.sh)
|
|
|
|
# This directory is where the scripts will be installed
|
|
PHPMYADMIN_INSTALL_DIR=""
|
|
PHPMYADMIN_CONFIG_DIR=""
|
|
BIN_DIR="/usr/local/bin"
|
|
IPV4_ADDRESS=${IPV4_ADDRESS}
|
|
IPV6_ADDRESS=${IPV6_ADDRESS}
|
|
|
|
# Give settings their default values. These may be changed by prompts later in the script.
|
|
QUERY_LOGGING=true
|
|
INSTALL_WEB_INTERFACE=true
|
|
PRIVACY_LEVEL=0
|
|
CACHE_SIZE=10000
|
|
|
|
if [ -z "${USER}" ]; then
|
|
USER="$(id -un)"
|
|
fi
|
|
|
|
# whiptail dialog dimensions: 20 rows and 70 chars width assures to fit on small screens and is known to hold all content.
|
|
r=20
|
|
c=70
|
|
|
|
######## Undocumented Flags. Shhh ########
|
|
# These are undocumented flags; some of which we can use when repairing an installation
|
|
# The runUnattended flag is one example of this
|
|
reconfigure=false
|
|
runUnattended=false
|
|
INSTALL_WEB_SERVER=true
|
|
# Check arguments for the undocumented flags
|
|
for var in "$@"; do
|
|
case "$var" in
|
|
"--reconfigure" ) reconfigure=true;;
|
|
"--unattended" ) runUnattended=true;;
|
|
"--disable-install-webserver" ) INSTALL_WEB_SERVER=false;;
|
|
esac
|
|
done
|
|
|
|
# If the color table file exists,
|
|
if [[ -f "${coltable}" ]]; then
|
|
# source it
|
|
source "${coltable}"
|
|
# Otherwise,
|
|
else
|
|
# Set these values so the installer can still run in color
|
|
COL_NC='\e[0m' # No Color
|
|
COL_LIGHT_GREEN='\e[1;32m'
|
|
COL_LIGHT_RED='\e[1;31m'
|
|
TICK="[${COL_LIGHT_GREEN}✓${COL_NC}]"
|
|
CROSS="[${COL_LIGHT_RED}✗${COL_NC}]"
|
|
INFO="[i]"
|
|
# shellcheck disable=SC2034
|
|
DONE="${COL_LIGHT_GREEN} done!${COL_NC}"
|
|
OVER="\\r\\033[K"
|
|
fi
|
|
|
|
|
|
# A simple function that just echoes out our logo in ASCII format
|
|
# This lets users know that it is a Pi-hole, LLC product
|
|
show_ascii_berry() {
|
|
echo -e "
|
|
${COL_LIGHT_GREEN}.;;,.
|
|
.ccccc:,.
|
|
:cccclll:. ..,,
|
|
:ccccclll. ;ooodc
|
|
'ccll:;ll .oooodc
|
|
.;cll.;;looo:.
|
|
${COL_LIGHT_RED}.. ','.
|
|
.',,,,,,'.
|
|
.',,,,,,,,,,.
|
|
.',,,,,,,,,,,,....
|
|
....''',,,,,,,'.......
|
|
......... .... .........
|
|
.......... ..........
|
|
.......... ..........
|
|
......... .... .........
|
|
........,,,,,,,'......
|
|
....',,,,,,,,,,,,.
|
|
.',,,,,,,,,'.
|
|
.',,,,,,'.
|
|
..'''.${COL_NC}
|
|
"
|
|
}
|
|
|
|
is_command() {
|
|
# Checks to see if the given command (passed as a string argument) exists on the system.
|
|
# The function returns 0 (success) if the command exists, and 1 if it doesn't.
|
|
local check_command="$1"
|
|
|
|
command -v "${check_command}" >/dev/null 2>&1
|
|
}
|
|
|
|
|
|
show_ascii_berry
|
|
is_command
|
|
|