Skip to content

Commit

Permalink
improve install script removing executing it and adding it to /usr/lo…
Browse files Browse the repository at this point in the history
…cal/bin
  • Loading branch information
hitchhooker committed Apr 9, 2024
1 parent 5441a83 commit 0c020a7
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
#!/bin/bash

set -euo pipefail

# Define locations and names
binary_name="genpeerid"
install_path="/usr/local/bin/${binary_name}"

# Check if genpeerid is already installed and exit if it is
if command -v ${binary_name} &> /dev/null; then
echo "${binary_name} is already installed."
exit 0
fi

# Install dependencies if missing, for Debian/Ubuntu systems
if ! command -v gpg &> /dev/null || ! command -v curl &> /dev/null; then
echo "Installing missing dependencies..."
sudo apt-get update
sudo apt-get install -y gpg curl
fi

# URLs for the assets
binary_url=$(curl -s https://api.github.com/repos/rotkonetworks/genpeerid/releases/latest | grep -oP '"browser_download_url": "\K(.*genpeerid)(?=")')
binary_signature_url=$(curl -s https://api.github.com/repos/rotkonetworks/genpeerid/releases/latest | grep -oP '"browser_download_url": "\K(.*genpeerid.sig)(?=")')
Expand All @@ -8,26 +27,31 @@ hash_signature_url=$(curl -s https://api.github.com/repos/rotkonetworks/genpeeri
public_key_url="https://github.com/hitchhooker.gpg"

# Download the binary, SHA512 hash, and the GPG signature of the hash
curl -sL "${binary_url}" -o genpeerid
curl -sL "${binary_signature_url}" -o genpeerid.sig
curl -sL "${hash_url}" -o genpeerid.sha512
curl -sL "${hash_signature_url}" -o genpeerid.sha512.sig
curl -sL "${binary_url}" -o ${binary_name}
curl -sL "${binary_signature_url}" -o ${binary_name}.sig
curl -sL "${hash_url}" -o ${binary_name}.sha512
curl -sL "${hash_signature_url}" -o ${binary_name}.sha512.sig
curl -sL "${public_key_url}" -o public_key.gpg

# Import the public key
gpg --import public_key.gpg

echo "Verifying SHA512 hash..."
sha512sum -c genpeerid.sha512 || { echo "SHA512 verification failed!"; exit 1; }
sha512sum -c ${binary_name}.sha512 || { echo "SHA512 verification failed!"; exit 1; }

# Verify the GPG signature of the SHA512 hash
echo "Verifying GPG signature of SHA512 hash..."
gpg --verify genpeerid.sha512.sig genpeerid.sha512 || { echo "GPG signature verification of SHA512 hash failed!"; exit 1; }
gpg --verify ${binary_name}.sha512.sig ${binary_name}.sha512 || { echo "GPG signature verification of SHA512 hash failed!"; exit 1; }

# New Step: Verify the GPG signature of the binary itself
echo "Verifying GPG signature of the binary..."
gpg --verify genpeerid.sig genpeerid || { echo "GPG signature verification of the binary failed!"; exit 1; }
gpg --verify ${binary_name}.sig ${binary_name} || { echo "GPG signature verification of the binary failed!"; exit 1; }

# Ensure the binary is executable
chmod +x ${binary_name}

# Move the binary to the installation path
sudo mv ${binary_name} ${install_path}

echo "${binary_name} installed successfully to ${install_path}."

# If all verifications passed, proceed to use the binary
chmod +x genpeerid
./genpeerid
# Clean up
rm -f ${binary_name}.sha512 ${binary_name}.sha512.sig public_key.gpg ${binary_name}.sig

0 comments on commit 0c020a7

Please sign in to comment.