Files
HamPack/install.sh
2026-03-19 10:41:27 -06:00

141 lines
3.6 KiB
Bash
Executable File

#!/bin/bash -i
#
# Purpose : HamPack installer
# Print the logo
print_logo() {
cat << "EOF"
██╗ ██╗ █████╗ ███╗ ███╗██████╗ █████╗ ██████╗██╗ ██╗
██║ ██║██╔══██╗████╗ ████║██╔══██╗██╔══██╗██╔════╝██║ ██╔╝
███████║███████║██╔████╔██║██████╔╝███████║██║ █████╔╝
██╔══██║██╔══██║██║╚██╔╝██║██╔═══╝ ██╔══██║██║ ██╔═██╗
██║ ██║██║ ██║██║ ╚═╝ ██║██║ ██║ ██║╚██████╗██║ ██╗
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝
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
clear
print_logo
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
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
cd ~/.local/share/HamPack
if [ ! -f "packages.conf" ]; then
echo "Error: packages.conf not found!"
exit 1
fi
source packages.conf
echo "Updating system..."
sudo pacman -Syu --noconfirm
cd ~
install_yay
echo "Installing system utilities..."
install_packages "${UTILITIES[@]}"
echo "Installing applications..."
install_packages "${APPLICATIONS[@]}"
cd ~/.local/share/HamPack
echo "Installing Flatpak applications..."
. install-flatpaks.sh
echo "Installing stand-alone compiled applications..."
. install-compiled.sh
echo "HamPack installation complete. You may want to reboot your machine."