fix: pasang paket distro per-paket (apk/pacman/zypper), fallback $HOME tanpa getent, yazi cp+chmod

This commit is contained in:
oxpoe committed 2026-10-15 02:10:36 +07:00
1 parent 79a99a1e84
commit 23f51898f1
1 file changed
+13 -11
+13 -11
View File
@@ -19,8 +19,10 @@ die() { printf "${RED} x${NC} %s\n" "$*" >&2; exit 1; }
[ "${EUID:-$(id -u)}" -eq 0 ] || die "Jalankan dengan sudo: curl -fsSL <url> | sudo bash"
TARGET_USER="${SUDO_USER:-root}"
TARGET_HOME="$(getent passwd "$TARGET_USER" | cut -d: -f6 || true)"
[ -n "${TARGET_HOME:-}" ] && [ -d "$TARGET_HOME" ] || die "Home untuk '${TARGET_USER}' tidak ditemukan."
TARGET_HOME="$(getent passwd "$TARGET_USER" 2>/dev/null | cut -d: -f6 || true)"
[ -n "${TARGET_HOME:-}" ] || TARGET_HOME="$(awk -F: -v u="$TARGET_USER" '$1==u{print $6}' /etc/passwd 2>/dev/null || true)"
[ -n "${TARGET_HOME:-}" ] || TARGET_HOME="${HOME:-/root}"
[ -d "$TARGET_HOME" ] || die "Home untuk '${TARGET_USER}' tidak ditemukan."
[ "$TARGET_USER" = root ] && warn "SUDO_USER tak terdeteksi — config user ditulis untuk root."
case "$(uname -m)" in
@@ -42,11 +44,11 @@ log "User=${TARGET_USER} Arch=${ARCH} PkgMgr=${PM:-none}"
install_base() {
case "$PM" in
apt-get) DEBIAN_FRONTEND=noninteractive apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq curl unzip tar ca-certificates ;;
dnf) dnf install -y -q curl unzip tar ca-certificates ;;
pacman) pacman -S --needed --noconfirm curl unzip tar ca-certificates ;;
zypper) zypper --non-interactive install curl unzip tar ca-certificates ;;
apk) apk add --no-cache curl unzip tar ca-certificates ;;
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq curl unzip tar gzip bash ca-certificates ;;
dnf) dnf install -y -q curl unzip tar gzip bash ca-certificates ;;
pacman) pacman -S --needed --noconfirm curl unzip tar gzip bash ca-certificates ;;
zypper) zypper --non-interactive install curl unzip tar gzip bash ca-certificates ;;
apk) apk add --no-cache curl unzip tar gzip bash ca-certificates ;;
*) warn "Paket manager tak dikenal — lewati paket dasar." ;;
esac
}
@@ -64,9 +66,9 @@ distro_install() {
for p in "${want[@]}"; do dnf -q list --available "$p" >/dev/null 2>&1 && got+=("$p"); done
[ ${#got[@]} -eq 0 ] && return 0
dnf install -y "${got[@]}" ;;
pacman) pacman -S --needed --noconfirm "${want[@]}" ;;
pacman) for p in "${want[@]}"; do pacman -S --needed --noconfirm "$p" >/dev/null 2>&1 || true; done ;;
zypper) for p in "${want[@]}"; do zypper --non-interactive install "$p" >/dev/null 2>&1 || true; done ;;
apk) apk add --no-cache "${want[@]}" 2>/dev/null || true ;;
apk) for p in "${want[@]}"; do apk add --no-cache "$p" >/dev/null 2>&1 || true; done ;;
esac
}
[ -n "$PM" ] && { log "Coba paket distro"; distro_install || warn "sebagian paket distro gagal (lanjut upstream)"; }
@@ -108,8 +110,8 @@ ensure_yazi() {
tmp="$(mktemp -d)"
curl -fsSL "$url" -o "$tmp/yazi.zip" || die "gagal unduh $url"
unzip -q "$tmp/yazi.zip" -d "$tmp"
install -m0755 "$tmp/yazi-${target}/yazi" "$BIN/yazi"
install -m0755 "$tmp/yazi-${target}/ya" "$BIN/ya"
cp -f "$tmp/yazi-${target}/yazi" "$BIN/yazi"; chmod 0755 "$BIN/yazi"
cp -f "$tmp/yazi-${target}/ya" "$BIN/ya"; chmod 0755 "$BIN/ya"
rm -rf "$tmp"
has yazi || die "yazi gagal dipasang"
}