Skip to content

Commit

Permalink
chore: installation script
Browse files Browse the repository at this point in the history
  • Loading branch information
ex3ndr committed Jan 25, 2024
1 parent 453dcf4 commit f2132d1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 4 deletions.
8 changes: 4 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mkdir -p ./out/
cd ./sources/

# Building
GOOS=linux GOARCH=amd64 go build -o ../out/linux-x64/ .
GOOS=darwin GOARCH=amd64 go build -o ../out/darwin-x64/ .
GOOS=darwin GOARCH=arm64 go build -o ../out/darwin-arm64/ .
GOOS=windows GOARCH=amd64 go build -o ../out/windows-x64/ .
GOOS=linux GOARCH=amd64 go build -o ../out/datasets-linux-x64 .
GOOS=darwin GOARCH=amd64 go build -o ../out/datasets-darwin-x64 .
GOOS=darwin GOARCH=arm64 go build -o ../out/datasets-darwin-arm64 .
GOOS=windows GOARCH=amd64 go build -o ../out/datasets-windows-x64.exe .
71 changes: 71 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/sh
set -eu

# Helper functions
status() { echo ">>> $*" >&2; }
error() { echo "ERROR $*"; exit 1; }
warning() { echo "WARNING: $*"; }

# Temporary directory
TEMP_DIR=$(mktemp -d)
cleanup() { rm -rf $TEMP_DIR; }
trap cleanup EXIT

# Check if a command is available
available() { command -v $1 >/dev/null; }
require() {
local MISSING=''
for TOOL in $*; do
if ! available $TOOL; then
MISSING="$MISSING $TOOL"
fi
done

echo $MISSING
}

# Check if the script is running on Linux
[ "$(uname -s)" = "Linux" ] || error 'This script is intended to run on Linux only.'

# Check architecture
ARCH=$(uname -m)
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac

# Resolving sudo command
SUDO=
if [ "$(id -u)" -ne 0 ]; then
# Running as root, no need for sudo
if ! available sudo; then
error "This script requires superuser permissions. Please re-run as root."
fi

SUDO="sudo"
fi

# Check if required tools are available
NEEDS=$(require curl)
if [ -n "$NEEDS" ]; then
status "ERROR: The following tools are required but missing:"
for NEED in $NEEDS; do
echo " - $NEED"
done
exit 1
fi

# Download tool
status "Downloading datasets..."
curl --fail --show-error --location --progress-bar -o $TEMP_DIR/datasets "https://github.com/ex3ndr/datasets/releases/latest/download/datasets-linux-$ARCH"

# Detecting installation directory
for BINDIR in /usr/local/bin /usr/bin /bin; do
echo $PATH | grep -q $BINDIR && break || continue
done

# Installing
status "Installing datasets to $BINDIR..."
$SUDO install -o0 -g0 -m755 -d $BINDIR
$SUDO install -o0 -g0 -m755 $TEMP_DIR/datasets $BINDIR/datasets

0 comments on commit f2132d1

Please sign in to comment.