-
Notifications
You must be signed in to change notification settings - Fork 9
/
install.sh
executable file
·92 lines (79 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
# error codes
# 0 - exited without problems
# 1 - parameters not supported were used or some unexpected error occurred
# 2 - OS not supported by this script
# 3 - installed version of oneshot is up to date
set -e
usage() { echo "Usage: curl https://github.com/forestnode-io/oneshot/raw/master/install.sh | sudo bash " 1>&2; exit 1; }
#create tmp directory and move to it with macOS compatibility fallback
tmp_dir=`mktemp -d 2>/dev/null || mktemp -d -t 'oneshot-install.XXXXXXXXXX'`; cd $tmp_dir
#check installed version of oneshot to determine if update is necessary
version=`oneshot -v 2>>errors | head -n 1 | awk '{print $4}'`
current_version=`curl -s -L https://github.com/forestnode-io/oneshot/raw/master/version.txt | tr -d "v"`
if [ "$version" = "$current_version" ]; then
printf "\nThe latest version of oneshot ${version} is already installed.\n\n"
exit 3
fi
#detect the platform
OS="`uname`"
case $OS in
Linux)
OS='linux'
;;
Darwin)
OS='macos'
;;
*)
echo 'OS not supported'
exit 2
;;
esac
ARCH_TYPE="`uname -m`"
case $ARCH_TYPE in
x86_64|amd64)
ARCH_TYPE='x86_64'
;;
i?86|x86)
ARCH_TYPE='386'
;;
arm*)
ARCH_TYPE='arm'
;;
aarch64)
ARCH_TYPE='arm64'
;;
*)
echo 'OS type not supported'
exit 2
;;
esac
#download and untar
download_link="https://github.com/forestnode-io/oneshot/releases/download/v${current_version}/oneshot_${current_version}.${OS}-${ARCH_TYPE}.tar.gz"
oneshot_tarball="oneshot_${current_version}.${OS}-${ARCH_TYPE}.tar.gz"
curl -s -O -L $download_link
untar_dir="oneshot_untar"
mkdir $untar_dir
tar -xzf $oneshot_tarball -C $untar_dir
cd $untar_dir
#install oneshot
case $OS in
'linux')
cp oneshot /usr/bin/oneshot
chmod 755 /usr/bin/oneshot
chown root:root /usr/bin/oneshot
;;
'macos')
mkdir -p /usr/local/bin
cp oneshot /usr/local/bin/oneshot
;;
*)
echo 'OS not supported'
exit 2
esac
# Let user know oneshot was installed
version=`oneshot --version 2>>errors | head -n 1 | awk '{print $4}'`
printf "\noneshot v${version} has successfully installed.\n"
printf 'You may now run "oneshot -h" for help with using oneshot.\n'
printf 'Visit https://github.com/forestnode-io/oneshot for more information.\n\n'
exit 0