diff --git a/hyprlock.sh b/hyprlock.sh index 8a049d4..3d72889 100644 --- a/hyprlock.sh +++ b/hyprlock.sh @@ -7,44 +7,44 @@ command_exists() { command -v "$@" >/dev/null 2>&1 } -# WHY: -# This import will give you the following variables: -# _sudo="sudo -E" <- only if non root user -# distro = -# arch = bool -# fedora = bool -# opensuse = bool.... -# You can then use it for, `if $arch; then` -# Also this gives you the _install command, which installs a package pased on the packagemanager/distro used. -# CAUTION: -# This only wokrs for generic package names, like neovim, or vim, or tmux etc.. -# not every package packagemanager has the same packagenames for their packages.. -getImports() { - local url="https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh" +source-script() { + local url="$1" local import="$(mktemp)" - if command_exists curl; then - curl -fsSL $url -o $import - elif command_exists wget; then - wget -o $import $url - else - echo "curl/wget is required, but missing.." - exit 69 - fi - source "$import" - sleep 0.2 - rm "$import" + # ─< if $1 is a local file, source this one instead >───────────────────────────────────── + if [ -f "$url" ]; then + source "$url" + sleep 0.1 + return 0 + else + # ─< if $1 is a url, grab it and source it, also deletes afterwards >───────────────────── + if command_exists curl; then + curl -fsSL $url -o $import + elif command_exists wget; then + wget -o $import $url + else + echo "curl/wget is required, but missing.." + exit 69 + fi + + source "$import" + + echo "${BLUE}Sourcing external script:${NC} $url" + line + sleep 0.1 + rm -f "$import" + fi } checkComp() { if ! $arch && ! $debian; then - echo_error "Your distro $distro is not compatible with this script" + echo-error "Your distro $distro is not compatible with this script" return 69 fi if $debian; then if ! $trixie; then - echo_error "Your debian version is not compatible with this script" + echo-error "Your debian version is not compatible with this script" return 69 fi fi @@ -80,26 +80,49 @@ getDependencies() { # ╰────────────────────────────────────────────────────────────────╯ declare -n pkgArray="${deps[$distro]}" - for pkg in "${pkgArray[@]}"; do - case "$pkg" in - hyprgraphics) - case "$distro" in - arch) checkAndInstall hyprgraphics ;; - debian) + case "$distro" in + arch) check-and-install ${pkgArray[@]} ;; + debian) + for pkg in "${pkgArray[@]}"; do + case "$pkg" in + hyprgraphics) cloneAndBuildUtils cloneAndBuildGraphics cloneAndBuildScanner cloneAndBuildLang ;; + *) + pkg-install $pkg + ;; esac - ;; - *) - if checkComp; then - checkAndInstall "$pkg" - fi - ;; - esac - done + done + ;; + *) + pen bold red "Cannot install currently for $distro!" + return 69 + ;; + esac + + # for pkg in "${pkgArray[@]}"; do + # case "$pkg" in + # hyprgraphics) + # case "$distro" in + # arch) check-and-install hyprgraphics ;; + # debian) + # cloneAndBuildUtils + # cloneAndBuildGraphics + # cloneAndBuildScanner + # cloneAndBuildLang + # ;; + # esac + # ;; + # *) + # if checkComp; then + # check-and-install "$pkg" + # fi + # ;; + # esac + # done } buildGraphicsAndUtils() { @@ -112,7 +135,7 @@ cloneAndBuildGraphics() { PACKAGE=hyprgraphics if command_exists $PACKAGE; then - echo_error "hyprlang is already installed!" + echo-error "hyprlang is already installed!" return 69 fi @@ -126,7 +149,7 @@ cloneAndBuildGraphics() { echo_pkg install $_sudo cmake --install build else - echo_error "Build has failed for $distro compiling hyprgraphics" + echo-error "Build has failed for $distro compiling hyprgraphics" return 69 fi } @@ -135,7 +158,7 @@ cloneAndBuildUtils() { PACKAGE=hyprutils if command_exists $PACKAGE; then - echo_error "hyprlang is already installed!" + echo-error "hyprlang is already installed!" return 69 fi @@ -153,7 +176,7 @@ cloneAndBuildUtils() { echo_pkg install $_sudo cmake --install build else - echo_error "Build has failed for $distro compiling hyprutils" + echo-error "Build has failed for $distro compiling hyprutils" return 69 fi } @@ -168,7 +191,7 @@ cloneAndBuildScanner() { PACKAGE=hyprwayland-scanner if command_exists $PACKAGE; then - echo_error "hyprlang is already installed!" + echo-error "hyprlang is already installed!" return 69 fi @@ -185,7 +208,7 @@ cloneAndBuildScanner() { echo_pkg install $_sudo cmake --install build else - echo_error "Build has failed for $distro compiling hyprlock" + echo-error "Build has failed for $distro compiling hyprlock" return 69 fi } @@ -200,7 +223,7 @@ cloneAndBuildLang() { PACKAGE=hyprlang if command_exists $PACKAGE; then - echo_error "hyprlang is already installed!" + echo-error "hyprlang is already installed!" return 69 fi @@ -217,7 +240,7 @@ cloneAndBuildLang() { echo_pkg install "Installing hyprlang" $_sudo cmake --install build else - echo_error "Build has failed for $distro compiling hyprlock" + echo-error "Build has failed for $distro compiling hyprlock" return 69 fi } @@ -244,7 +267,7 @@ cloneAndBuildLock() { echo_pkg install $_sudo cmake --install build else - echo_error "Build has failed for $distro compiling hyprlock" + echo-error "Build has failed for $distro compiling hyprlock" return 69 fi } @@ -255,7 +278,7 @@ main() { fi if ! getDependencies; then - echo_error "Error when installing dependencies.." + echo-error "Error when installing dependencies.." fi case "$distro" in @@ -266,13 +289,24 @@ main() { cloneAndBuildLock ;; *) - echo_error "$distro is not supported by this script!" + echo-error "$distro is not supported by this script!" exit 1 ;; esac } -if getImports; then +setup-env() { + # local beddu=https://git.k4li.de/scripts/beddu/raw/branch/main/dist/beddu.sh + # local pika=https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh + local dream=https://git.k4li.de/scripts/imports/raw/branch/main/dream.sh + + if ! command_exists pkg-install && ! command_exists check-and-install && ! command_exists spin; then + source-script $dream + line + fi +} + +if setup-env; then # ─< package variable >─────────────────────────────────────────────────────────────────── unset PACKAGE