#!/usr/bin/env bash set -e echo "=================================" echo " System Installer" echo "=================================" OS="unknown" if [[ -f /etc/os-release ]]; then source /etc/os-release OS="$ID" elif [[ -f /etc/debian_version ]]; then OS="debian" elif [[ -f /etc/redhat-release ]]; then OS="rhel" fi echo "Detected OS: $OS" BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" MIRROR_DIR="$BASE_DIR/mirrors/os" # Normalize distro name to match mirror scripts case "$OS" in ubuntu) DISTRO="ubuntu" ;; debian) DISTRO="debian" ;; alpine) DISTRO="alpine" ;; arch) DISTRO="archlinux" ;; manjaro) DISTRO="manjaro" ;; fedora) DISTRO="fedora" ;; rocky) DISTRO="rocky" ;; centos) DISTRO="centos" ;; opensuse*|opensuse-leap|opensuse-tumbleweed) DISTRO="opensuse" ;; kali) DISTRO="kali" ;; almalinux) DISTRO="almalinux" ;; *) DISTRO="$OS" ;; esac read -rp "Set custom DNS servers? (y/n): " SET_DNS if [[ "$SET_DNS" == "y" ]]; then read -rp "Enter DNS server (example 1.1.1.1): " DNS if systemctl is-active --quiet systemd-resolved 2>/dev/null; then echo "Configuring DNS via systemd-resolved..." if grep -q "^DNS=" /etc/systemd/resolved.conf; then sed -i "s/^DNS=.*/DNS=$DNS/" /etc/systemd/resolved.conf else sed -i "/^\[Resolve\]/a DNS=$DNS" /etc/systemd/resolved.conf fi systemctl restart systemd-resolved else echo "Configuring DNS via /etc/resolv.conf..." echo "nameserver $DNS" > /etc/resolv.conf fi fi # Mirror configuration read -rp "Configure package mirror? (y/n): " MIRROR_SETUP if [[ "$MIRROR_SETUP" == "y" ]]; then echo "Select mirror provider:" echo "1) Liara" echo "2) ArvanCloud" echo "3) Runflare" read -rp "Choice [1-3]: " PROVIDER case "$PROVIDER" in 1) MIRROR_PROVIDER="liara" ;; 2) MIRROR_PROVIDER="arvancloud" ;; 3) MIRROR_PROVIDER="runflare" ;; *) echo "Invalid mirror provider"; exit 1 ;; esac MIRROR_SCRIPT="$MIRROR_DIR/$MIRROR_PROVIDER/$DISTRO.sh" if [[ -f "$MIRROR_SCRIPT" ]]; then echo "Applying $MIRROR_PROVIDER mirror for $DISTRO..." bash "$MIRROR_SCRIPT" else echo "No mirror script found for $DISTRO with provider $MIRROR_PROVIDER" fi fi if [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then echo "Updating package lists..." apt update echo "Installing development packages..." apt install -y \ git \ curl \ wget \ vim \ htop \ build-essential \ ca-certificates \ gnupg \ lsb-release \ software-properties-common read -rp "Enable automatic security updates? (y/n): " AUTOUP if [[ "$AUTOUP" == "y" ]]; then apt install -y unattended-upgrades dpkg-reconfigure -plow unattended-upgrades fi fi read -rp "Install Docker using docker/install.sh? (y/n): " INSTALL_DOCKER if [[ "$INSTALL_DOCKER" == "y" ]]; then if [[ -f "$BASE_DIR/docker/install.sh" ]]; then bash "$BASE_DIR/docker/install.sh" else echo "$BASE_DIR/docker/install.sh not found" fi fi echo "Installer complete"