-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·67 lines (58 loc) · 2.25 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
#!/bin/sh
set -e # Fail and exit on error of any command
REPO_OWNER='thetillhoff'
REPO_NAME='webscan'
CLI_NAME='webscan'
OS="$(uname -s | tr '[:upper:]' '[:lower:]')" # f.e. 'darwin'
# Verify OS
case "${OS}" in
darwin|linux|windows) ;;
*) cat <<EOF
Unsupported OS type ${OS} detected. Supported are darwin, linux, windows.
Feel free to open an issue or PR for your OS at https://github.com/thetillhoff/webscan."
EOF
exit 0 ;;
esac
ARCH="$(uname -m)" # f.e. 'arm64'
if [ "${ARCH}" == "x86_64" ]; then # Overwrite ARCH, required for WSL
ARCH=amd64
fi
# Verify ARCH
case "${ARCH}" in
amd64|arm64) ;;
*) cat <<EOF
Unsupported ARCH type ${ARCH} detected. Supported are amd64, arm64.
Feel free to open an issue or PR for your ARCH at https://github.com/thetillhoff/webscan.
EOF
exit 0 ;;
esac
# Check if jq is available
if [ ! 'command -v jq' ]; then
printf "jq is required to run this script"
exit 1
fi
# Check if sha256sum is available
if [ ! 'command -v sha256sum' ]; then
printf "sha256sum is required to run this script"
exit 1
fi
# Check if curl or wget are available
if [ 'command -v curl' ]; then
DOWNLOAD_FILE_CMD="curl -Lo"
DOWNLOAD_BODY_CMD="curl -sL"
elif [ 'command -v wget' ]; then
DOWNLOAD_FILE_CMD="wget -O"
DOWNLOAD_BODY_CMD="wget -qO-"
else
printf "Either curl or wget are required to run this script"
exit 2
fi
LATEST_VERSION="$($DOWNLOAD_BODY_CMD https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest | jq -r '.tag_name')"
echo https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST_VERSION}/${CLI_NAME}_${OS}_${ARCH}
echo https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST_VERSION}/${CLI_NAME}_${OS}_${ARCH}.sha256
$DOWNLOAD_FILE_CMD ${CLI_NAME} "https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST_VERSION}/${CLI_NAME}_${OS}_${ARCH}"
$DOWNLOAD_FILE_CMD ${CLI_NAME}.sha256 "https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST_VERSION}/${CLI_NAME}_${OS}_${ARCH}.sha256"
printf "$(cat ${CLI_NAME}.sha256) ${CLI_NAME}" | sha256sum --check --status
printf "Checksum validation complete, installing to /usr/local/bin/ ...\n"
sudo install ${CLI_NAME} /usr/local/bin/${CLI_NAME} # automatically sets rwxr-xr-x permissions
rm ${CLI_NAME} ${CLI_NAME}.sha256