This repository has been archived by the owner on Jul 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathomniedge-install.sh
161 lines (139 loc) · 3.23 KB
/
omniedge-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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/sh
set -e
#set -n noglob
STORAGE_URL=https://github.com/omniedgeio/app-release/releases/download
PKG_NAME="omniedgecli"
VERSION="v0.2.3"
BIN_DIR="/usr/local/bin"
setup_env() {
SUDO=sudo
if [ $(id -u) -eq 0 ]; then
SUDO=
fi
}
download_and_verify() {
setup_verify_arch
verify_downloader curl || verify_downloader wget || fatal 'Can not find curl or wget for downloading files'
verify_unzip unzip || fatal 'Can not find unzip'
setup_tmp
download_binary
setup_binary
}
output_usage(){
echo ""
}
# --- create temporary directory and cleanup when done ---
setup_tmp() {
TMP_DIR=$(mktemp -d -t omniedge-install.XXXXXXXXXX)
TMP_HASH=${TMP_DIR}/omniedge.hash
TMP_ZIP=${TMP_DIR}/omniedge.zip
TMP_BIN=${TMP_DIR}/omniedge.bin
cleanup() {
code=$?
set +e
trap - EXIT
rm -rf ${TMP_DIR}
exit $code
}
trap cleanup INT EXIT
}
# --- download binary from github url ---
download_binary() {
OS=$(uname)
BIN_URL=""
if [ $OS == 'Darwin' ]; then
BIN_URL=${STORAGE_URL}/${VERSION}/${PKG_NAME}-macos.zip
else
BIN_URL=${STORAGE_URL}/${VERSION}/${PKG_NAME}-${SUFFIX}.zip
fi
info "Downloading binary zip ${BIN_URL}"
download ${TMP_ZIP} ${BIN_URL}
}
# --- setup permissions and move binary to system directory ---
setup_binary() {
info "Unzip omniedge"
$UNZIP ${TMP_ZIP} -d ${TMP_BIN}
info "Installing omniedge to ${BIN_DIR}/omniedge"
chmod 755 ${TMP_BIN}/omniedge
$SUDO mv -f ${TMP_BIN}/omniedge ${BIN_DIR}/omniedge
}
# --- set arch and suffix, fatal if architecture not supported ---
setup_verify_arch() {
if [ -z "$ARCH" ]; then
ARCH=$(uname -m)
fi
case $ARCH in
amd64)
ARCH=amd64
SUFFIX=amd64
;;
x86_64)
ARCH=amd64
SUFFIX=amd64
;;
arm64)
ARCH=arm64
SUFFIX=arm64v8
;;
aarch64)
ARCH=arm64
SUFFIX=arm64v8
;;
arm*)
ARCH=arm
SUFFIX=armv7
;;
*)
fatal "Unsupported architecture $ARCH"
;;
esac
}
# --- verify existence of network downloader executable ---
verify_downloader() {
# Return failure if it doesn't exist or is no executable
[ -x "$(command -v $1)" ] || return 1
# Set verified executable as our downloader program and return success
DOWNLOADER=$1
return 0
}
# --- verify unzip ---
verify_unzip() {
# Return failure if it doesn't exist or is no executable
[ -x "$(command -v $1)" ] || return 1
# Set verified executable as our downloader program and return success
UNZIP=$1
return 0
}
# --- download from github url ---
download() {
[ $# -eq 2 ] || fatal 'download needs exactly 2 arguments'
case $DOWNLOADER in
curl)
curl -o $1 -sfL $2
;;
wget)
wget -qO $1 $2
;;
*)
fatal "Incorrect executable '$DOWNLOADER'"
;;
esac
# Abort if download command failed
[ $? -eq 0 ] || fatal 'Download failed'
}
# --- helper functions for logs ---
info() {
echo '[INFO] ' "$@"
}
warn() {
echo '[WARN] ' "$@" >&2
}
fatal() {
echo '[ERROR] ' "$@" >&2
exit 1
}
{
setup_env
download_and_verify
output_usage
}