Skip to content

Commit

Permalink
chore: Add install script
Browse files Browse the repository at this point in the history
  • Loading branch information
coolapso committed Oct 27, 2024
1 parent 999f50f commit 360bd3c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/deployInstallScript.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy Install script to pages

on:
push:
branches: ["main"]

workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'scripts/install.sh'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

63 changes: 63 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

## check for root privileges
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi

# Variables
REPO="coolapso/megophone" # Replace 'user/megophone' with the actual repository path
VERSION=${1:-"latest"}
INSTALL_DIR="/usr/local/bin"

# Determine OS and Architecture
OS=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
if [[ "$ARCH" == "x86_64" ]]; then
ARCH="amd64"
elif [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then
ARCH="arm64"
elif [[ "$ARCH" == "i386" || "$ARCH" == "i686" ]]; then
ARCH="386"
fi

# Fetch the latest release if no version is specified
if [[ "$VERSION" == "latest" ]]; then
VERSION=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi

# Download URL for the release file and checksum
FILE="megophone_${VERSION:1}_${OS}_${ARCH}.tar.gz"
FILE_URL="https://github.com/$REPO/releases/download/$VERSION/$FILE"

# Download the file and checksum
if ! curl -LO "$FILE_URL"; then
echo "Failed to download $FILE_URL"
exit 1
fi

# Extract and install
if ! tar xzf "$FILE"; then
echo "Failed to extract $FILE"
exit 1
fi

## Install the binary
if ! chmod +x megophone; then
echo "Failed to make megophone executable"
exit 1
fi

if ! mv megophone "$INSTALL_DIR" ; then
echo "Failed to move megophone to $INSTALL_DIR"
exit 1
fi

# Cleanup
if ! rm "$FILE"; then
echo "Failed to remove $FILE"
exit 1
fi

echo "Installation of $REPO version $VERSION complete."

0 comments on commit 360bd3c

Please sign in to comment.