From af0835fc302d2d12dbf28f1e0e89357082844016 Mon Sep 17 00:00:00 2001 From: Erik Reinert <4638629+erikreinert@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:43:06 -0800 Subject: [PATCH] feat: added support for macOS with install.sh (#142) --- .github/workflows/vorpal.yaml | 4 +- script/install.sh | 86 ++++++++++++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/.github/workflows/vorpal.yaml b/.github/workflows/vorpal.yaml index 4f8e921e..c6cf06ea 100644 --- a/.github/workflows/vorpal.yaml +++ b/.github/workflows/vorpal.yaml @@ -76,7 +76,9 @@ jobs: sudo mv bwrap /etc/apparmor.d/bwrap sudo systemctl restart apparmor.service - - run: ./script/install.sh + - run: | + sudo mkdir -pv /var/lib/vorpal/{cache,key,sandbox,store} + sudo chown -R "$(id -u):$(id -g)" /var/lib/vorpal - run: | echo "ARCH=$(uname -m | tr '[:upper:]' '[:lower:]' | sed 's/arm64/aarch64/')" >> $GITHUB_ENV diff --git a/script/install.sh b/script/install.sh index 182f50e2..32f663e7 100755 --- a/script/install.sh +++ b/script/install.sh @@ -1,6 +1,90 @@ #!/bin/bash set -euo pipefail +# Environment variables +INSTALL_ARCH=$(uname -m | tr '[:upper:]' '[:lower:]' | sed 's/arm64/aarch64/') +INSTALL_DIR="$HOME/.vorpal" +INSTALL_OS=$(uname -s | tr '[:upper:]' '[:lower:]') +INSTALL_VERSION="nightly" +INSTALL_BINARY_URL="https://github.com/ALT-F4-LLC/vorpal/releases/download/$INSTALL_VERSION/vorpal-$INSTALL_ARCH-$INSTALL_OS.tar.gz" + +read -p "|> Install script requires sudo permissions. Would you like to continue? (y/n) " -n 1 -r + +if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo -e "\nAborting." + exit 1 +fi + +if [ -d "$INSTALL_DIR" ]; then + echo -e "" + read -p "|> Install path $INSTALL_DIR exists. Would you like to replace? (y/n) " -n 1 -r + + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo -e "\nAborting." + exit 1 + fi + + rm -rf "$INSTALL_DIR" +fi + +echo -e "\n|> Installing in $INSTALL_DIR directory..." + +# Setup installation directories +mkdir -p "$INSTALL_DIR/bin" + +# Download and extract the Vorpal binary +curl -s -L "$INSTALL_BINARY_URL" | tar xz -C "$INSTALL_DIR/bin" + # Setup directories -sudo mkdir -p /var/lib/vorpal/{cache,key,sandbox,store} +sudo mkdir -pv /var/lib/vorpal/{cache,key,sandbox,store} sudo chown -R "$(id -u):$(id -g)" /var/lib/vorpal + +# Generate a new keypair +echo -e "|> Generating a new keypair..." +"$INSTALL_DIR/bin/vorpal" keys generate + +# Setup LaunchAgent for macOS +if [[ $INSTALL_OS == "darwin" ]]; then +echo -e "|> Setting up LaunchAgent for macOS..." + +cat < "com.altf4llc.vorpal.plist" + + + + + + Label + com.altf4llc.vorpal + + + ProgramArguments + + ${INSTALL_DIR}/bin/vorpal + start + + + + RunAtLoad + + + + KeepAlive + + + +EOF + +# Move the plist file to the LaunchAgents directory +mv com.altf4llc.vorpal.plist ~/Library/LaunchAgents/ +chmod 644 ~/Library/LaunchAgents/com.altf4llc.vorpal.plist + +echo -e "|> Starting Vorpal service..." + +launchctl unload "$HOME/Library/LaunchAgents/com.altf4llc.vorpal.plist" +launchctl load "$HOME/Library/LaunchAgents/com.altf4llc.vorpal.plist" + +echo -e "|> Vorpal service(s) started" +fi + +## TODO: implement Linux service setup