-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·55 lines (50 loc) · 1.37 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
#!/bin/bash
BINARY=webhash
BIN_PATH=$HOME/bin
UNAME=$(uname)
ARCH=$(uname -m)
if [ "$UNAME" = "Darwin" ]; then
if [ "$ARCH" = "x86_64" ]; then
PLATFORM="darwin_amd64"
fi
elif [ "$UNAME" = "Linux" ]; then
if [ "$ARCH" = "i686" ]; then
PLATFORM="linux_386"
elif [ "$ARCH" = "x86_64" ]; then
PLATFORM="linux_amd64"
fi
fi
DEST=$BIN_PATH/$BINARY
# latest
get_latest_release() {
curl --silent "https://api.github.com/repos/xuender/$BINARY/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
# 安装
install() {
echo "Installing $BINARY..."
if [ "$UNAME" != "Linux" ] && [ "$UNAME" != "Darwin" ] && [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "i686" ]; then
echo "Sorry, OS/Architecture not supported: ${UNAME}/${ARCH}. Download binary from https://github.com/xuender/${BINARY}/releases"
exit 1
fi
mkdir -p $BIN_PATH
LATEST=$(get_latest_release)
echo "$LATEST"
URL="https://github.com/xuender/webhash/releases/download/$LATEST/${BINARY}_${PLATFORM}"
echo "download $URL"
rm -rf $DEST
curl -L $URL -o $DEST
chmod +x $DEST
}
run() {
echo "Running webhash..."
webhash
}
if [ -f $DEST ]; then
echo "Webhash is already installed."
else
echo "Webhash is not installed."
fi
install
run