Files
temp-own/install.sh
T

198 lines
7.2 KiB
Bash

#!/usr/bin/env bash
#
# temp-own — installer sekali jalan:
# fish (default shell, global) + starship (polos) + yazi + micro + lazydocker
#
# Pakai:
# curl -fsSL https://gitea.oxpoe.qzz.io/oxpoe/temp-own/raw/branch/main/install.sh | sudo bash
#
# Auto-deteksi distro (pacman / apt / dnf / zypper / apk).
# Hanya butuh sudo. Idempotent (aman dijalankan ulang).
set -euo pipefail
BLUE='\033[1;34m'; YEL='\033[1;33m'; RED='\033[1;31m'; NC='\033[0m'
log() { printf "${BLUE}==>${NC} %s\n" "$*"; }
warn() { printf "${YEL} !${NC} %s\n" "$*"; }
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" 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
x86_64|amd64) ARCH=x86_64 ;;
aarch64|arm64) ARCH=aarch64 ;;
*) ARCH="$(uname -m)" ;;
esac
PM=""
for c in pacman apt-get dnf zypper apk; do command -v "$c" >/dev/null 2>&1 && { PM="$c"; break; }; done
BIN=/usr/local/bin
# deteksi tool: di PATH atau di /usr/local/bin
has() { command -v "$1" >/dev/null 2>&1 || [ -x "$BIN/$1" ]; }
log "User=${TARGET_USER} Arch=${ARCH} PkgMgr=${PM:-none}"
# ---------------------------------------------------------------- base deps
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 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
}
log "Paket dasar (curl/unzip/tar)"; install_base || warn "sebagian paket dasar gagal (lanjut)"
# ---------------------------------------------------------------- distro pkgs
distro_install() {
local want=(fish starship yazi micro lazydocker) got=() p
case "$PM" in
apt-get)
for p in "${want[@]}"; do apt-cache show "$p" >/dev/null 2>&1 && got+=("$p"); done
[ ${#got[@]} -eq 0 ] && return 0
DEBIAN_FRONTEND=noninteractive apt-get install -y "${got[@]}" ;;
dnf)
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) 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) 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)"; }
# ---------------------------------------------------------------- upstream
ensure_fish() {
has fish && return 0
log "Non-repo: fish tak ada di repo — coba lewat manager lagi"
[ -n "$PM" ] && distro_install || true
has fish || die "fish tidak tersedia di distro ini"
}
ensure_micro() {
has micro && return 0
log "Install micro (getmic.ro -> $BIN)"
( cd "$BIN" && curl -fsSL https://getmic.ro | bash ) >/dev/null
has micro || die "micro gagal dipasang"
}
ensure_starship() {
has starship && return 0
log "Install starship (script resmi)"
curl -fsSL https://starship.rs/install.sh | sh -s -- -y --bin-dir "$BIN"
has starship || die "starship gagal dipasang"
}
ensure_yazi() {
has yazi && return 0
log "Install yazi (release GitHub)"
local tag target url tmp
tag="$(curl -fsSL -o /dev/null -w '%{url_effective}' https://github.com/sxyazi/yazi/releases/latest | sed 's#.*/tag/##')"
[ -n "$tag" ] || die "gagal menentukan versi yazi"
case "$ARCH" in
x86_64) target=x86_64-unknown-linux-gnu ;;
aarch64) target=aarch64-unknown-linux-gnu ;;
*) target="${ARCH}-unknown-linux-gnu" ;;
esac
url="https://github.com/sxyazi/yazi/releases/download/${tag}/yazi-${target}.zip"
tmp="$(mktemp -d)"
curl -fsSL "$url" -o "$tmp/yazi.zip" || die "gagal unduh $url"
unzip -q "$tmp/yazi.zip" -d "$tmp"
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"
}
ensure_lazydocker() {
has lazydocker && return 0
log "Install lazydocker (script resmi -> $BIN)"
local tmp; tmp="$(mktemp -d)"
( cd "$tmp" && curl -fsSL https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | DIR="$BIN" bash )
rm -rf "$tmp"
has lazydocker || die "lazydocker gagal dipasang"
}
log "Pastikan tool terpasang"
ensure_fish
ensure_micro
ensure_starship
ensure_yazi
ensure_lazydocker
# ---------------------------------------------------------------- config yazi
write_yazi() {
local home="$1" user="$2" file
[ -d "$home" ] || return 0
file="$home/.config/yazi/yazi.toml"
mkdir -p "$home/.config/yazi"
[ -f "$file" ] && cp -a "$file" "${file}.bak-$(date +%Y%m%d%H%M%S)"
cat > "$file" <<'EOF'
# Editor default: micro (bukan vim)
[opener]
edit = [
{ run = 'micro %s', block = true, desc = "Edit (micro)", for = "unix" },
]
EOF
chown -R "$user:$user" "$home/.config/yazi" 2>/dev/null || true
}
log "Config Yazi (editor=micro) untuk $TARGET_USER"
write_yazi "$TARGET_HOME" "$TARGET_USER"
if [ "$TARGET_USER" != root ]; then
write_yazi "/root" "root"
fi
# ---------------------------------------------------------------- fish global
FISH="$(command -v fish)"
log "Daftarkan $FISH ke /etc/shells"
grep -qxF "$FISH" /etc/shells 2>/dev/null || echo "$FISH" >> /etc/shells
log "Config fish GLOBAL: /etc/fish/conf.d/temp-own.fish"
mkdir -p /etc/fish/conf.d
cat > /etc/fish/conf.d/temp-own.fish <<'EOF'
# temp-own — berlaku untuk SEMUA user
if status is-interactive
set -gx EDITOR micro
set -gx VISUAL micro
# starship polos (default)
if command -q starship
starship init fish | source
end
end
EOF
set_shell() {
local u="$1"
id "$u" >/dev/null 2>&1 || return 0
chsh -s "$FISH" "$u" >/dev/null 2>&1 && log " default shell $u -> fish" || warn "chsh gagal untuk $u"
}
log "Jadikan fish default shell"
set_shell "$TARGET_USER"
[ "$TARGET_USER" != root ] && set_shell root
# ---------------------------------------------------------------- selesai
cat <<EOF
$(printf "${BLUE}==>${NC}") Selesai.
fish : $(command -v fish)
starship : $(command -v starship) (polos)
yazi : $(command -v yazi) (editor default: micro)
micro : $(command -v micro)
lazydocker: $(command -v lazydocker)
Logout/login (atau buka terminal baru) agar shell fish aktif.
Konfigurasi fish global: /etc/fish/conf.d/temp-own.fish
EOF