-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·76 lines (64 loc) · 1.77 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/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 or MacOS
SYS=$(uname -s)
case "$SYS" in
Linux) SYS="linux" ;;
Darwin) SYS="darwin" ;;
*) error "Unsupported OS: $SYS" ;;
esac
# 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-$SYS-$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