2024-01-07 18:05:38 -07:00
#!/bin/bash
mkdir -p ~/.allpac/cache ~/.allpac/logs ~/.allpac/bin
2024-01-07 20:31:16 -07:00
echo "We are about to write a new pkg.list"
echo "Do you want us to proceed?"
2024-01-08 14:43:29 -07:00
echo "(reply 'n' if you already have a pkg.list)"
2024-01-07 20:31:16 -07:00
read -p "Proceed? [Y/n] " -n 1 -r
echo
2024-01-08 14:43:29 -07:00
if [ [ $REPLY = ~ ^[ Yy] $ ] ] ; then
echo "Writing new pkg.list..."
2024-01-08 14:54:28 -07:00
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..."
2024-01-08 14:54:28 -07:00
sleep 2
2024-01-08 14:43:29 -07:00
fi
2024-01-07 18:05:38 -07:00
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..."
2024-01-07 18:05:38 -07:00
if [ [ " $go_version " != *" $required_version " * ] ] ; then
echo "Required Go version is not installed."
2024-01-08 14:43:29 -07:00
read -p "Do you want to install Go? (this will also perform a general system update with pacman) [Y/n] " -n 1 -r
2024-01-07 18:05:38 -07:00
echo
if [ [ $REPLY = ~ ^[ Yy] $ ] ] ; then
2024-01-08 14:49:56 -07:00
echo " "
2024-01-08 13:35:08 -07:00
echo "Running 'sudo pacman -Syu go' instead of 'pacman -Sy'..."
2024-01-08 14:49:56 -07:00
echo " "
echo "So, because the Arch Developers won't make Pacman alert you of this, I guess AllPac has to..."
echo " "
2024-01-08 14:54:28 -07:00
sleep 2
echo "Running 'pacman -Sy' syncs the package database, but doesn't update all the packages on the system"
2024-01-08 14:43:29 -07:00
echo "This can cause a lot of problems if something gets updated but something that depends on it doesn't."
2024-01-08 14:49:56 -07:00
echo " "
2024-01-08 13:35:08 -07:00
echo "It's called a 'Partial Upgrade' and it can break your system"
echo "If you wanna install a package and you don't use AllPac, always just run 'pacman -Syu {package}'"
2024-01-08 14:49:56 -07:00
echo " "
2024-01-08 14:54:28 -07:00
sleep 2
echo "On the other hand;"
echo "Running 'pacman -S' will install a package, but not update the package database. So you might not get the newest version. Which can be it's own issue."
echo " "
sleep 2
2024-01-08 13:35:08 -07:00
echo "That's all it took to explain the issue properly Scimmia..."
echo "Arch Linux Forums users/devs are toxic."
2024-01-08 14:54:28 -07:00
sleep 4
2024-01-08 13:35:08 -07:00
sudo pacman -Syu go
2024-01-07 18:05:38 -07:00
else
echo "Go not installed. Exiting."
exit 1
fi
fi
2024-01-08 14:54:28 -07:00
sleep 2
2024-01-07 20:16:54 -07:00
echo "Compatible Go version is installed!"
echo "Checking if Git is installed..."
2024-01-07 18:05:38 -07:00
if ! command -v git & >/dev/null; then
echo "Git is not installed."
read -p "Do you want to install Git? [Y/n] " -n 1 -r
echo
if [ [ $REPLY = ~ ^[ Yy] $ ] ] ; then
2024-01-08 13:35:08 -07:00
sudo pacman -Syu git
2024-01-07 18:05:38 -07:00
else
echo "Git not installed. Exiting."
exit 1
fi
fi
2024-01-08 14:54:28 -07:00
sleep 2
2024-01-07 20:16:54 -07:00
echo "Git is installed!"
echo "Cloning AllPac Repository from Git..."
2024-01-08 14:54:28 -07:00
sleep 2
2024-01-07 20:16:54 -07:00
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 18:05:38 -07:00
2024-01-07 20:16:54 -07:00
echo "Descending into cloned repo..."
2024-01-08 14:54:28 -07:00
sleep 2
2024-01-08 14:43:29 -07:00
cd AllPac/cmd/ || { echo "Failed to change directory. Exiting." ; exit 1; }
2024-01-07 18:05:38 -07:00
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-08 14:54:28 -07:00
sleep 2
2024-01-07 18:05:38 -07:00
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-08 14:54:28 -07:00
sleep 2
2024-01-07 20:16:54 -07:00
echo "Binary built!"
2024-01-07 18:05:38 -07:00
shell_rc = ""
case $SHELL in
*/bash)
shell_rc = " $HOME /.bashrc "
; ;
*/zsh)
shell_rc = " $HOME /.zshrc "
; ;
*)
echo "Unsupported shell. Please manually add ~/.allpac/bin to your PATH."
exit 1
; ;
esac
2024-01-07 20:16:54 -07:00
echo "Adding AllPac to the system path..."
2024-01-08 14:54:28 -07:00
sleep 2
2024-01-08 13:35:08 -07:00
if ! grep -qF 'export PATH=$PATH:$HOME/.allpac/bin' " $shell_rc " ; then
echo 'export PATH=$PATH:$HOME/.allpac/bin' >> " $shell_rc "
fi
2024-01-07 18:05:38 -07:00
2024-01-07 18:10:01 -07:00
updater_url = "https://git.pixelridgesoftworks.com/PixelRidge-Softworks/Installers/raw/branch/main/allpac/update.sh"
2024-01-07 20:16:54 -07:00
echo "Downloading updater script..."
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; }
2024-01-08 14:54:28 -07:00
sleep 2
2024-01-07 18:10:01 -07:00
2024-01-07 20:16:54 -07:00
echo "Setting updater script permissions..."
2024-01-07 18:10:01 -07:00
chmod u+rwx ~/.allpac/bin/allpac-updater.sh
2024-01-08 14:54:28 -07:00
sleep 2
2024-01-07 18:10:01 -07:00
2024-01-07 20:16:54 -07:00
echo "Aliasing the updater script..."
2024-01-07 18:10:01 -07:00
echo "alias allpac-update-system='~/.allpac/bin/allpac-updater.sh'" >> " $shell_rc "
2024-01-07 20:16:54 -07:00
echo "Cleaning up..."
2024-01-08 14:43:29 -07:00
cd ../../ || exit
2024-01-07 18:05:38 -07:00
rm -rf AllPac
2024-01-08 14:43:29 -07:00
echo "AllPac setup complete. Please restart your shell or source your shell configuration file to apply changes."