improve install.sh

This commit is contained in:
David Young
2026-03-15 09:18:33 -06:00
parent a04dd1232f
commit 01d6662828

View File

@@ -1,101 +1,39 @@
#!/bin/bash -i
#
# Purpose : HamPack installer
# Print the logo
print_logo() {
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
# Clear screen and show logo
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
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
# 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[@]}"
}
echo "Destination is up to date, proceeding..."
break
done
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!"
fi
source packages.conf
# Update the system first
echo "Updating system..."
sudo pacman -Syu --noconfirm
cd ~/
# Install yay AUR helper if not present
# Install yay AUR helper
install_yay() {
if command -v yay &> /dev/null; then
echo "yay is already installed, skipping."
exit 0
return
fi
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
@@ -113,30 +51,72 @@ echo "Cleaning up..."
rm -rf yay
echo "yay installed successfully."
}
# Install packages by category
# 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"
sudo cp ~/.local/share/coredesktop/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
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..."
echo "Installing applications..."
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."