-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathinstall.sh
executable file
·93 lines (68 loc) · 1.94 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
#!/bin/bash
# curl -fsSL https://raw.githubusercontent.com/midoks/imail/master/scripts/install.sh | sh
check_go_environment() {
if test ! -x "$(command -v go)"; then
printf "\e[1;31mmissing go running environment\e[0m\n"
exit 1
fi
}
load_vars() {
OS=$(uname | tr '[:upper:]' '[:lower:]')
VERSION=$(get_latest_release "midoks/imail")
TARGET_DIR="/usr/local/imail"
}
get_latest_release() {
curl -sL "https://api.github.com/repos/$1/releases/latest" | grep '"tag_name":' | cut -d'"' -f4
}
get_arch() {
echo "package main
import (
\"fmt\"
\"runtime\"
)
func main() { fmt.Println(runtime.GOARCH) }" > /tmp/go_arch.go
ARCH=$(go run /tmp/go_arch.go)
}
get_download_url() {
DOWNLOAD_URL="https://github.com/midoks/imail/releases/download/$VERSION/imail_${VERSION}_${OS}_${ARCH}.tar.gz"
}
# download file
download_file() {
url="${1}"
destination="${2}"
printf "Fetching ${url} \n\n"
if test -x "$(command -v curl)"; then
code=$(curl --connect-timeout 15 -w '%{http_code}' -L "${url}" -o "${destination}")
elif test -x "$(command -v wget)"; then
code=$(wget -t2 -T15 -O "${destination}" --server-response "${url}" 2>&1 | awk '/^ HTTP/{print $2}' | tail -1)
else
printf "\e[1;31mNeither curl nor wget was available to perform http requests.\e[0m\n"
exit 1
fi
if [ "${code}" != 200 ]; then
printf "\e[1;31mRequest failed with code %s\e[0m\n" $code
exit 1
else
printf "\n\e[1;33mDownload succeeded\e[0m\n"
fi
}
main() {
check_go_environment
load_vars
get_arch
get_download_url
DOWNLOAD_FILE="$(mktemp).tar.gz"
download_file $DOWNLOAD_URL $DOWNLOAD_FILE
if [ ! -d "$TARGET_DIR" ]; then
mkdir -p "$TARGET_DIR"
fi
tar -C "$TARGET_DIR" -zxf $DOWNLOAD_FILE
rm -rf $DOWNLOAD_FILE
pushd "$TARGET_DIR/scripts" >/dev/null 2>&1
bash make.sh
systemctl daemon-reload
service imail restart
cd .. && ./imail -v
popd >/dev/null 2>&1
}
main "$@" || exit 1