+user_check() {
+ if [ $(id -u) -ne 0 ]; then
+ printf "Script must be run as root. Try 'sudo ./install.sh'\n"
+ exit 1
+ fi
+}
+
+confirm() {
+ if [ "$FORCE" == '-y' ]; then
+ true
+ else
+ read -r -p "$1 [y/N] " response < /dev/tty
+ if [[ $response =~ ^(yes|y|Y)$ ]]; then
+ true
+ else
+ false
+ fi
+ fi
+}
+
+prompt() {
+ read -r -p "$1 [y/N] " response < /dev/tty
+ if [[ $response =~ ^(yes|y|Y)$ ]]; then
+ true
+ else
+ false
+ fi
+}
+
+success() {
+ echo -e "$(tput setaf 2)$1$(tput sgr0)"
+}
+
+inform() {
+ echo -e "$(tput setaf 6)$1$(tput sgr0)"
+}
+
+warning() {
+ echo -e "$(tput setaf 1)$1$(tput sgr0)"
+}
+
+function do_config_backup {
+ if [ ! $CONFIG_BACKUP == true ]; then
+ CONFIG_BACKUP=true
+ FILENAME="config.preinstall-$LIBRARY_NAME-$DATESTAMP.txt"
+ inform "Backing up $CONFIG to /boot/$FILENAME\n"
+ cp $CONFIG /boot/$FILENAME
+ mkdir -p $RESOURCES_TOP_DIR/config-backups/
+ cp $CONFIG $RESOURCES_TOP_DIR/config-backups/$FILENAME
+ if [ -f "$UNINSTALLER" ]; then
+ echo "cp $RESOURCES_TOP_DIR/config-backups/$FILENAME $CONFIG" >> $UNINSTALLER
+ fi
+ fi
+}
+
+function apt_pkg_install {
+ PACKAGES=()
+ PACKAGES_IN=("$@")
+ for ((i = 0; i < ${#PACKAGES_IN[@]}; i++)); do
+ PACKAGE="${PACKAGES_IN[$i]}"
+ printf "Checking for $PACKAGE\n"
+ dpkg -L $PACKAGE > /dev/null 2>&1
+ if [ "$?" == "1" ]; then
+ PACKAGES+=("$PACKAGE")
+ fi
+ done
+ PACKAGES="${PACKAGES[@]}"
+ if ! [ "$PACKAGES" == "" ]; then
+ echo "Installing missing packages: $PACKAGES"
+ if [ ! $APT_HAS_UPDATED ]; then
+ apt update
+ APT_HAS_UPDATED=true
+ fi
+ apt install -y $PACKAGES
+ if [ -f "$UNINSTALLER" ]; then
+ echo "apt uninstall -y $PACKAGES"
+ fi
+ fi
+}
+
+user_check