153 lines
4.7 KiB
Bash
153 lines
4.7 KiB
Bash
{
|
|
#!/usr/bin/env bash
|
|
|
|
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
|
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 = <distro name, like 'arch', 'debian', 'fedora'..>
|
|
# 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"
|
|
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"
|
|
}
|
|
|
|
getDependencies() {
|
|
echo_info "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 libgtk3.0-cli-dev libasound2-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) checkAndInstall "${pkgArray[@]}" ;;
|
|
*)
|
|
echo_warning "No dependencies for $distro.."
|
|
echo_warning "Could be good, could be bad :):"
|
|
return 0
|
|
;;
|
|
esac
|
|
}
|
|
|
|
main() {
|
|
case "$distro" in
|
|
arch)
|
|
_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 zenDir="$(mktemp -d)"
|
|
if [ -d "$HOME/.local/bin/" ]; then
|
|
local zenDir="$HOME/.local/bin/zen"
|
|
else
|
|
local zenDir="$HOME/.local/zen"
|
|
fi
|
|
|
|
cd "$zenDir" || mkdir -p "$zenDir" && cd "$zenDir"
|
|
echo_info "Downloading .tar.xz from $cloneUrl"
|
|
if command_exists wget; then
|
|
wget "$cloneUrl"
|
|
elif command_exists curl; then
|
|
curl -fsSL "$cloneUrl" -o "zen.linux-${ARCH}.tar.xz"
|
|
else
|
|
exit 69
|
|
echo_error "curl/wget is required but missing.."
|
|
fi
|
|
|
|
echo_info "Extracting archive.."
|
|
run tar -xf "./zen.linux-${ARCH}.tar.xz"
|
|
|
|
echo_info "Installing to /bin/zen-browser"
|
|
$_sudo ln -fsr ./zen/zen-bin /bin/zen-browser
|
|
;;
|
|
esac
|
|
}
|
|
|
|
setup() {
|
|
if getImports; then
|
|
case "$@" in
|
|
--silent | -s)
|
|
silent=true
|
|
echo_warning "Running script silently!"
|
|
;;
|
|
*)
|
|
silent=false
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
if ! command_exists zen-browser; then
|
|
return 0
|
|
else
|
|
echo_error "zen-browser does already exist on this machine!"
|
|
return 69
|
|
fi
|
|
}
|
|
|
|
if setup "$@"; then
|
|
getDependencies
|
|
main </dev/tty
|
|
fi
|
|
}
|