296 lines
8 KiB
Bash
296 lines
8 KiB
Bash
{
|
|
#!/usr/bin/env bash
|
|
|
|
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
|
command_exists() {
|
|
command -v "$@" >/dev/null 2>&1
|
|
}
|
|
|
|
getImports() {
|
|
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"
|
|
|
|
echo "${BLUE}Sourcing external script:${NC} $url"
|
|
|
|
sleep 0.1
|
|
rm -f "$import"
|
|
}
|
|
|
|
setup-env() {
|
|
# 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..
|
|
#
|
|
# 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
|
|
# dream ~= combined beddu and pika
|
|
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 pen; then
|
|
getImports $dream
|
|
fi
|
|
}
|
|
|
|
getDependencies() {
|
|
# INFO:
|
|
# ╭─────────────────────────────────────────────────────────────────────────╮
|
|
# │ You can define dependencies for various linux distros here. It will │
|
|
# │ automagically be pulled via the $pkgArray[$distro] variable │
|
|
# ╰─────────────────────────────────────────────────────────────────────────╯
|
|
generalDeps=(
|
|
git
|
|
wget
|
|
)
|
|
|
|
depsDebian=(
|
|
build-essential
|
|
libpam0g-dev
|
|
libxcb-xkb-dev
|
|
)
|
|
# depsUbuntu=()
|
|
depsFedora=(
|
|
kernel-devel
|
|
pam-devel
|
|
libxcb-devel
|
|
zig
|
|
)
|
|
# depsOpensuse=()
|
|
# depsArch=()
|
|
# depsAlpine=()
|
|
|
|
declare -A deps=(
|
|
[debian]="depsDebian"
|
|
[ubuntu]="depsDebian"
|
|
[fedora]="depsFedora"
|
|
# [arch]="depsArch"
|
|
# [alpine]="depsAlpine"
|
|
# [opensuse]="depsOpensuse"
|
|
)
|
|
|
|
# INFO:
|
|
# ╭────────────────────────────────────────────────────────────────╮
|
|
# │ This variable stores the packages you provided for each distro │
|
|
# ╰────────────────────────────────────────────────────────────────╯
|
|
declare -n pkgArray="${deps[$distro]}"
|
|
|
|
pkgArray="${pkgArray[@]} ${generalDeps[@]}"
|
|
|
|
case "$distro" in
|
|
debian | ubuntu | arch | fedora | alpine | opensuse)
|
|
check-and-install ${pkgArray[@]}
|
|
;;
|
|
*)
|
|
pen bold yellow "There are no dependencies to install for $distro"
|
|
return 0
|
|
;;
|
|
esac
|
|
}
|
|
|
|
check-zig-path() {
|
|
if ! command_exists zig; then
|
|
export PATH="$ZIG_PATH:$PATH"
|
|
else
|
|
check-zig
|
|
fi
|
|
}
|
|
|
|
check-zig() {
|
|
if command_exists zig; then
|
|
local version_needed version_current
|
|
|
|
version_needed=0.14.0
|
|
version_current=$(zig version)
|
|
|
|
if [ "$version_current" != "$version_needed" ]; then
|
|
throw "Version missmatch, you have $version_current, needed is $version_needed"
|
|
return 69
|
|
fi
|
|
|
|
# return no exit code if zig version is correct
|
|
return 0
|
|
else
|
|
return 69
|
|
fi
|
|
}
|
|
|
|
get-zig() {
|
|
local err out zigInstallPath arch url zigtemp zigBinPath tarfile
|
|
|
|
arch=$(uname -m)
|
|
url="https://ziglang.org/download/0.14.0/zig-linux-${arch}-0.14.0.tar.xz"
|
|
zigtemp=$(mktemp -d)
|
|
zigBinPath="zig-0.14.0"
|
|
tarfile=*.tar.xz
|
|
|
|
spin bold blue "Getting zig 0.14.0 from $url.."
|
|
|
|
if [ -d "$HOME/.bin" ]; then
|
|
zigInstallPath="$HOME/.bin"
|
|
else
|
|
zigInstallPath="$HOME/.local/bin"
|
|
fi
|
|
|
|
cd "$zigtemp" || mkdir -p "$zigtemp" && cd "$zigtemp" || exit 0
|
|
|
|
if run --err err --out out wget "$url"; then
|
|
upclear
|
|
check bold green "zig download complete!"
|
|
else
|
|
upclear
|
|
throw bold red "${out:-}"
|
|
echo-error "${err:-}"
|
|
fi
|
|
|
|
spin grey "Extracting archive.."
|
|
|
|
# representing the whole zig path
|
|
local zig="${zigInstallPath}/${zigBinPath}"
|
|
|
|
[[ ! -d "$zig" ]] && mkdir -p "$zig"
|
|
|
|
if run --err err --out out tar --strip-components=1 -xJf $tarfile -C "$zig"; then
|
|
upclear
|
|
check bold green "Archive extracted!"
|
|
else
|
|
upclear
|
|
throw bold red "${out:-}"
|
|
echo-error "${err:-}"
|
|
fi
|
|
|
|
# line
|
|
# pen bold green "ZIG_PATH=$zig"
|
|
# line
|
|
|
|
[[ -d "$zig" ]] && ZIG_PATH="$zig" || throw bold red "Something went terribly wrong!"
|
|
|
|
check-zig-path
|
|
}
|
|
|
|
get-ly() {
|
|
local url tempdir err out
|
|
|
|
url="https://codeberg.org/AnErrupTion/ly"
|
|
tempdir=$(mktemp -d)
|
|
|
|
spin bold yellow "Cloning ly from $url.."
|
|
cd $tempdir || mkdir -p $tempdir && cd $tempdir
|
|
|
|
if run --err err --out ou git clone --depth=1 $url; then
|
|
upclear
|
|
check "Cloned ly"
|
|
else
|
|
upclear
|
|
pen bold red "Cloning ly failed hard!"
|
|
throw bold red "${out:-}"
|
|
echo-error "${err:-}"
|
|
return 69
|
|
fi
|
|
|
|
cd ly || echo-error "cannot cd into ly"
|
|
}
|
|
|
|
build-ly() {
|
|
build-error() {
|
|
upclear
|
|
pen bold red "Could not build ly!"
|
|
throw bold red "${out:-}"
|
|
echo-error "${err:-}"
|
|
return 69
|
|
}
|
|
|
|
spin bold blue "Building ly with zig.."
|
|
|
|
# zig init
|
|
|
|
if run --err err --out out zig build; then
|
|
# if run --err err --out out zig build installexe; then
|
|
check "."
|
|
if zig build installexe; then
|
|
upclear
|
|
check "Build ly with zig successfully!"
|
|
else
|
|
build-error
|
|
fi
|
|
else
|
|
build-error
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
if $silent; then
|
|
pen yellow "ARG: Executing script silently!"
|
|
fi
|
|
|
|
case "$distro" in
|
|
arch | ubuntu | debian | fedora)
|
|
if ! getDependencies; then
|
|
throw "Error when installing dependencies.."
|
|
fi
|
|
|
|
if ! check-zig; then
|
|
get-zig
|
|
fi
|
|
|
|
get-ly
|
|
build-ly
|
|
|
|
if command_exists ly; then
|
|
line
|
|
check "Installed ly successfully!"
|
|
fi
|
|
;;
|
|
*)
|
|
echo "$distro is not supported by this script!"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
if setup-env; then
|
|
# ─< package variable >───────────────────────────────────────────────────────────────────
|
|
unset PACKAGE
|
|
|
|
# ─< argument list variables >────────────────────────────────────────────────────────────
|
|
silent=false
|
|
|
|
sleep 0.1
|
|
|
|
PACKAGE=ly
|
|
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
|
|
fi
|
|
}
|