From fc3a9c6bf7622aea9894b8591ff5ce9cf4d950a8 Mon Sep 17 00:00:00 2001 From: eichehome Date: Sun, 26 Sep 2021 00:40:55 +0200 Subject: [PATCH] Installer installiert Pakete --- desec-dns.sh | 20 ++++++++++++ functions.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ install.sh | 34 ++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100755 desec-dns.sh create mode 100644 functions.sh create mode 100755 install.sh diff --git a/desec-dns.sh b/desec-dns.sh new file mode 100755 index 0000000..9266a7c --- /dev/null +++ b/desec-dns.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Screen prepare +screen_size=$(stty size 2>/dev/null || echo 24 80) +rows=$(echo "$screen_size" | awk '{print $1}') +columns=$(echo "$screen_size" | awk '{print $2}') + +# Divide by two so the dialogs take up half of the screen, which looks nice. +r=$(( rows / 2 )) +c=$(( columns / 2 )) +# Unless the screen is tiny +r=$(( r < 20 ? 20 : r )) +c=$(( c < 70 ? 70 : c )) + +if [ -f ./functions.sh ]; then + . ./functions.sh +else + echo "functions.sh does not exists" + exit 1 +fi \ No newline at end of file diff --git a/functions.sh b/functions.sh new file mode 100644 index 0000000..f915b9c --- /dev/null +++ b/functions.sh @@ -0,0 +1,87 @@ +setColors() { + 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" +} + +prepare_screen() { + screen_size=$(stty size 2>/dev/null || echo 24 80) + rows=$(echo "$screen_size" | awk '{print $1}') + columns=$(echo "$screen_size" | awk '{print $2}') + # Divide by two so the dialogs take up half of the screen, which looks nice. + r=$(( rows / 2 )) + c=$(( columns / 2 )) + # Unless the screen is tiny + r=$(( r < 20 ? 20 : r )) + c=$(( c < 70 ? 70 : c )) +} + +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 +} +package_manager_detect() { + if is_command apt-get ; then + PKG_MANAGER="apt-get" + UPDATE_PKF_CACHE="${PKG_MANAGER} update" + PKG_INSTALL=("${PKG_MANAGER}" -qq --no-install-recommends install) + elif is_command rpm ; then + if is_command dnf ; then + PKG_MANAGER="dnf" + else + PKG_MANAGER="yum" + fi + PKG_INSTALL=("${PKG_MANAGER}" install -y) +fi +} +install_dependencies() { + declare -a installArray + for i in "$@"; do + printf " %b Checking for %s...\\n" "${INFO}" "${i}" + if is_command ${i} ; then + printf " %b Checking for %s\\n" "${TICK}" "${i}" + else + printf " %b Checking for %s (will be installed)\\n" "${CROSS}" "${i}" + installArray+="${i}" + fi + done + if [[ "${#installArray[@]}" -gt 0 ]]; then + printf " %b Processing %s install(s) for: %s, please wait...\\n" "${INFO}" "${PKG_MANAGER}" "${installArray[*]}" + printf '%*s\n' "$columns" '' | tr " " -; + "${SUDO}" "${PKG_INSTALL[@]}" "${installArray[@]}" + printf '%*s\n' "$columns" '' | tr " " -; + fi +} \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..23f60e6 --- /dev/null +++ b/install.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +if [ -f ./functions.sh ]; then + . ./functions.sh +else + echo "functions.sh does not exists" + exit 1 +fi +###### Prepare Environement ###### +setColors +prepare_screen +package_manager_detect +show_ascii_berry +######## FIRST CHECK ######## +# Must be root to install +echo ":::" +if [[ $EUID -eq 0 ]];then + echo "::: You are root." +else + echo "::: sudo will be used for the install." + # Check if it is actually installed + # If it isn't, exit because the install cannot complete + if [[ $(command -v sudo) ]];then + export SUDO="sudo" + export SUDOE="sudo -E" + else + echo "::: Please install sudo or run this as root." + exit 1 + fi +fi +printf ":::\\n\\n" + +# Check for dependencies +install_dependencies whiptail +install_path=$(whiptail --inputbox "Text" "${r}" "${c}" 2>&1 >/dev/tty) \ No newline at end of file