refactor install
This commit is contained in:
122
install.sh
122
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."
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user