Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·180 lines (155 loc) · 4.71 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·180 lines (155 loc) · 4.71 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
#!/bin/sh
set -eu
BIN_NAME="confluence-cli"
SKILL_NAME="confluence-cli"
REPO="${CONFLUENCE_CLI_REPO:-laipz8200/confluence-cli}"
GITHUB_BASE_URL="${CONFLUENCE_CLI_GITHUB_BASE_URL:-https://github.com}"
GITHUB_API_URL="${CONFLUENCE_CLI_GITHUB_API_URL:-https://api.github.com}"
REQUESTED_VERSION="${CONFLUENCE_CLI_VERSION:-latest}"
GITHUB_BASE_URL="${GITHUB_BASE_URL%/}"
GITHUB_API_URL="${GITHUB_API_URL%/}"
fail() {
printf 'confluence-cli install.sh: %s\n' "$*" >&2
exit 1
}
usage() {
cat <<'USAGE'
Usage:
install.sh
install.sh --uninstall
USAGE
}
need_command() {
command -v "$1" >/dev/null 2>&1 || fail "Missing required command: $1"
}
detect_target() {
os=$(uname -s)
arch=$(uname -m)
case "$os:$arch" in
Linux:x86_64 | Linux:amd64)
printf 'x86_64-unknown-linux-gnu\n'
;;
Linux:aarch64 | Linux:arm64)
printf 'aarch64-unknown-linux-gnu\n'
;;
Darwin:x86_64 | Darwin:amd64)
printf 'x86_64-apple-darwin\n'
;;
Darwin:arm64 | Darwin:aarch64)
printf 'aarch64-apple-darwin\n'
;;
*)
fail "Unsupported platform: $os/$arch. Release binaries are available for Linux x86_64, Linux arm64, macOS x86_64, and macOS arm64."
;;
esac
}
resolve_tag() {
if [ "$REQUESTED_VERSION" = "latest" ]; then
latest_json=$(curl -fsSL "$GITHUB_API_URL/repos/$REPO/releases/latest") \
|| fail "Failed to resolve the latest GitHub release."
tag=$(printf '%s\n' "$latest_json" \
| sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' \
| head -n 1)
[ -n "$tag" ] || fail "Could not find a tag_name in the latest GitHub release response."
printf '%s\n' "$tag"
return
fi
case "$REQUESTED_VERSION" in
v*) printf '%s\n' "$REQUESTED_VERSION" ;;
*) printf 'v%s\n' "$REQUESTED_VERSION" ;;
esac
}
default_install_dir() {
if [ -n "${CONFLUENCE_CLI_INSTALL_DIR:-}" ]; then
printf '%s\n' "$CONFLUENCE_CLI_INSTALL_DIR"
return
fi
[ -n "${HOME:-}" ] || fail "HOME is not set. Set CONFLUENCE_CLI_INSTALL_DIR to choose an install directory."
printf '%s/.local/bin\n' "$HOME"
}
uninstall_cli() {
install_dir=$(default_install_dir)
binary_path="$install_dir/$BIN_NAME"
if [ -e "$binary_path" ]; then
rm -f "$binary_path" || fail "Failed to remove $binary_path."
printf 'Removed %s from %s\n' "$BIN_NAME" "$binary_path"
else
printf '%s was not installed at %s\n' "$BIN_NAME" "$binary_path"
fi
if command -v npx >/dev/null 2>&1; then
printf 'Removing Agent Skills package\n'
npx skills remove "$SKILL_NAME" --yes </dev/null \
|| fail "Failed to remove Agent Skills package."
else
printf 'Note: npx is not on PATH; skipping Agent Skills package removal.\n'
fi
printf 'Note: configuration files were not removed.\n'
}
action=install
while [ "$#" -gt 0 ]; do
case "$1" in
--uninstall | uninstall)
action=uninstall
;;
--help | -h)
usage
exit 0
;;
--)
;;
*)
fail "Unknown argument: $1"
;;
esac
shift
done
if [ "$action" = "uninstall" ]; then
need_command rm
uninstall_cli
exit 0
fi
need_command curl
need_command head
need_command install
need_command mktemp
need_command sed
need_command tar
need_command uname
target="${CONFLUENCE_CLI_TARGET:-$(detect_target)}"
tag=$(resolve_tag)
version="${tag#v}"
asset="confluence-cli-$version-$target.tar.gz"
package="confluence-cli-$version-$target"
url="$GITHUB_BASE_URL/$REPO/releases/download/$tag/$asset"
install_dir=$(default_install_dir)
tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/confluence-cli.XXXXXX") \
|| fail "Failed to create a temporary directory."
cleanup() {
rm -rf "$tmpdir"
}
trap cleanup EXIT INT TERM
archive="$tmpdir/$asset"
printf 'Downloading %s\n' "$url"
curl -fsSL -o "$archive" "$url" || fail "Failed to download $asset."
tar -xzf "$archive" -C "$tmpdir" || fail "Failed to extract $asset."
binary="$tmpdir/$package/$BIN_NAME"
[ -f "$binary" ] || fail "Release archive did not contain $package/$BIN_NAME."
mkdir -p "$install_dir" || fail "Failed to create install directory: $install_dir"
install -m 0755 "$binary" "$install_dir/$BIN_NAME" \
|| fail "Failed to install $BIN_NAME to $install_dir."
printf 'Installed %s to %s\n' "$BIN_NAME" "$install_dir/$BIN_NAME"
case ":$PATH:" in
*":$install_dir:"*) ;;
*) printf 'Note: %s is not on PATH.\n' "$install_dir" ;;
esac
printf 'Running %s config init\n' "$install_dir/$BIN_NAME"
if [ -t 0 ]; then
"$install_dir/$BIN_NAME" config init \
|| fail "Failed to run $BIN_NAME config init."
elif ( : </dev/tty ) 2>/dev/null; then
"$install_dir/$BIN_NAME" config init </dev/tty \
|| fail "Failed to run $BIN_NAME config init."
else
"$install_dir/$BIN_NAME" config init \
|| fail "Failed to run $BIN_NAME config init."
fi