-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
79 lines (66 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
77
78
79
#!/bin/bash
NAME="spm"
BIN_NAME="spm"
VERSION="0.2.1"
PREFIX="/usr/local"
COMP_PREFIX="/usr/local/share/zsh/site-functions"
GITHUB_USER="tzmfreedom"
TMP_DIR="/tmp"
ZSH_COMPLETION=""
set -ue
function parse_options() {
for OPT in "$@"
do
case "$OPT" in
"--zsh-completion" )
ZSH_COMPLETION="t"
;;
-* )
echo "$PROGRAM: illegal option -- '$(echo $1 | sed 's/^-*//')'" 1>&2
exit 1
;;
esac
shift
done
}
parse_options $@
UNAME=$(uname -s)
if [ "$UNAME" != "Linux" -a "$UNAME" != "Darwin" ] ; then
echo "Sorry, OS not supported: ${UNAME}. Download binary from https://github.com/${USERNAME}/${NAME}/releases"
exit 1
fi
if [ "${UNAME}" = "Darwin" ] ; then
OS="darwin"
OSX_ARCH=$(uname -m)
if [ "${OSX_ARCH}" = "x86_64" ] ; then
ARCH="amd64"
else
echo "Sorry, architecture not supported: ${OSX_ARCH}. Download binary from https://github.com/${USERNAME}/${NAME}/releases"
exit 1
fi
elif [ "${UNAME}" = "Linux" ] ; then
OS="linux"
LINUX_ARCH=$(uname -m)
if [ "${LINUX_ARCH}" = "i686" ] ; then
ARCH="386"
elif [ "${LINUX_ARCH}" = "x86_64" ] ; then
ARCH="amd64"
else
echo "Sorry, architecture not supported: ${LINUX_ARCH}. Download binary from https://github.com/${USERNAME}/${NAME}/releases"
exit 1
fi
fi
ARCHIVE_FILE=${NAME}-${VERSION}-${OS}-${ARCH}.tar.gz
BINARY="https://github.com/${GITHUB_USER}/${NAME}/releases/download/v${VERSION}/${ARCHIVE_FILE}"
cd $TMP_DIR
curl -sL -O ${BINARY}
tar xzf ${ARCHIVE_FILE}
mv ${OS}-${ARCH}/${BIN_NAME} ${PREFIX}/bin/${BIN_NAME}
chmod +x ${PREFIX}/bin/${BIN_NAME}
if [ -d ${COMP_PREFIX} ]; then
if [ "${ZSH_COMPLETION}" == "t" ]; then
mv ${OS}-${ARCH}/_${BIN_NAME} ${COMP_PREFIX}/_${BIN_NAME}
fi
fi
rm -rf ${OS}-${ARCH}
rm -rf ${ARCHIVE_FILE}