{ #!/usr/bin/env bash # ─< Check if the given command exists silently >───────────────────────────────────────── command_exists() { command -v "$@" >/dev/null 2>&1 } source-script() { local url="$1" local import="$(mktemp)" # ─< 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 } getDependencies() { pen bold blue "Checking build dependencies.." # INFO: # ╭─────────────────────────────────────────────────────────────────────────╮ # │ You can define dependencies for various linux distros here. It will │ # │ automagically be pulled via the $pkgArray[$distro] variable │ # ╰─────────────────────────────────────────────────────────────────────────╯ depsDebian=(wget libgtk-3-dev) depsFedora=(wget) depsOpensuse=(wget) # depsArch=() # depsAlpine=() declare -A deps=( [debian]="depsDebian" [ubuntu]="depsDebian" [fedora]="depsFedora" [opensuse]="depsOpensuse" # [arch]="depsArch" # [alpine]="depsAlpine" ) # INFO: # ╭────────────────────────────────────────────────────────────────╮ # │ This variable stores the packages you provided for each distro │ # ╰────────────────────────────────────────────────────────────────╯ declare -n pkgArray="${deps[$distro]}" case "$distro" in debian | ubuntu | fedora | opensuse) check-and-install ${pkgArray[@]} ;; *) pen bold yellow "No dependencies for $distro.." pen bold yellow "Could be good, could be bad :):" return 0 ;; esac } main() { if $silent; then pen bold yellow "Executing script silently!" fi # if ! getDependencies; then # echo-error "Error when installing dependencies.." # fi case "$distro" in arch) pkg-install zen-browser-bin ;; *) getDependencies # Detect system architecture ARCH=$(uname -m) case "$ARCH" in x86_64) ARCH="x86_64" ;; aarch64 | arm64) ARCH="aarch64" ;; *) echo-error "❌ Unsupported architecture: $ARCH" >&2 exit 1 ;; esac cloneUrl="https://github.com/zen-browser/desktop/releases/latest/download/zen.linux-${ARCH}.tar.xz" local tempDir="$(mktemp -d)" if [ -d "$HOME/.local/bin/" ]; then local zenDir="$HOME/.local/bin" else if [ ! -d "$HOME/.local" ]; then mkdir -p "$HOME/.local" fi local zenDir="$HOME/.local" fi # cd "$zenDir" || mkdir -p "$zenDir" && cd "$zenDir" cd "$tempDir" || mkdir -p "$tempDir" && cd "$tempDir" spin bold blue "Downloading .tar.xz from $cloneUrl" local err out if command_exists wget; then if run --err err --out out wget "$cloneUrl"; then upclear check "Done pulling archive" else upclear throw-err # throw "Error pulling archive" # pen bold yellow "OUT: ${out:-}" # echo-error "${err:-}" fi elif command_exists curl; then if run --err err --out out curl -fsSL "$cloneUrl" -o "zen.linux-${ARCH}.tar.xz"; then upclear check "Done pulling archive" else upclear throw-err # throw "Error pulling archive" # pen bold yellow "OUT: ${out:-}" # echo-error "${err:-}" fi # curl -fsSL "$cloneUrl" -o "zen.linux-${ARCH}.tar.xz" else echo-error "curl/wget is required but missing.." exit 69 fi spin bold blue "Extracting archive.." if run --err err --out out tar -xf "./zen.linux-${ARCH}.tar.xz" -C "$zenDir"; then upclear check "Extracted archive.." else upclear throw-err # throw "Error extracting archive" # pen bold yellow "OUT: ${out:-}" # echo-error "${err:-}" fi pen bold blue "Installing to /bin/zen-browser" $_sudo ln -fsr "$zenDir/zen/zen-bin" /bin/zen-browser ;; esac } # 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 pkg-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.. 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 # ─< argument list variables >──────────────────────────────────────────────────────────── silent=false sleep 0.1 PACKAGE=zen-browser if command_exists "$PACKAGE"; then pen bold yellow "$PACKAGE is already installed!" pen bold yellow "Exiting now!" exit 69 fi # ─< parse arguments and get variable contents >────────────────────────────────────────── for arg in "$@"; do case "$arg" in --silent | -s) export silent=true ;; esac done main