218 lines
6.3 KiB
Bash
218 lines
6.3 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
PACKAGE=postinstallation
|
|
|
|
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
|
command-exists() {
|
|
command -v "$@" >/dev/null 2>&1
|
|
}
|
|
|
|
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"
|
|
}
|
|
|
|
get-dependencies() {
|
|
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 │
|
|
# ╰─────────────────────────────────────────────────────────────────────────╯
|
|
generalDeps=(
|
|
"awk"
|
|
"7zip"
|
|
"bc"
|
|
"btop"
|
|
"curl"
|
|
"fzf"
|
|
"gawk"
|
|
"git"
|
|
"keychain"
|
|
"make"
|
|
"pv"
|
|
"ripgrep"
|
|
"rsync"
|
|
"stow"
|
|
"sudo"
|
|
"unzip"
|
|
"vi"
|
|
"zsh"
|
|
"zoxide"
|
|
)
|
|
|
|
generalBloat=(
|
|
"nano"
|
|
)
|
|
|
|
depsDebian=(
|
|
"eza"
|
|
)
|
|
|
|
depsFedora=()
|
|
depsOpensuse=()
|
|
depsArch=(
|
|
"tldr"
|
|
"oh-my-posh"
|
|
"eza"
|
|
"ytui-bin"
|
|
)
|
|
depsAlpine=()
|
|
|
|
declare -A deps=(
|
|
[debian]="depsDebian"
|
|
[ubuntu]="depsUbuntu"
|
|
[fedora]="depsFedora"
|
|
[arch]="depsArch"
|
|
[alpine]="depsAlpine"
|
|
[opensuse]="depsOpensuse"
|
|
)
|
|
|
|
# INFO:
|
|
# ╭────────────────────────────────────────────────────────────────╮
|
|
# │ This variable stores the packages you provided for each distro │
|
|
# ╰────────────────────────────────────────────────────────────────╯
|
|
#
|
|
declare -n pkgArray="${deps[$distro]}"
|
|
|
|
case "$distro" in
|
|
debian | ubuntu | arch | fedora | alpine | opensuse)
|
|
pen bold blue "Installing base packages.."
|
|
|
|
check-and-install ${generalDeps[@]}
|
|
|
|
check-and-install ${pkgArray[@]}
|
|
;;
|
|
*)
|
|
echo-error "There are no dependencies to install for $distro"
|
|
return 0
|
|
;;
|
|
esac
|
|
}
|
|
|
|
removeBloat() {
|
|
if ! $arch; then
|
|
spin "Removing bloat.."
|
|
for pkg in "${generalBloat[@]}"; do
|
|
if run --err err pkg-remove "$pkg"; then
|
|
upclear
|
|
check "Removed $pkg"
|
|
else
|
|
upclear
|
|
throw "Error while removing $pkg"
|
|
echo-error "${err:-}"
|
|
fi
|
|
done
|
|
else
|
|
pen bold blue "There are no pacakges to remove on arch.."
|
|
fi
|
|
}
|
|
|
|
init-nala() {
|
|
if command-exists nala; then
|
|
# pen bold blue "Nala is already present, fetching mirros now!"
|
|
# pen bold yellow "(This might take a minute or two, depending on your internet speed)"
|
|
if confirm "Nala is already present. Do you want to auto fetch the best mirrors?"; then
|
|
check green bold "Depending on your internet speed, this might take a while.."
|
|
$_sudo nala fetch --auto --assume-yes --https-only
|
|
fi
|
|
else
|
|
if confirm "Nala is not installed on the system, do you want to install it now?" </dev/tty; then
|
|
spin bold yellow "Installing nala.."
|
|
if run --err err $_sudo apt install nala --assume-yes; then
|
|
upclear
|
|
check bold green "Installed nala"
|
|
else
|
|
throw "Error installing nala!"
|
|
fi
|
|
|
|
pen bold blue "Fetching best mirrors"
|
|
$_sudo nala fetch --auto --assume-yes --https-only
|
|
fi
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
if $silent; then
|
|
pen bold yellow "Executing script silently!"
|
|
fi
|
|
|
|
# Getting general dependencies
|
|
if ! get-dependencies; then
|
|
echo-error "Error when installing dependencies.."
|
|
fi
|
|
|
|
# removing 'bloat'
|
|
if ! removeBloat; then
|
|
echo-error "Error when removing bloat.."
|
|
fi
|
|
|
|
case "$distro" in
|
|
debian | ubuntu)
|
|
# Path to sources.list
|
|
sources_file="/etc/apt/sources.list"
|
|
|
|
# Check if file exists
|
|
if [ -f "$sources_file" ]; then
|
|
# Comment out CD-ROM entries using sudo
|
|
$_sudo sed -i 's/^[[:space:]]*deb[[:space:]]\+cdrom:/#&/' "$sources_file"
|
|
pen bold blue "CD-ROM entries have been commented out in $sources_file"
|
|
else
|
|
if [ ! -f "/etc/apt/sources.d/sources.list" ]; then
|
|
echo-error "Error: $sources_file not found"
|
|
fi
|
|
fi
|
|
init-nala
|
|
;;
|
|
*)
|
|
pen bold yellow "There are no distro specific things to install for your distro: $(pen bold red $distro)"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# 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 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
|
|
|
|
PACKAGE=postinstallation
|
|
|
|
main
|
|
fi
|