skeleton: launcher, entrypoint, distro/log/prompt libs

This commit is contained in:
mk committed 2026-07-28 04:32:38 +03:00
commit 8057fbac4d
5 files changed
+196

No files matched your search

Executable
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# detect.sh — distro + arch detection. Exports DISTRO and ARCH.
detect_distro() {
DISTRO="unknown"
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
esac
if [[ -f /etc/os-release ]]; then
# shellcheck disable=SC1091
. /etc/os-release
case "${ID:-}" in
debian|ubuntu) DISTRO="debian" ;;
arch) DISTRO="arch" ;;
*)
case "${ID_LIKE:-}" in
*debian*) DISTRO="debian" ;;
*arch*) DISTRO="arch" ;;
esac ;;
esac
fi
export DISTRO ARCH
}
detect_distro
Executable
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# log.sh — tiny color log helpers.
log() { printf '\033[1;34m>>\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33m!!\033[0m %s\n' "$*" >&2; }
err() { printf '\033[1;31mxx\033[0m %s\n' "$*" >&2; }
ok() { printf '\033[1;32mok\033[0m %s\n' "$*"; }
# run a command as root when not already root
sudo_() { if (( EUID == 0 )); then "$@"; else sudo "$@"; fi; }
# run a command AS the invoking (non-root) user — used for AUR builds, etc.
# when root: drop to SUDO_USER (or USER) via runuser; when not root: run directly.
as_user() {
local u="$USER"
if (( EUID == 0 )); then
u="${SUDO_USER:-$USER}"
command -v runuser >/dev/null 2>&1 && runuser -u "$u" -- "$@" || su "$u" -c "$*"
else
"$@"
fi
}
Executable
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# prompt.sh — plain y/N prompts.
# ask "prompt?" [default y|n] -> sets REPLY
ask() {
local p="$1" d="${2:-y}" hint
if [[ "$d" == "y" ]]; then hint="[Y/n]"; else hint="[y/N]"; fi
read -rp "$p $hint " REPLY
[[ -z "$REPLY" ]] && REPLY="$d"
}
# yn "prompt?" [default] -> returns 0 (true) if answer is yes
yn() {
ask "$1" "${2:-y}"
[[ "$REPLY" =~ ^[Yy]$ ]]
}
# confirm_once "prompt?" default -> for destructive single confirm
confirm_once() { yn "$1" "${2:-n}"; }