-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·140 lines (121 loc) · 2.72 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
{ # this ensures the entire script is downloaded #
set -e
KNOB_VERSION='v0.0.6'
has_wget() {
if [ $(type -P wget) ]; then
echo "1"
else
echo "0"
fi
}
has_curl() {
if [ $(type -P curl) ]; then
echo "1"
else
echo "0"
fi
}
is_x64arch() {
local HARDWARE_NAME
HARDWARE_NAME=$(uname -m)
if [[ $HARDWARE_NAME == *"x86_64"* ]]; then
echo "1"
else
echo "0"
fi
}
get_platform() {
local unameOut
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
*) machine="UNKNOWN:${unameOut}"
esac
echo ${machine}
}
get_bin() {
local PLATFORM
local IS_X64
PLATFORM=$(get_platform)
IS_X64=$(is_x64arch)
if [ $PLATFORM == "Mac" ]
then
if [ $IS_X64 == "1" ]; then
echo "knob-macos-x64"
else
echo "The install script only supports x64 architecture at this time. A PR that fixes this would be welcome."
knob_reset
exit 1
fi
elif [ $PLATFORM == "Linux" ]
then
echo "knob-linux-x64"
else
echo "This script does not support platform: $PLATFORM"
knob_reset
exit 1
fi
}
is_root() {
if [[ "$EUID" = 0 ]]; then
echo 1
else
echo 0
fi
}
dl_wget() {
local KNOB_BIN
KNOB_BIN=$(get_bin)
wget --quiet --show-progress https://github.com/tkambler/knob/releases/download/$KNOB_VERSION/${KNOB_BIN} -O /tmp/knob
chmod +x /tmp/knob
}
dl_curl() {
local KNOB_BIN
KNOB_BIN=$(get_bin)
curl --silent --progress-bar -o /tmp/knob https://github.com/tkambler/knob/releases/download/$KNOB_VERSION/${KNOB_BIN}
}
dl_knob() {
if [ $(has_wget) == "1" ]
then
dl_wget
elif [ $(has_curl) == "1" ]
then
dl_curl
else
echo "Error: Unable to find wget or curl executable"
knob_reset
exit 1
fi
}
set_perms() {
chmod +x /tmp/knob
}
move_bin() {
if [ $(is_root) == "1" ]; then
mv /tmp/knob /usr/local/bin/knob
else
echo "Moving knob to: /usr/local/bin/knob"
sudo mv /tmp/knob /usr/local/bin/knob
fi
}
on_success() {
local NEW_KNOB_VERSION
NEW_KNOB_VERSION=$(knob -v)
echo "Knob has been saved to: /usr/local/bin/knob"
echo "Version: $NEW_KNOB_VERSION"
}
knob_do_install() {
dl_knob
set_perms
move_bin
on_success
knob_reset
}
knob_reset() {
unset -f has_wget has_curl is_root dl_wget dl_curl dl_knob set_perms move_bin on_success knob_do_install get_platform get_bin is_x64arch knob_reset
unset -v KNOB_VERSION
}
knob_do_install
} # this ensures the entire script is downloaded #