improve install.sh
This commit is contained in:
180
install.sh
180
install.sh
@@ -1,142 +1,122 @@
|
|||||||
#!/bin/bash -i
|
#!/bin/bash -i
|
||||||
|
#
|
||||||
|
# Purpose : HamPack installer
|
||||||
|
|
||||||
# Print the logo
|
# Print the logo
|
||||||
print_logo() {
|
print_logo() {
|
||||||
cat << "EOF"
|
cat << "EOF"
|
||||||
|
|
||||||
██╗ ██╗ █████╗ ███╗ ███╗██████╗ █████╗ ██████╗██╗ ██╗
|
██╗ ██╗ █████╗ ███╗ ███╗██████╗ █████╗ ██████╗██╗ ██╗
|
||||||
██║ ██║██╔══██╗████╗ ████║██╔══██╗██╔══██╗██╔════╝██║ ██╔╝
|
██║ ██║██╔══██╗████╗ ████║██╔══██╗██╔══██╗██╔════╝██║ ██╔╝
|
||||||
███████║███████║██╔████╔██║██████╔╝███████║██║ █████╔╝
|
███████║███████║██╔████╔██║██████╔╝███████║██║ █████╔╝
|
||||||
██╔══██║██╔══██║██║╚██╔╝██║██╔═══╝ ██╔══██║██║ ██╔═██╗
|
██╔══██║██╔══██║██║╚██╔╝██║██╔═══╝ ██╔══██║██║ ██╔═██╗
|
||||||
██║ ██║██║ ██║██║ ╚═╝ ██║██║ ██║ ██║╚██████╗██║ ██╗
|
██║ ██║██║ ██║██║ ╚═╝ ██║██║ ██║ ██║╚██████╗██║ ██╗
|
||||||
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝
|
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝
|
||||||
|
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse command line arguments
|
# Install packages helper
|
||||||
DEV_ONLY=false
|
install_packages() {
|
||||||
while [[ "$#" -gt 0 ]]; do
|
local packages=("$@")
|
||||||
case $1 in
|
if [[ ${#packages[@]} -eq 0 ]]; then
|
||||||
--dev-only) DEV_ONLY=true; shift ;;
|
echo "Warning: no packages to install."
|
||||||
*) echo "Unknown parameter: $1"; exit 1 ;;
|
return
|
||||||
esac
|
fi
|
||||||
done
|
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
|
clear
|
||||||
print_logo
|
print_logo
|
||||||
|
|
||||||
cd
|
cd ~
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sudo -v
|
sudo -v
|
||||||
|
|
||||||
echo "Getting the latest version of HamPack..."
|
echo "Getting the latest version of HamPack..."
|
||||||
|
|
||||||
rm -rf ~/.local/share/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"
|
sync_file "$HOME/.local/share/HamPack/hampackupdate" "$HOME/.local/bin/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
|
|
||||||
|
|
||||||
sudo cp ~/.local/share/coredesktop/hampackrefresh ~/.local/bin/hampackrefresh
|
sudo cp ~/.local/share/coredesktop/hampackrefresh ~/.local/bin/hampackrefresh
|
||||||
|
|
||||||
# Exit on any error
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cd ~/.local/share/HamPack
|
cd ~/.local/share/HamPack
|
||||||
|
|
||||||
# Source the packages list
|
|
||||||
|
|
||||||
if [ ! -f "packages.conf" ]; then
|
if [ ! -f "packages.conf" ]; then
|
||||||
echo "Error: packages.conf not found!"
|
echo "Error: packages.conf not found!"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source packages.conf
|
source packages.conf
|
||||||
|
|
||||||
# Update the system first
|
|
||||||
|
|
||||||
echo "Updating system..."
|
echo "Updating system..."
|
||||||
sudo pacman -Syu --noconfirm
|
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 "Installing applications..."
|
||||||
echo "yay is already installed, skipping."
|
install_packages "${APPLICATIONS[@]}"
|
||||||
exit 0
|
|
||||||
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
|
|
||||||
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
|
cd ~/.local/share/HamPack
|
||||||
|
|
||||||
# Install Flatpack applications
|
echo "Installing Flatpak applications..."
|
||||||
|
. install-flatpaks.sh
|
||||||
|
|
||||||
echo "Installing Flatpack Applications..."
|
echo "HamPack installation complete."
|
||||||
|
|
||||||
. install-flatpacks.sh
|
|
||||||
|
|
||||||
echo "Done, for now."
|
|
||||||
Reference in New Issue
Block a user