#!/usr/bin/env bash set -euo pipefail # ========================== # CONFIG # ========================== REPO_URL="${REPO_URL:-http://apt.nsts.com.vn}" DIST="${DIST:-noble}" COMPONENTS="${COMPONENTS:-main restricted universe multiverse}" LIST_FILE="/etc/apt/sources.list.d/internal.list" BACKUP_SUFFIX="$(date +%Y%m%d_%H%M%S)" # ========================== # CHECK ROOT # ========================== if [[ "$EUID" -ne 0 ]]; then echo "❌ Please run as root" exit 1 fi echo "✅ Running as root" # ========================== # BACKUP EXISTING FILE # ========================== if [[ -f "$LIST_FILE" ]]; then cp "$LIST_FILE" "${LIST_FILE}.bak.${BACKUP_SUFFIX}" echo "đŸ“Ļ Backup created: ${LIST_FILE}.bak.${BACKUP_SUFFIX}" fi # ========================== # GENERATE SOURCE CONTENT # ========================== read -r -d '' SOURCE_CONTENT </dev/null; then echo "â„šī¸ $LIST_FILE already up to date" else echo "$SOURCE_CONTENT" > "$LIST_FILE" echo "âœī¸ Written $LIST_FILE" fi # ========================== # OPTIONAL: DISABLE DEFAULT UBUNTU REPOS # ========================== if [[ "${DISABLE_DEFAULT_REPOS:-false}" == "true" ]]; then echo "âš ī¸ Disabling default Ubuntu repositories" sed -i 's|^deb http://archive.ubuntu.com|# deb http://archive.ubuntu.com|g' /etc/apt/sources.list || true sed -i 's|^deb http://security.ubuntu.com|# deb http://security.ubuntu.com|g' /etc/apt/sources.list || true fi # ========================== # APT UPDATE # ========================== echo "🔄 Running apt update" apt clean apt update echo "🎉 Internal APT repository configured successfully"