#!/usr/bin/env bash set -euo pipefail export DEBIAN_FRONTEND=noninteractive echo "=========================================================" echo " 1. Updating System Package Repositories..." echo "=========================================================" if command -v apt-get >/dev/null; then sudo apt-get update -y elif command -v pacman >/dev/null; then sudo pacman -Sy --noconfirm elif command -v apk >/dev/null; then sudo apk update elif command -v dnf >/dev/null; then sudo dnf makecache elif command -v zypper >/dev/null; then sudo zypper refresh elif command -v brew >/dev/null; then brew update fi echo "=========================================================" echo " 2. Ensuring Git is Installed..." echo "=========================================================" if ! command -v git >/dev/null; then echo "[+] Installing git..." if command -v apt-get >/dev/null; then sudo apt-get install -y git elif command -v pacman >/dev/null; then sudo pacman -S --noconfirm git elif command -v apk >/dev/null; then sudo apk add git elif command -v dnf >/dev/null; then sudo dnf install -y git elif command -v yum >/dev/null; then sudo yum install -y git elif command -v zypper >/dev/null; then sudo zypper install -y git elif command -v brew >/dev/null; then brew install git fi else echo "[+] Git is already installed." fi # Detect hostname robustly without external 'hostname' command dependency if command -v hostname >/dev/null; then MY_HOSTNAME=$(hostname) elif [[ -f /proc/sys/kernel/hostname ]]; then MY_HOSTNAME=$(cat /proc/sys/kernel/hostname) elif [[ -f /etc/hostname ]]; then MY_HOSTNAME=$(cat /etc/hostname) else MY_HOSTNAME="${HOSTNAME:-unknown-host}" fi # 3. Setup secure .ssh directory KEY_NAME="alz@${MY_HOSTNAME}" KEY_PATH="$HOME/.ssh/$KEY_NAME" mkdir -p ~/.ssh && chmod 700 ~/.ssh # 4. Securely prompt for the private key interactively (handling multi-line input) echo "=========================================================" echo "Please paste your private SSH key for Codeberg." echo "Press [Enter] then [Ctrl+D] on a new line to finish:" echo "=========================================================" cat > "$KEY_PATH" chmod 600 "$KEY_PATH" # 5. Add Codeberg host key and configure SSH ssh-keyscan codeberg.org >> ~/.ssh/known_hosts 2>/dev/null cat << EOF >> ~/.ssh/config Host codeberg.org HostName codeberg.org User git IdentityFile $KEY_PATH IdentitiesOnly yes EOF chmod 600 ~/.ssh/config # 6. Clone dotfiles to clean, visible ~/dotfiles folder (no leading dot) echo "=========================================================" echo " 3. Cloning Dotfiles Repository..." echo "=========================================================" git clone ssh://git@codeberg.org/axell/dotfiles.git ~/dotfiles # 7. Run the installer echo "=========================================================" echo " 4. Running Dotfiles Installer..." echo "=========================================================" bash ~/dotfiles/install.sh