-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.sh
58 lines (49 loc) · 1.45 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
#!/usr/bin/env sh
set -e
# Determine OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case $ARCH in
x86_64)
ARCH="amd64"
;;
aarch64|arm64)
ARCH="arm64"
;;
i386|i686)
ARCH="386"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
# Check for version argument
# Otherwise, set latest release version
if [ -z "$VERSION" ]; then
VERSION=$(curl -s "https://api.github.com/repos/fOSS-Community/wand/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([0-9.]+)".*/\1/')
fi
# Construct download URL
DOWNLOAD_URL="https://github.com/fOSS-Community/wand/releases/download/v${VERSION}/wand_${VERSION}_${OS}_${ARCH}.tar.gz"
# Create temporary directory
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
# Download and extract
echo "Downloading wand ${VERSION} for ${OS} ${ARCH}..."
curl -L -s "$DOWNLOAD_URL" | tar -xz -C "$TMP_DIR"
# Check if directory is writable by the current user
# If not, use sudo to install
INSTALL_DIR=${INSTALL_DIR:-/usr/local/bin}
if [ ! -w "$INSTALL_DIR" ]; then
echo "Installing wand to $INSTALL_DIR..."
sudo mkdir -p "$INSTALL_DIR"
sudo mv "$TMP_DIR/wand" "$INSTALL_DIR/"
else
echo "Installing wand to $INSTALL_DIR..."
mkdir -p "$INSTALL_DIR"
mv "$TMP_DIR/wand" "$INSTALL_DIR/"
fi
echo "wand ${VERSION} has been installed successfully!"
echo "Be sure that $INSTALL_DIR is in your PATH:"
printf "\n\texport PATH=\$PATH:%s\n\n" "$INSTALL_DIR"
echo "You can now use the 'wand' command."