-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkiptup
More file actions
197 lines (168 loc) · 5.59 KB
/
Copy pathkiptup
File metadata and controls
197 lines (168 loc) · 5.59 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/sh
set -eE
BASE_DIR=${XDG_CONFIG_HOME:-$HOME}
KIPT_DIR=${KIPT_DIR-"$BASE_DIR/.kipt"}
KIPT_BIN_DIR="$KIPT_DIR/bin"
KIPT_MAN_DIR="$KIPT_DIR/share/man/man1"
KIPT_BIN_PATH="${KIPT_BIN_DIR}/kipt"
# This MUST be updated whenever this file is changed.
# TODO: add CI check to ensure this.
KIPTUP_VERSION="2023-08-30"
# Fancy color setup:
# https://unix.stackexchange.com/questions/9957/how-to-check-if-bash-can-print-colors
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
bold="$(tput bold)"
underline="$(tput smul)"
standout="$(tput smso)"
normal="$(tput sgr0)"
black="$(tput setaf 0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
white="$(tput setaf 7)"
fi
fi
main() {
RELEASE_TAG=latest
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-v|--version)
if [ $# -gt 1 ]; then
case $2 in
"v"*)
RELEASE_TAG="$2"
;;
*)
RELEASE_TAG="v$2"
;;
esac
shift
else
echo "${red}Version tag is missing${normal}" 1>&2
exit 1
fi
;;
*)
echo "${red}Unknown option: $1${normal}" 1>&2
echo "Run ${yellow}kiptup --help${normal} to see usage." 1>&2
exit 1
;;
esac
shift
done
install
echo
echo "Installation successfully completed."
}
install() {
if [ $RELEASE_TAG = "latest" ]; then
echo "Installing the latest version of kipt..."
echo "Fetching the latest release tag from GitHub..."
RELEASE_TAG="$(curl -s "https://api.github.com/repos/glihm/kipt/releases/latest" | grep "tag_name" | cut -d \" -f 4)"
echo "Latest version found: ${yellow}${RELEASE_TAG}${normal}"
else
echo "Installing version ${yellow}${RELEASE_TAG}${normal}..."
fi
detect_host_triple
if [ -z "$TRIPLE" ]; then
echo "${red}Unable to detect platform.${normal} Please install kipt from source." 1>&2
exit 1
fi
echo "Detected host triple: ${cyan}${TRIPLE}${normal}"
FILE_NAME="kipt-${TRIPLE}.tar.gz"
FILE_URL="https://github.com/glihm/kipt/releases/download/${RELEASE_TAG}/${FILE_NAME}"
TEMP_DIR="$(mktemp -d)"
TEMP_FILE_NAME="${TEMP_DIR}/${FILE_NAME}"
# TODO: support wget if curl is not found
download_release_file
tar zxf $TEMP_FILE_NAME -C $TEMP_DIR
mv "${TEMP_DIR}/kipt" "${KIPT_BIN_PATH}"
rm -rf $TEMP_DIR
echo "Successfully installed kipt ${yellow}${LATEST_TAG}${normal}"
}
download_release_file() {
echo "Downloading release file from GitHub..."
if command -v curl >/dev/null 2>&1; then
HTTP_CODE="$(curl -# -L "$FILE_URL" -o "$TEMP_FILE_NAME" --write-out "%{http_code}")"
if [ "$HTTP_CODE" -ne 200 ]; then
echo "${red}Couldn't download release file for tag '${RELEASE_TAG}' from GitHub [${HTTP_CODE}].${normal}"
exit 1
fi
else
echo "${red}Command 'curl' is required.${normal}"
exit 1
fi
}
detect_host_triple() {
PLATFORM="$(uname -s)"
ARCHITECTURE="$(uname -m)"
case $PLATFORM in
Linux)
# Android Termux detection
case $PREFIX in
*com.termux*)
case $ARCHITECTURE in
aarch64|arm64)
TRIPLE="aarch64-linux-android"
;;
esac
;;
*)
# Likely very unreliable way to check musl
if [ -n "$(ls /lib | grep "libc.musl-")" ]; then
case $ARCHITECTURE in
x86_64)
TRIPLE="x86_64-unknown-linux-musl"
;;
aarch64|arm64)
TRIPLE="aarch64-unknown-linux-musl"
;;
esac
else
case $ARCHITECTURE in
x86_64)
TRIPLE="x86_64-unknown-linux-gnu"
;;
aarch64|arm64)
TRIPLE="aarch64-unknown-linux-gnu"
;;
esac
fi
esac
;;
Darwin)
case $ARCHITECTURE in
x86_64)
TRIPLE="x86_64-apple-darwin"
;;
aarch64|arm64)
TRIPLE="aarch64-apple-darwin"
;;
esac
;;
esac
}
usage() {
cat 1>&2 <<EOF
kiptup ${cyan}(${KIPTUP_VERSION})${normal}
The installer for kipt.
Install the latest version of kipt by running without any options.
More installation options will be implemented. To update kiptup itself, run the installation command again:
curl https://raw.githubusercontent.com/glihm/kipt/main/kiptup/install | sh
USAGE:
kiptup <OPTIONS>
OPTIONS:
-h, --help Print this message
-v, --version The version of kipt to install
EOF
}
main "$@"