#!/bin/bash # Default values for non-interactive mode INSTALL_GO="Y" INSTALL_WGET="Y" INSTALL_GIT="Y" WRITE_PKGLIST="Y" # Check if the script is running interactively if [[ $- == *i* ]]; then # The script is running interactively, so prompt the user for input echo "We are about to write a new pkg.list" echo "Do you want us to proceed?" echo "(reply 'n' if you already have a pkg.list)" read -p "Proceed? [Y/n] " -n 1 -r -e -i "Y" WRITE_PKGLIST echo fi # Check if the ~/.allpac directory already exists if [ -d "$HOME/.allpac" ]; then echo "The AllPac directory ~/.allpac already exists." echo "Please remove or rename this directory before attempting to install AllPac again." exit 1 fi mkdir -p "$HOME/.allpac/cache" "$HOME/.allpac/logs" "$HOME/.allpac/bin" if [[ $WRITE_PKGLIST =~ ^[Yy]$ ]] || [[ -z $WRITE_PKGLIST ]]; then echo "Writing new pkg.list..." sleep 2 touch ~/.allpac/pkg.list echo "{}" > ~/.allpac/pkg.list else echo "Skipping writing new pkg.list..." sleep 2 fi go_version=$(go version 2>/dev/null) required_version="go1.21.5" echo "Checking if Go is installed..." if [[ "$go_version" != *"$required_version"* ]]; then echo "Required Go version is not installed." if [[ $- == *i* ]]; then read -p "Do you want to install Go? [Y/n] " -n 1 -r -e -i "Y" INSTALL_GO echo fi if [[ $INSTALL_GO =~ ^[Yy]$ ]] || [[ -z $INSTALL_GO ]]; then echo "Installing Go..." sudo pacman -Syu --noconfirm go else echo "Go not installed. Exiting." exit 1 fi fi sleep 2 echo "Checking if wget is installed..." if ! command -v wget &>/dev/null; then echo "wget is not installed." if [[ $- == *i* ]]; then read -p "Do you want to install wget? [Y/n] " -n 1 -r -e -i "Y" INSTALL_WGET echo fi if [[ $INSTALL_WGET =~ ^[Yy]$ ]] || [[ -z $INSTALL_WGET ]]; then sudo pacman -Syu --noconfirm wget else echo "wget not installed. Exiting." exit 1 fi fi sleep 2 echo "Checking if Git is installed..." if ! command -v git &>/dev/null; then echo "Git is not installed." if [[ $- == *i* ]]; then read -p "Do you want to install Git? [Y/n] " -n 1 -r -e -i "Y" INSTALL_GIT echo fi if [[ $INSTALL_GIT =~ ^[Yy]$ ]] || [[ -z $INSTALL_GIT ]]; then sudo pacman -Syu --noconfirm git else echo "Git not installed. Exiting." exit 1 fi fi sleep 2 echo "Cloning AllPac Repository from Git..." git clone https://git.pixelridgesoftworks.com/PixelRidge-Softworks/AllPac.git || { echo "Failed to clone repository. Exiting."; exit 1; } echo "Descending into cloned repo..." cd AllPac/cmd/ || { echo "Failed to change directory. Exiting."; exit 1; } echo "Ensuring we have up to date dependencies..." go mod tidy || { echo "Failed to tidy dependencies. Exiting."; exit 1; } echo "Building binary..." go build -o ~/.allpac/bin/allpac || { echo "Failed to build binary. Exiting."; exit 1; } echo "Downloading updater script..." updater_url="https://git.pixelridgesoftworks.com/PixelRidge-Softworks/Installers/raw/branch/main/allpac/update.sh" wget -O ~/.allpac/bin/allpac-updater.sh "$updater_url" || { echo "Failed to download updater script. Exiting."; exit 1; } sleep 2 echo "Downloading uninstaller script..." uninstaller_url="https://git.pixelridgesoftworks.com/PixelRidge-Softworks/Installers/raw/branch/main/allpac/uninstall.sh" wget -O ~/.allpac/bin/allpac-uninstaller.sh "$uninstaller_url" || { echo "Failed to download uninstaller script. Exiting."; exit 1; } echo "Setting updater script permissions..." chmod u+rwx ~/.allpac/bin/allpac-updater.sh echo "Detecting your shell and updating the configuration..." if [[ "$SHELL" == *"bash"* ]]; then shell_rc="$HOME/.bashrc" elif [[ "$SHELL" == *"zsh"* ]]; then shell_rc="$HOME/.zshrc" else echo "Unsupported shell. Please manually add the following alias to your shell configuration:" echo "alias allpac-update-system='$HOME/.allpac/bin/allpac-updater.sh'" exit 1 fi if ! grep -q "alias allpac-update-system=" "$shell_rc"; then echo "alias allpac-update-system='$HOME/.allpac/bin/allpac-updater.sh'" >> "$shell_rc" echo "Update Alias added to $shell_rc" else echo "Update Alias already exists in $shell_rc" fi if ! grep -q "alias uninstall-allpac=" "$shell_rc"; then echo "alias uninstall-allpac=$HOME/.allpac/bin/allpac-uninstaller.sh''" >> "$shell_rc" echo "Uninstall Alias added to $shell_rc" else echo "Uninstall Alias already exists in $shell_rc" fi echo "Adding AllPac to the system path for all users..." echo 'export PATH=$PATH:$HOME/.allpac/bin' | sudo tee -a /etc/profile.d/allpac.sh > /dev/null sudo chmod +x /etc/profile.d/allpac.sh echo "Cleaning up..." cd ../../ || exit rm -rf AllPac echo "AllPac setup complete. Please re-login (or restart the shell) to apply the changes."