-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·168 lines (133 loc) · 3.41 KB
/
install.sh
File metadata and controls
executable file
·168 lines (133 loc) · 3.41 KB
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
162
163
164
165
166
167
168
#!/bin/bash
set -u
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | sed -e 's/version = "//' -e 's/"$//')
UPDATE_ROOT="https://github.com/KhanShaheb34/Coterm/releases/download/v${CURRENT_VERSION}"
main() {
downloader --check
need_cmd uname
need_cmd mktemp
need_cmd chmod
need_cmd mkdir
need_cmd rm
need_cmd rmdir
need_cmd tar
need_cmd which
need_cmd dirname
get_architecture || return 1
local _arch="$RETVAL"
assert_nz "$_arch" "arch"
local _tardir="coterm-v${CURRENT_VERSION}-${_arch}"
local _url="$UPDATE_ROOT/${_tardir}.tar.gz"
echo "Downloading Coterm from $_url"
local _dir="$(mktemp -d 2>/dev/null || ensure mktemp -d -t coterm)"
local _file="$_dir/input.tar.gz"
local _coterm="$_dir/coterm"
local _path="/usr/local/bin/coterm"
local _shortpath="/usr/local/bin/ct"
printf '%s\n' 'info: downloading Coterm' 1>&2
ensure mkdir -p "$_dir"
downloader "$_url" "$_file"
if [ $? != 0 ]; then
say "failed to download $_url"
say "this may be a standard network error, but it may also indicate"
say "that Coterm's release process is not working. When in doubt"
say "please feel free to open an issue!"
exit 1
fi
ensure tar xf "$_file" --strip-components 1 -C "$_dir"
echo "Copying Coterm to $_path and $_shortpath"
ensure sudo cp "$_coterm" "$_path"
ensure chmod +x "$_path"
ensure sudo cp "$_coterm" "$_shortpath"
ensure chmod +x "$_shortpath"
ignore rm -rf "$_dir"
}
get_architecture() {
local _ostype="$(uname -s)"
local _cputype="$(uname -m)"
set +u
if [ -n "$TARGETOS" ]; then
_ostype="$TARGETOS"
fi
if [ -n "$TARGETARCH" ]; then
_cputype="$TARGETARCH"
fi
set -u
if [ "$_ostype" = Darwin -a "$_cputype" = i386 ]; then
if sysctl hw.optional.x86_64 | grep -q ': 1'; then
local _cputype=x86_64
fi
fi
case "$_ostype" in
Linux | linux)
local _ostype=unknown-linux-musl
;;
Darwin)
local _ostype=apple-darwin
;;
MINGW* | MSYS* | CYGWIN*)
local _ostype=pc-windows-msvc
;;
*)
err "no precompiled binaries available for OS: $_ostype"
;;
esac
case "$_cputype" in
x86_64 | x86-64 | x64 | amd64)
local _cputype=x86_64
;;
arm64 | aarch64)
local _cputype=aarch64
;;
*)
err "no precompiled binaries available for CPU architecture: $_cputype"
esac
local _arch="$_cputype-$_ostype"
RETVAL="$_arch"
}
say() {
echo "Coterm-init: $1"
}
err() {
say "$1" >&2
exit 1
}
need_cmd() {
if ! check_cmd "$1"
then err "need '$1' (command not found)"
fi
}
check_cmd() {
command -v "$1" > /dev/null 2>&1
return $?
}
need_ok() {
if [ $? != 0 ]; then err "$1"; fi
}
assert_nz() {
if [ -z "$1" ]; then err "assert_nz $2"; fi
}
ensure() {
"$@"
need_ok "command failed: $*"
}
ignore() {
"$@"
}
downloader() {
if check_cmd curl
then _dld=curl
elif check_cmd wget
then _dld=wget
else _dld='curl or wget'
fi
if [ "$1" = --check ]
then need_cmd "$_dld"
elif [ "$_dld" = curl ]
then curl -sSfL "$1" -o "$2"
elif [ "$_dld" = wget ]
then wget "$1" -O "$2"
else err "Unknown downloader"
fi
}
main "$@" || exit 1