#!/bin/bash # # sync-bashrc-all.sh (v3) # # 0. Pastikan dependency vivid + fastfetch tersedia # 1. Sinkronkan /etc/skel/.bashrc # 2. Sinkronkan /etc/shell-prompt.sh # 3. Sinkronkan /etc/fastfetch/config.jsonc # 4. Terapkan .bashrc ke semua user existing di /home # 5. Terapkan .bashrc yang sama ke root # # Jalankan: sudo bash sync-bashrc-all.sh set -euo pipefail export DEBIAN_FRONTEND=noninteractive BASHRC_URL="https://gist.darto.id/dartokloning/866220d4bda046fe93508ed50dac1965/download/HEAD/.bashrc" PROMPT_URL="https://gist.darto.id/dartokloning/def50cb1b3024c3b8683960c873caf34/download/HEAD/shell-prompt.sh" FASTFETCH_CONFIG_URL="https://gist.darto.id/dartokloning/655822e458964d0a93085c205506443f/download/HEAD/config.jsonc" SKEL_BASHRC="/etc/skel/.bashrc" PROMPT_FILE="/etc/shell-prompt.sh" FASTFETCH_CONFIG_FILE="/etc/fastfetch/config.jsonc" if [ "$(id -u)" -ne 0 ]; then echo "Skrip ini harus dijalankan sebagai root (pakai sudo)." >&2 exit 1 fi TMP_DIR="$(mktemp -d)" trap 'rm -rf "$TMP_DIR"' EXIT fetch() { local url="$1" dest="$2" if ! wget -q -O "$dest" "$url"; then echo "Error: gagal download $url (cek koneksi internet)." >&2 exit 1 fi } sync_file() { local url="$1" dest="$2" label="$3" mode="${4:-}" local tmp="$TMP_DIR/$(basename "$dest")" fetch "$url" "$tmp" mkdir -p "$(dirname "$dest")" if [ ! -f "$dest" ] || ! cmp -s "$tmp" "$dest"; then cp "$tmp" "$dest" [ -n "$mode" ] && chmod "$mode" "$dest" echo " -> $label diperbarui." return 0 else echo " -> $label sudah sesuai, tidak ada perubahan." return 1 fi } apply_bashrc() { local user="$1" home_dir="$2" local target="$home_dir/.bashrc" local backup="$home_dir/.bashrc.original" if [ -f "$target" ] && cmp -s "$SKEL_BASHRC" "$target"; then echo "[SKIP] $user - .bashrc sudah sesuai template" return fi if [ -f "$target" ] && [ ! -f "$backup" ]; then cp -a "$target" "$backup" echo "[BACKUP] $user - .bashrc lama disimpan sebagai .bashrc.original" fi cp "$SKEL_BASHRC" "$target" if [ "$user" = "root" ]; then chown root:root "$target" else chown "$user":"$(id -gn "$user")" "$target" fi echo "[APPLY] $user - .bashrc diperbarui dari template skel" } echo "== 0. Pastikan dependency (vivid, fastfetch) terinstall ==" need_install=() command -v vivid >/dev/null 2>&1 || need_install+=("vivid") command -v fastfetch >/dev/null 2>&1 || need_install+=("fastfetch") if [ "${#need_install[@]}" -gt 0 ]; then echo " -> Menginstall: ${need_install[*]}" apt-get update -qq apt-get install -y "${need_install[@]}" else echo " -> vivid & fastfetch sudah terinstall, skip." fi echo echo "== 1. Cek /etc/skel/.bashrc ==" sync_file "$BASHRC_URL" "$SKEL_BASHRC" "$SKEL_BASHRC" || true echo echo "== 2. Cek /etc/shell-prompt.sh ==" sync_file "$PROMPT_URL" "$PROMPT_FILE" "$PROMPT_FILE" "644" || true echo echo "== 3. Cek /etc/fastfetch/config.jsonc ==" sync_file "$FASTFETCH_CONFIG_URL" "$FASTFETCH_CONFIG_FILE" "$FASTFETCH_CONFIG_FILE" "644" || true echo echo "== 4. Terapkan template ke user existing di /home ==" for home_dir in /home/*/; do [ -d "$home_dir" ] || continue home_dir="${home_dir%/}" user="$(basename "$home_dir")" id "$user" >/dev/null 2>&1 || continue apply_bashrc "$user" "$home_dir" done echo echo "== 5. Terapkan template ke root ==" apply_bashrc "root" "/root" echo echo "Selesai." echo "User yang sedang login perlu 'source ~/.bashrc' atau login ulang." echo "Untuk menguji root prompt: sudo -i"