From f2696d3dd30fa3797241ed77a79145e2bf254e58 Mon Sep 17 00:00:00 2001 From: pika Date: Sun, 18 May 2025 17:19:16 +0200 Subject: [PATCH] wip --- template.sh | 61 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/template.sh b/template.sh index 38a74c1..19daa03 100644 --- a/template.sh +++ b/template.sh @@ -6,6 +6,30 @@ command -v "$@" >/dev/null 2>&1 } + # ─< package variable >─────────────────────────────────────────────────────────────────── + unset PACKAGE + + # ─< argument list variables >──────────────────────────────────────────────────────────── + unset silent + + sleep 0.1 + + PACKAGE=packagename + if command_exists "$PACKAGE"; then + echo_warning "$PACKAGE is already installed!" + echo_warning "Exiting now!" + exit 69 + fi + + # ─< parse arguments and get variable contents >────────────────────────────────────────── + for arg in "$@"; do + case "$arg" in + --silent | -s) + silent=true + ;; + esac + done + # WHY: # This import will give you the following variables: # _sudo="sudo -E" <- only if non root user @@ -31,8 +55,8 @@ fi source "$import" - sleep 0.2 - rm "$import" + sleep 0.1 + rm -f "$import" } getDependencies() { @@ -65,15 +89,25 @@ declare -n pkgArray="${deps[$distro]}" case "$distro" in - debian | ubuntu | arch | fedora | alpine | opensuse) checkAndInstall "${pkgArray[@]}" ;; + debian | ubuntu | arch | fedora | alpine | opensuse) + checkAndInstall "${pkgArray[@]}" + ;; *) - echo_error "Cannot install for $distro" + echo_error "There are no dependencies to install for $distro" return 69 ;; esac } main() { + if $silent; then + echo_warning "Executing script silently!" + fi + + if ! getDependencies; then + echo_error "Error when installing dependencies.." + fi + case "$distro" in arch) echo "arch" @@ -100,22 +134,7 @@ esac } - setup() { - if getImports; then - case "$@" in - --silent | -s) - silent=true - echo_warning "Running script silently!" - ;; - *) - silent=false - ;; - esac - fi - } - - if setup; then - getDependencies - main