Skip to content

Commit

Permalink
new macOS installation instructions (#15)
Browse files Browse the repository at this point in the history
* new release instructions

* add uninstallation script to the installation dir.

* fix CI

* upgrade CI actions

* upgrade to chechout action v4

* update setup action to v5

* CI: fix packaging

* CI: remove nested folder

* update mac scripts.

* tiny fix.
  • Loading branch information
tarassh authored Sep 1, 2024
1 parent b8236fe commit 78cb4a3
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 83 deletions.
44 changes: 28 additions & 16 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ on:

jobs:
build:

runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.22'

Expand Down Expand Up @@ -50,14 +49,26 @@ jobs:
- name: Build binaries
run: make build

- name: Collect artifacts
- name: Collect light client artifacts (macOS)
if: matrix.os == 'macos-latest'
run: cp scripts/lc-install-macos.sh bin/install.sh && cp scripts/lc-uninstall-macos.sh bin/uninstall.sh && cp test/data/trusted_setup.txt bin/
run: |
mkdir -p das-${{ matrix.os }}
cp bin/light-client das-${{ matrix.os }}/
cp scripts/macos/* das-${{ matrix.os }}/
cp test/data/trusted_setup.txt das-${{ matrix.os }}/
cp test/data/gcp-credentials.json das-${{ matrix.os }}/
- name: Collect light client artifacts (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
mkdir -p das-${{ matrix.os }}
cp bin/light-client das-${{ matrix.os }}/
- name: Create tarball
run: tar -czvf das-${{ matrix.os }}.tar.gz bin

run: tar -czvf das-${{ matrix.os }}.tar.gz -C das-${{ matrix.os }} .
- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: das-${{ matrix.os }}
path: das-${{ matrix.os }}.tar.gz
Expand All @@ -73,15 +84,16 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Download binaries
uses: actions/download-artifact@v3
- name: Download Ubuntu artifacts
uses: actions/download-artifact@v4
with:
name: das-ubuntu-latest
pattern: das-ubuntu-latest.tar.gz
path: .
- name: Download binaries
uses: actions/download-artifact@v3

- name: Download macOS artifacts
uses: actions/download-artifact@v4
with:
name: das-macos-latest
pattern: das-macos-latest.tar.gz
path: .

- name: Upload release asset
Expand Down
18 changes: 0 additions & 18 deletions scripts/lc-uninstall-macos.sh

This file was deleted.

92 changes: 43 additions & 49 deletions scripts/lc-install-macos.sh → scripts/macos/install.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
#!/bin/bash

if [ -z "$1" ]; then
echo "Client ID is required."
echo "Usage: $0 <client_id>"
exit 1
fi

# Paths
COVALENT_DIR="$HOME/.covalent"
IPFS_PATH=$(which ipfs)
IPFS_PATH=$(which ipfs) # Get the actual path of the IPFS binary
EXECUTABLE="light-client"
TRUSTED_SETUP="trusted_setup.txt"
GCP_CREDENTIALS="gcp-credentials.json"
WRAPPER_SCRIPT="run_light_client.sh"
PLIST_FILE="com.covalent.light-client.plist"
IPFS_PLIST_FILE="com.covalent.ipfs.plist"
WRAPPER_SCRIPT="$COVALENT_DIR/run.sh"
PLIST_FILE="$HOME/Library/LaunchAgents/com.covalent.light-client.plist"
IPFS_PLIST_FILE="$HOME/Library/LaunchAgents/com.covalent.ipfs.plist"
IPFS_REPO_DIR="$HOME/.ipfs"

# Uninstallation step (run the uninstallation script)
bash uninstall.sh

# Check if the destination directory exists
mkdir -p "$COVALENT_DIR"

# Copy the executable and trusted setup to the destination directory
# Copy the executable, trusted setup, and wrapper script to the destination directory
cp "$EXECUTABLE" "$COVALENT_DIR/"
cp "$TRUSTED_SETUP" "$COVALENT_DIR/"
cp "$GCP_CREDENTIALS" "$COVALENT_DIR/"
cp "uninstall.sh" "$COVALENT_DIR/"
cp "run.sh" "$WRAPPER_SCRIPT"

# Make the executable runnable
# Make the executable and wrapper script runnable
chmod +x "$COVALENT_DIR/$EXECUTABLE"
chmod +x "$WRAPPER_SCRIPT"

# Bypass Gatekeeper for the executable
spctl --add --label "Trusted" "$COVALENT_DIR/$EXECUTABLE"
spctl --enable --label "Trusted"

# Create the IPFS launchd plist file without a wrapper script
cat <<EOF > "$HOME/Library/LaunchAgents/$IPFS_PLIST_FILE"
# Create the IPFS launchd plist file with the correct IPFS path
cat <<EOF > "$IPFS_PLIST_FILE"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
Expand Down Expand Up @@ -59,45 +71,18 @@ cat <<EOF > "$HOME/Library/LaunchAgents/$IPFS_PLIST_FILE"
</plist>
EOF

# Load the IPFS daemon
launchctl load "$HOME/Library/LaunchAgents/$IPFS_PLIST_FILE"
# Validate the IPFS plist file
plutil -lint "$IPFS_PLIST_FILE"

# Create the light client wrapper script
cat <<EOF > "$COVALENT_DIR/$WRAPPER_SCRIPT"
#!/bin/bash
# Define the directory again in the wrapper script, it will use the value assigned during installation
COVALENT_DIR="$COVALENT_DIR"
# Ensure that only one instance of the service is running
SERVICE_NAME="$EXECUTABLE"
if pgrep -f "\$SERVICE_NAME" > /dev/null 2>&1; then
echo "\$SERVICE_NAME is already running."
# Load the IPFS daemon
launchctl unload "$IPFS_PLIST_FILE" # Unload first to ensure no conflicts
launchctl load "$IPFS_PLIST_FILE" || {
echo "Failed to load IPFS plist. Check the plist and system logs for more details."
exit 1
fi
# Wait for IPFS daemon to be fully available
until pgrep -f "ipfs daemon" > /dev/null 2>&1; do
echo "Waiting for IPFS daemon to start..."
sleep 5
done
# Run your service binary with all the arguments
"\$COVALENT_DIR/\$SERVICE_NAME" \\
--loglevel debug \\
--rpc-url wss://moonbase-alpha.blastapi.io/618fd77b-a090-457b-b08a-373398006a5e \\
--contract 0x916B54696A70588a716F899bE1e8f2A5fFd5f135 \\
--topic-id DAS-TO-BQ \\
--gcp-creds-file "\$COVALENT_DIR/$GCP_CREDENTIALS" \\
--client-id {YOUR_UNIQUE_ID}
EOF

# Make the wrapper script executable
chmod +x "$COVALENT_DIR/$WRAPPER_SCRIPT"
}

# Create the launchd plist file for the light client
cat <<EOF > "$HOME/Library/LaunchAgents/$PLIST_FILE"
# Create the light client launchd plist file with the correct executable path
cat <<EOF > "$PLIST_FILE"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
Expand All @@ -106,12 +91,14 @@ cat <<EOF > "$HOME/Library/LaunchAgents/$PLIST_FILE"
<string>com.covalent.light-client</string>
<key>ProgramArguments</key>
<array>
<string>$COVALENT_DIR/$WRAPPER_SCRIPT</string>
<string>$HOME/.covalent/run.sh</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>PINNER_DIR</key>
<string>$COVALENT_DIR</string>
<string>$HOME/.covalent</string>
<key>CLIENT_ID</key>
<string>$1</string>
</dict>
<key>RunAtLoad</key>
<true/>
Expand All @@ -120,14 +107,21 @@ cat <<EOF > "$HOME/Library/LaunchAgents/$PLIST_FILE"
<key>ThrottleInterval</key>
<integer>30</integer> <!-- Prevents rapid restarts -->
<key>StandardOutPath</key>
<string>$COVALENT_DIR/light-client.log</string>
<string>$HOME/.covalent/light-client.log</string>
<key>StandardErrorPath</key>
<string>$COVALENT_DIR/light-client.log</string>
<string>$HOME/.covalent/light-client.log</string>
</dict>
</plist>
EOF

# Validate the light client plist file
plutil -lint "$PLIST_FILE"

# Load the light client daemon
launchctl load "$HOME/Library/LaunchAgents/$PLIST_FILE"
launchctl unload "$PLIST_FILE" # Unload first to ensure no conflicts
launchctl load "$PLIST_FILE" || {
echo "Failed to load Light Client plist. Check the plist and system logs for more details."
exit 1
}

echo "Installation completed. The IPFS daemon and the light client daemon are now running."
29 changes: 29 additions & 0 deletions scripts/macos/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Define the directory again in the wrapper script, it will use the value assigned during installation
COVALENT_DIR="${COVALENT_DIR:-$HOME/.covalent}" # Default to ~/.covalent if not set
SERVICE_NAME="${EXECUTABLE:-light-client}" # Default to light-client if not set
GCP_CREDENTIALS="${GCP_CREDENTIALS:-gcp-credentials.json}" # Default to gcp-credentials.json if not set

# Ensure that only one instance of the service is running
if pgrep -f "$SERVICE_NAME" > /dev/null 2>&1; then
echo "$SERVICE_NAME is already running."
exit 1
fi

# Wait for IPFS daemon to start by checking if it is listening on port 5001
echo "Waiting for IPFS daemon to start on port 5001..."
until lsof -i :5001 | grep LISTEN > /dev/null; do
printf '.'
sleep 1
done
echo "IPFS daemon has started."

# Run your service binary with all the arguments
"$COVALENT_DIR/$SERVICE_NAME" \
--loglevel debug \
--rpc-url wss://moonbase-alpha.blastapi.io/618fd77b-a090-457b-b08a-373398006a5e \
--contract 0x916B54696A70588a716F899bE1e8f2A5fFd5f135 \
--topic-id DAS-TO-BQ \
--gcp-creds-file "$COVALENT_DIR/$GCP_CREDENTIALS" \
--client-id "$CLIENT_ID"
40 changes: 40 additions & 0 deletions scripts/macos/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Paths for the old setup
OLD_COVALENT_DIR="$HOME/.covalenthq"
OLD_PLIST_FILE="com.covalenthq.light-client.plist"
OLD_IPFS_PLIST_FILE="com.covalenthq.ipfs.plist"

# Paths for the new setup
COVALENT_DIR="$HOME/.covalent"
PLIST_FILE="com.covalent.light-client.plist"
IPFS_PLIST_FILE="com.covalent.ipfs.plist"

# Function to unload and remove plist files
remove_plist() {
local plist_file="$1"
if [ -f "$HOME/Library/LaunchAgents/$plist_file" ]; then
launchctl unload "$HOME/Library/LaunchAgents/$plist_file" || echo "Failed to unload $plist_file"
rm "$HOME/Library/LaunchAgents/$plist_file" || echo "Failed to remove $plist_file"
fi
}

# Function to remove directories
remove_directory() {
local dir="$1"
if [ -d "$dir" ]; then
rm -rf "$dir" || echo "Failed to remove directory $dir"
fi
}

# Unload and remove plist files for both old and new setups
remove_plist "$PLIST_FILE"
remove_plist "$IPFS_PLIST_FILE"
remove_plist "$OLD_PLIST_FILE"
remove_plist "$OLD_IPFS_PLIST_FILE"

# Remove the .covalent and .covalenthq directories and their contents
remove_directory "$COVALENT_DIR"
remove_directory "$OLD_COVALENT_DIR"

echo "Uninstallation completed. The light client and IPFS daemons for both old and new versions have been removed."

0 comments on commit 78cb4a3

Please sign in to comment.