Installer installiert Pakete

This commit is contained in:
eichehome 2021-09-26 00:40:55 +02:00
parent edcb66a852
commit fc3a9c6bf7
3 changed files with 141 additions and 0 deletions

20
desec-dns.sh Executable file
View file

@ -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

87
functions.sh Normal file
View file

@ -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
}

34
install.sh Executable file
View file

@ -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)