addet pika.install script
This commit is contained in:
parent
5b44177cf2
commit
091ff1034e
1 changed files with 156 additions and 0 deletions
156
pika.sh
Executable file
156
pika.sh
Executable file
|
@ -0,0 +1,156 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||
command-exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# ─< Check if the user is root and set sudo variable if necessary >───────────────────────
|
||||
check_root() {
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
if command-exists sudo; then
|
||||
echo "User is not root. Using sudo for privileged operations."
|
||||
_sudo="sudo -E"
|
||||
else
|
||||
echo "No sudo found and you're not root! Can't install packages."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "Root access confirmed."
|
||||
_sudo=""
|
||||
fi
|
||||
}
|
||||
|
||||
get-packager() {
|
||||
local packagers
|
||||
packagers=(
|
||||
apt
|
||||
dnf
|
||||
pacman
|
||||
zypper
|
||||
apk
|
||||
)
|
||||
|
||||
for packager in "${packagers[@]}"; do
|
||||
if command-exists $packager; then
|
||||
case $packager in
|
||||
apt)
|
||||
pkg-install() {
|
||||
if command-exists nala; then
|
||||
$_sudo nala install --assume-yes "$@"
|
||||
else
|
||||
$_sudo apt install --assume-yes "$@"
|
||||
fi
|
||||
}
|
||||
;;
|
||||
dnf)
|
||||
pkg-install() {
|
||||
$_sudo dnf -y install "$@"
|
||||
}
|
||||
;;
|
||||
pacman)
|
||||
pkg-install() {
|
||||
if command-exists paru; then
|
||||
paru --noconfirm -S "$@"
|
||||
elif command-exists yay; then
|
||||
yay --noconfirm -S "$@"
|
||||
else
|
||||
$_sudo pacman --noconfirm -S "$@"
|
||||
fi
|
||||
}
|
||||
;;
|
||||
zypper)
|
||||
pkg-install() {
|
||||
$_sudo zypper install "$@"
|
||||
}
|
||||
;;
|
||||
apk)
|
||||
pkg-install() {
|
||||
$_sudo apk add "$@"
|
||||
}
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
source-script() {
|
||||
i="$1"
|
||||
import="$(mktemp)"
|
||||
if command-exists curl; then
|
||||
curl -fsSL $i -o $import
|
||||
else
|
||||
echo "curl is required, but missing.."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "$import"
|
||||
sleep 0.3
|
||||
rm "$import"
|
||||
}
|
||||
|
||||
script-exists() {
|
||||
local install_url=https://git.k4li.de/scripts/installs/raw/branch/main
|
||||
local script_url
|
||||
|
||||
for pkg in "$@"; do
|
||||
script_url="${install_url}/${pkg}.sh"
|
||||
if curl -fsSL $script_url 2>/dev/null; then
|
||||
return 0
|
||||
else
|
||||
return 69
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
install-func() {
|
||||
local pkg
|
||||
for pkg in "$@"; do
|
||||
if script-exists $pkg; then
|
||||
eval "$(curl -fsSL https://git.k4li.de/scripts/installs/raw/branch/main/${pkg}.sh)"
|
||||
else
|
||||
pkg-install "$pkg"
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
help-func() {
|
||||
echo "How to use?"
|
||||
echo
|
||||
echo "pika [argument] [options]"
|
||||
echo "argument=[i|install]"
|
||||
echo "options:"
|
||||
echo "i|install: <pkg name or space separated list"
|
||||
}
|
||||
|
||||
# setup-env() {
|
||||
# local script=https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh
|
||||
#
|
||||
# if ! command-exists pkg-install && ! command-exists check-and-install; then
|
||||
# source-script $script
|
||||
# fi
|
||||
# }
|
||||
|
||||
check_root
|
||||
get-packager
|
||||
|
||||
# NOTE:
|
||||
# arguments to parse:
|
||||
# i or install = installs the package after wards either with the pika scripts,
|
||||
# or directly via the packagemanager, if no script is available under this name.
|
||||
#
|
||||
for arg in "$@"; do
|
||||
if [ -n "$arg" ]; then
|
||||
case $arg in
|
||||
install | i)
|
||||
shift
|
||||
install-func "$@"
|
||||
;;
|
||||
*)
|
||||
help-func
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
Loading…
Add table
Add a link
Reference in a new issue