diff --git a/install.sh b/install.sh index 7d91098..32fc5f9 100755 --- a/install.sh +++ b/install.sh @@ -1,142 +1,122 @@ #!/bin/bash -i +# +# Purpose : HamPack installer # Print the logo print_logo() { - cat << "EOF" - + cat << "EOF" ██╗ ██╗ █████╗ ███╗ ███╗██████╗ █████╗ ██████╗██╗ ██╗ ██║ ██║██╔══██╗████╗ ████║██╔══██╗██╔══██╗██╔════╝██║ ██╔╝ ███████║███████║██╔████╔██║██████╔╝███████║██║ █████╔╝ ██╔══██║██╔══██║██║╚██╔╝██║██╔═══╝ ██╔══██║██║ ██╔═██╗ ██║ ██║██║ ██║██║ ╚═╝ ██║██║ ██║ ██║╚██████╗██║ ██╗ - ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ - - + ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ EOF } -# Parse command line arguments -DEV_ONLY=false -while [[ "$#" -gt 0 ]]; do - case $1 in - --dev-only) DEV_ONLY=true; shift ;; - *) echo "Unknown parameter: $1"; exit 1 ;; - esac - done +# Install packages helper +install_packages() { + local packages=("$@") + if [[ ${#packages[@]} -eq 0 ]]; then + echo "Warning: no packages to install." + return + fi + yay -S --needed --noconfirm "${packages[@]}" +} -# Clear screen and show logo +# Install yay AUR helper +install_yay() { + if command -v yay &> /dev/null; then + echo "yay is already installed, skipping." + return + fi + + echo "Installing yay AUR helper..." + sudo pacman -S --needed --noconfirm git base-devel + + if [[ -d "yay" ]]; then + echo "Removing leftover yay directory..." + rm -rf yay + fi + + echo "Cloning yay repository..." + git clone https://aur.archlinux.org/yay.git + + echo "Building yay..." + cd yay + makepkg -si --noconfirm + cd .. + + echo "Cleaning up..." + rm -rf yay + + echo "yay installed successfully." +} + +# Sync a file from src to dst if src is newer +sync_file() { + local src="$1" + local dst="$2" + local max_retries=3 + local retries=0 + + while true; do + if [ "$src" -nt "$dst" ]; then + retries=$((retries + 1)) + if [ "$retries" -ge "$max_retries" ]; then + echo "Error: failed to sync $src after $max_retries attempts, exiting." + exit 1 + fi + echo "Source is newer than destination, updating (attempt $retries)..." + sudo cp -p "$src" "$dst" + continue + fi + echo "$(basename "$dst") is up to date, proceeding..." + break + done +} + +# --- Main --- + +set -e clear print_logo -cd - - - +cd ~ sudo -v echo "Getting the latest version of HamPack..." - rm -rf ~/.local/share/HamPack -git clone https://gitea.young.computer/david/HamPack.git ~/.local/share/HamPack >/dev/null +git clone https://gitea.young.computer/david/HamPack.git ~/.local/share/HamPack > /dev/null -SRC="$HOME/.local/share/HamPack/hampackupdate" -DST="$HOME/.local/bin/hampackupdate" - -MAX_RETRIES=3 -retries=0 - -while true; do - if [ "$SRC" -nt "$DST" ]; then - retries=$((retries + 1)) - if [ "$retries" -ge "$MAX_RETRIES" ]; then - echo "Error: failed to sync files after $MAX_RETRIES attempts, exiting." - exit 1 - fi - echo "Source is newer than destination, updating (attempt $retries)..." - sudo cp -p "$SRC" "$DST" - continue - fi - - echo "Destination is up to date, proceeding..." - break -done +sync_file "$HOME/.local/share/HamPack/hampackupdate" "$HOME/.local/bin/hampackupdate" sudo cp ~/.local/share/coredesktop/hampackrefresh ~/.local/bin/hampackrefresh -# Exit on any error - -set -e - cd ~/.local/share/HamPack -# Source the packages list - if [ ! -f "packages.conf" ]; then echo "Error: packages.conf not found!" + exit 1 fi - source packages.conf -# Update the system first - echo "Updating system..." sudo pacman -Syu --noconfirm -cd ~/ +cd ~ +install_yay -# Install yay AUR helper if not present +echo "Installing system utilities..." +install_packages "${UTILITIES[@]}" -if command -v yay &> /dev/null; then - echo "yay is already installed, skipping." - exit 0 -fi +echo "Installing applications..." +install_packages "${APPLICATIONS[@]}" -echo "Installing yay AUR helper..." -sudo pacman -S --needed --noconfirm git base-devel - -# Clean up any leftover yay directory from a previous failed install -if [[ -d "yay" ]]; then - echo "Removing leftover yay directory..." - rm -rf yay -fi - -echo "Cloning yay repository..." -git clone https://aur.archlinux.org/yay.git - -echo "Building yay..." -cd yay -makepkg -si --noconfirm -cd .. - -echo "Cleaning up..." -rm -rf yay - -echo "yay installed successfully." - -# Install packages by category - -if [[ "$DEV_ONLY" == true ]]; then - # Only install essential development packages - echo "Installing system utilities..." - install_packages "${UTILITIES[@]}" - - echo "Installing development tools..." - install_packages "${APPLICATIONS[@]}" -else - # Install all packages - echo "Installing system utilities..." - install_packages "${UTILITIES[@]}" - - echo "Installing development tools..." - install_packages "${APPLICATIONS[@]}" - cd ~/.local/share/HamPack -# Install Flatpack applications +echo "Installing Flatpak applications..." +. install-flatpaks.sh -echo "Installing Flatpack Applications..." - -. install-flatpacks.sh - -echo "Done, for now." +echo "HamPack installation complete." \ No newline at end of file