From ab40804b7029dfe5f8166bb607702eb4b0067276 Mon Sep 17 00:00:00 2001 From: David Young Date: Thu, 19 Mar 2026 15:30:18 -0600 Subject: [PATCH] refactor install --- install.sh | 122 +++++++++++++++++++---------------------------------- 1 file changed, 43 insertions(+), 79 deletions(-) diff --git a/install.sh b/install.sh index ae9aaca..7c8c959 100755 --- a/install.sh +++ b/install.sh @@ -18,78 +18,6 @@ print_logo() { EOF } -# Install packages helper -install_packages() { - local conf_file="$HOME/.local/share/HamPack/packages.conf" - - if [ ! -f "$conf_file" ]; then - echo "Error: packages.conf not found at $conf_file" - exit 1 - fi - - source "$conf_file" - - if [[ ${#PACKAGES[@]} -eq 0 ]]; then - echo "Warning: no packages to install." - return - fi - - echo "Installing ${#PACKAGES[@]} packages..." - yay -S --needed --noconfirm "${PACKAGES[@]}" -} - -# 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 @@ -104,13 +32,15 @@ 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 -sync_file "$HOME/.local/share/HamPack/hampackupdate" "$HOME/.local/bin/hampackupdate" -sync_file "$HOME/.local/share/HamPack/hampackrefresh" "$HOME/.local/bin/hampackrefresh" - -# sudo cp ~/.local/share/HamPack/hampackrefresh ~/.local/bin/hampackrefresh +sudo cp ~/.local/share/HamPack/hampackrefresh ~/.local/bin/hampackrefresh +sudo cp ~/.local/share/HamPack/hampackupdate ~/.local/bin/hampackupdate cd ~/.local/share/HamPack +# Source utility functions +source utils.sh + +# Source package list if [ ! -f "packages.conf" ]; then echo "Error: packages.conf not found!" exit 1 @@ -120,8 +50,26 @@ source packages.conf echo "Updating system..." sudo pacman -Syu --noconfirm -cd ~ -install_yay +cd ~/ + +# Install yay AUR helper if not present +if ! command -v yay &> /dev/null; then + echo "Installing yay AUR helper..." + sudo pacman -S --needed git base-devel --noconfirm + if [[ -d "yay" ]]; then + echo "yay directory already exists, removing it..." + rm -rf yay + fi + echo "Cloning yay repository..." + git clone https://aur.archlinux.org/yay.git + cd yay + echo "Building yay..." + makepkg -si --noconfirm + cd .. + rm -rf yay +else + echo "yay is already installed." +fi echo "Installing system utilities..." install_packages "${UTILITIES[@]}" @@ -138,4 +86,20 @@ echo "Installing stand-alone compiled applications..." . install-compiled.sh -echo "HamPack installation complete. You may want to reboot your machine." \ No newline at end of file + +if ! ls /usr/lib/modules/$(uname -r) > /dev/null 2>&1; then + echo "HamPack is installed. A newer kernel has been installed, a reboot is recommended." + read -rp "Reboot now? [y/N] " response + case "$response" in + [yY][eE][sS]|[yY]) + echo "Rebooting..." + sudo reboot + ;; + *) + echo "Reboot skipped. Please remember to reboot when convenient." + exit 0 + ;; + esac +else + echo "Ham Pack is installed. Reboot when convenient." +fi \ No newline at end of file