Installers/allpac/install.sh

151 lines
4.8 KiB
Bash
Raw Normal View History

#!/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
2024-01-08 14:43:29 -07:00
echo "Writing new pkg.list..."
sleep 2
2024-01-08 14:43:29 -07:00
touch ~/.allpac/pkg.list
echo "{}" > ~/.allpac/pkg.list
else
echo "Skipping writing new pkg.list..."
sleep 2
2024-01-08 14:43:29 -07:00
fi
go_version=$(go version 2>/dev/null)
required_version="go1.21.5"
2024-01-07 20:16:54 -07:00
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..."
2024-01-08 18:06:16 -07:00
sudo pacman -Syu --noconfirm go
else
echo "Go not installed. Exiting."
exit 1
fi
fi
sleep 2
2024-01-07 20:16:54 -07:00
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
2024-01-08 18:06:16 -07:00
sudo pacman -Syu --noconfirm wget
else
echo "wget not installed. Exiting."
exit 1
fi
fi
sleep 2
2024-01-07 20:16:54 -07:00
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
2024-01-08 18:06:16 -07:00
sudo pacman -Syu --noconfirm git
else
echo "Git not installed. Exiting."
exit 1
fi
fi
sleep 2
2024-01-07 20:16:54 -07:00
echo "Cloning AllPac Repository from Git..."
2024-01-08 14:43:29 -07:00
git clone https://git.pixelridgesoftworks.com/PixelRidge-Softworks/AllPac.git || { echo "Failed to clone repository. Exiting."; exit 1; }
2024-01-07 20:16:54 -07:00
echo "Descending into cloned repo..."
2024-01-08 14:43:29 -07:00
cd AllPac/cmd/ || { echo "Failed to change directory. Exiting."; exit 1; }
2024-01-07 20:16:54 -07:00
echo "Ensuring we have up to date dependencies..."
2024-01-08 14:43:29 -07:00
go mod tidy || { echo "Failed to tidy dependencies. Exiting."; exit 1; }
2024-01-07 20:16:54 -07:00
echo "Building binary..."
2024-01-08 14:43:29 -07:00
go build -o ~/.allpac/bin/allpac || { echo "Failed to build binary. Exiting."; exit 1; }
2024-01-07 20:16:54 -07:00
echo "Downloading updater script..."
2024-01-08 18:02:12 -07:00
updater_url="https://git.pixelridgesoftworks.com/PixelRidge-Softworks/Installers/raw/branch/main/allpac/update.sh"
2024-01-08 14:43:29 -07:00
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; }
2024-01-07 20:16:54 -07:00
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
2024-01-07 20:16:54 -07:00
echo "Cleaning up..."
2024-01-08 14:43:29 -07:00
cd ../../ || exit
rm -rf AllPac
echo "AllPac setup complete. Please re-login (or restart the shell) to apply the changes."