@gizai/cli 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/install.sh DELETED
@@ -1,260 +0,0 @@
1
- #!/bin/sh
2
- # Install Gizlang: curl -fsSL https://gizstack.com/install | sh
3
- # Install it for the GizDB server: curl -fsSL https://gizstack.com/install | sh -s -- --only gizdb
4
- # While gizstack.com is in private preview, the command on your signed-in page adds
5
- # -H "Authorization: Bearer TOKEN": the script served for it carries that access token
6
- # and stores it in ~/.config/gizstack/access-token, where the installer and
7
- # `giz upgrade` read it.
8
- #
9
- # This script downloads the official installer for your platform from its
10
- # content address, checks its SHA-256 against that address and runs it. The
11
- # installer verifies the release signature and every file hash before it
12
- # activates the version. Nothing needs root. Docs: https://gizstack.com/docs/start
13
- #
14
- # Options (sh -s -- OPTION...):
15
- # --only gizdb install it for the GizDB server, into ~/.gizdb: bin/gizdb
16
- # runs the server, which compiles its scan kernels with it
17
- # --version VERSION install this published version (default: the newest)
18
- # --no-modify-path do not add the bin directory to shell profiles
19
- # --installer FILE use this downloaded installer (the npm and Homebrew
20
- # packages carry it); its SHA-256 is checked the same way
21
- # --if-missing do nothing when this version is installed already
22
- # (the package wrappers run it before each command)
23
- # Environment: GIZ_INSTALL (default ~/.giz; with --only gizdb,
24
- # GIZDB_INSTALL, default ~/.gizdb), NO_MODIFY_PATH=1.
25
- #
26
- # Everything runs inside main(), called on the last line, so a download that
27
- # is cut off does nothing.
28
-
29
- set -u
30
-
31
- SITE="https://gizstack.com"
32
- # The access token this script was served for (the server writes it here), or empty.
33
- ACCESS=''
34
-
35
- # Published installers: target, version, installer SHA-256.
36
- # Generated from $SITE/api/releases when this script was served.
37
- releases() {
38
- cat <<'RELEASES'
39
- x86_64-unknown-linux-gnu 0.1.0-preview.20261023.8 69c0c897fa694c7e9b9fa8de9dec8d54b0479d5b451fa2a118c427300c111aac
40
- RELEASES
41
- }
42
-
43
- say() { printf '%s\n' "$*"; }
44
- fail() { printf 'giz-install: %s\n' "$*" >&2; exit 1; }
45
-
46
- detect_target() {
47
- os=$(uname -s)
48
- arch=$(uname -m)
49
- case "$arch" in
50
- x86_64 | amd64) arch=x86_64 ;;
51
- aarch64 | arm64) arch=aarch64 ;;
52
- *) fail "unsupported CPU architecture: $arch. Supported platforms: $SITE/download" ;;
53
- esac
54
- case "$os" in
55
- Linux)
56
- libc=gnu
57
- if ls /lib/ld-musl-* >/dev/null 2>&1 || (ldd --version 2>&1 | grep -qi musl); then libc=musl; fi
58
- target="$arch-unknown-linux-$libc" ;;
59
- Darwin)
60
- # No macOS release until a Mac builds and tests it: say so instead of naming a missing target.
61
- printf '%s\n' "macOS is coming; use the Playground ($SITE/play) or a Linux machine meanwhile" >&2
62
- exit 1 ;;
63
- MINGW* | MSYS* | CYGWIN* | Windows_NT)
64
- fail "on Windows, run in PowerShell: irm $SITE/install.ps1 | iex" ;;
65
- *) fail "unsupported operating system: $os. Supported platforms: $SITE/download" ;;
66
- esac
67
- }
68
-
69
- # Sets digest and version from the table, or explains what exists.
70
- select_release() {
71
- digest=""
72
- [ -n "$(releases)" ] || fail "no Gizlang release supports this install script yet. Download an installer: $SITE/download"
73
- found=$(releases | while read -r t v d; do
74
- if [ "$t" = "$target" ] && { [ -z "$wanted" ] || [ "$v" = "$wanted" ]; }; then say "$v $d"; break; fi
75
- done)
76
- if [ -n "$found" ]; then version=${found% *}; digest=${found#* }; return; fi
77
- available=$(releases | while read -r t v d; do if [ "$t" = "$target" ]; then printf ' %s' "$v"; fi; done)
78
- if [ -n "$available" ]; then fail "$name $wanted is not published for $target. Published:$available"; fi
79
- platforms=$(releases | while read -r t v d; do printf '\n %s' "$t"; done)
80
- [ -n "$platforms" ] || fail "no $name release supports this install script yet. Release status: $SITE/download"
81
- fail "no $name release for $target yet. Published platforms:$platforms
82
- Use the browser Playground meanwhile: $SITE/play. Release status: $SITE/download"
83
- }
84
-
85
- download() { # URL FILE
86
- if command -v curl >/dev/null 2>&1; then
87
- if [ -n "$KEY" ]; then curl --proto '=https' --tlsv1.2 -fsSL --retry 3 -H "Authorization: Bearer $KEY" -o "$2" "$1"
88
- else curl --proto '=https' --tlsv1.2 -fsSL --retry 3 -o "$2" "$1"; fi
89
- elif command -v wget >/dev/null 2>&1; then
90
- if [ -n "$KEY" ]; then wget --https-only -q --header="Authorization: Bearer $KEY" -O "$2" "$1"
91
- else wget --https-only -q -O "$2" "$1"; fi
92
- elif command -v node >/dev/null 2>&1; then
93
- # The npm package runs this script, so Node.js is there even where curl and wget are not (node:*-slim, a minimal WSL).
94
- node -e 'const [u, f, k] = process.argv.slice(1); if (!u.startsWith("https://")) { console.error("not https: " + u); process.exit(1); }
95
- require("https").get(u, { headers: k ? { Authorization: "Bearer " + k } : {} }, (r) => {
96
- if (r.statusCode !== 200) { console.error("HTTP " + r.statusCode + " for " + u); process.exit(1); }
97
- r.pipe(require("fs").createWriteStream(f)).on("error", (e) => { console.error(e.message); process.exit(1); });
98
- }).on("error", (e) => { console.error(e.message); process.exit(1); });' "$1" "$2" "$KEY"
99
- else
100
- fail "curl, wget or node is required"
101
- fi
102
- }
103
-
104
- sha256() {
105
- if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d ' ' -f 1
106
- elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d ' ' -f 1
107
- elif command -v openssl >/dev/null 2>&1; then openssl dgst -sha256 -r "$1" | cut -d ' ' -f 1
108
- else fail "sha256sum, shasum or openssl is required to check the installer"
109
- fi
110
- }
111
-
112
- add_line() { # FILE LINE: append LINE once
113
- if [ -f "$1" ] && grep -qxF "$2" "$1"; then return; fi
114
- printf '\n%s\n' "$2" >>"$1" && changed="$changed $1"
115
- }
116
-
117
- # One line in each profile sources $root/env, which adds bin to PATH once.
118
- modify_path() {
119
- bin="$root/bin"
120
- cat >"$root/env" <<ENV
121
- # Added by the $name installer.
122
- case ":\${PATH}:" in *":$bin:"*) ;; *) export PATH="$bin:\$PATH" ;; esac
123
- ENV
124
- cat >"$root/env.fish" <<ENV
125
- # Added by the $name installer.
126
- if not contains -- "$bin" \$PATH; set -gx PATH "$bin" \$PATH; end
127
- ENV
128
- line=". \"$root/env\""
129
- zshrc="${ZDOTDIR:-$HOME}/.zshrc"
130
- for profile in "$HOME/.profile" "$HOME/.bashrc" "$HOME/.bash_profile" "$zshrc"; do
131
- case "$profile" in
132
- "$HOME/.bash_profile") [ -f "$profile" ] || continue ;;
133
- "$zshrc") [ -f "$profile" ] || command -v zsh >/dev/null 2>&1 || continue ;;
134
- esac
135
- add_line "$profile" "$line"
136
- done
137
- if command -v fish >/dev/null 2>&1 || [ -d "$HOME/.config/fish" ]; then
138
- mkdir -p "$HOME/.config/fish/conf.d"
139
- fishline="source \"$root/env.fish\""
140
- fishrc="$HOME/.config/fish/conf.d/$command.fish"
141
- add_line "$fishrc" "$fishline"
142
- fi
143
- # The profile this shell reads, for the line that tells the person what to source now.
144
- case "${SHELL:-}" in
145
- */zsh) rc=$zshrc ;;
146
- */fish) rc=${fishrc:-$HOME/.bashrc} ;;
147
- *) rc="$HOME/.bashrc" ;;
148
- esac
149
- }
150
-
151
- # The installer, `giz upgrade` and package reads send this token to gizstack.com.
152
- store_access() {
153
- [ -n "$ACCESS" ] || return 0
154
- config="${XDG_CONFIG_HOME:-$HOME/.config}/gizstack"
155
- (umask 077 && mkdir -p "$config" && printf '%s\n' "$ACCESS" >"$config/access-token.new" && mv "$config/access-token.new" "$config/access-token") || fail "cannot store the access token in $config"
156
- }
157
-
158
- # A script not served with a key (npm, or a rerun) takes the key the way access.giz does: GIZ_ACCESS_TOKEN, else the
159
- # file. Only the downloads below use it, and only from $SITE. A value outside the token alphabet is refused whole, as
160
- # access.giz refuses it, so a bad value is never sent.
161
- resolve_access() {
162
- KEY=$ACCESS
163
- if [ -z "$KEY" ]; then KEY=$(printf '%s' "${GIZ_ACCESS_TOKEN:-}" | tr -d ' \t\r\n'); fi
164
- if [ -z "$KEY" ] && [ -n "${HOME:-}" ]; then
165
- KEY=$(tr -d ' \t\r\n' 2>/dev/null <"${XDG_CONFIG_HOME:-$HOME/.config}/gizstack/access-token")
166
- fi
167
- case "$KEY" in *[!0-9a-z_]*) KEY='' ;; esac
168
- }
169
-
170
- main() {
171
- wanted=""
172
- local_installer=""
173
- if_missing=0
174
- only=""
175
- path_changes=1
176
- if [ -n "${NO_MODIFY_PATH:-}" ]; then path_changes=0; fi
177
- while [ $# -gt 0 ]; do
178
- case "$1" in
179
- --only) [ $# -ge 2 ] || fail "--only needs a value"; [ "$2" = gizdb ] || fail "--only takes gizdb (the GizDB server), not $2"; only=gizdb; shift 2 ;;
180
- --version) [ $# -ge 2 ] || fail "--version needs a value"; wanted=$2; shift 2 ;;
181
- --no-modify-path) path_changes=0; shift ;;
182
- --if-missing) if_missing=1; shift ;;
183
- --installer) [ $# -ge 2 ] || fail "--installer needs a value"; local_installer=$2; shift 2 ;;
184
- -h | --help) say "Usage: curl -fsSL $SITE/install | sh -s -- [--only gizdb] [--version VERSION] [--no-modify-path]"; say "Docs: $SITE/docs/start"; exit 0 ;;
185
- *) fail "unknown option: $1 (see $SITE/docs/start)" ;;
186
- esac
187
- done
188
- # For the GizDB server the toolchain goes to a folder of its own: its bin/gizdb runs the server, which compiles its
189
- # scan kernels with that toolchain (a server without a compiler ran every query on the interpreter).
190
- if [ "$only" = gizdb ]; then
191
- name=GizDB; command=gizdb; variable=GIZDB_INSTALL; root="${GIZDB_INSTALL:-}"; home=.gizdb
192
- else
193
- name=Gizlang; command=giz; variable=GIZ_INSTALL; root="${GIZ_INSTALL:-}"; home=.giz
194
- fi
195
- if [ -z "$root" ]; then
196
- [ -n "${HOME:-}" ] || fail "HOME is not set; set $variable to the installation directory"
197
- root="$HOME/$home"
198
- # An install from before the command was gizstack (~/.gizlang) is upgraded in place: the installer then removes
199
- # its gizlang command, and no second command stays on PATH.
200
- if [ "$only" != gizdb ] && [ ! -e "$root" ] && [ -f "$HOME/.gizlang/active-toolchain" ]; then root="$HOME/.gizlang"; fi
201
- fi
202
- if [ "$wanted" = latest ]; then wanted=""; fi
203
- case "$root" in
204
- /*) ;;
205
- *) fail "$variable must be an absolute path: $root" ;;
206
- esac
207
- case "$root" in
208
- *[\"\$\`\\]*) fail "$variable cannot contain quotes, \$, backquotes or backslashes: $root" ;;
209
- esac
210
-
211
- detect_target
212
- select_release
213
- if [ "$if_missing" = 1 ]; then
214
- for installed in "$root/versions/toolchain-$target-$version-"*; do
215
- if [ -f "$installed/release.json" ]; then exit 0; fi
216
- done
217
- fi
218
-
219
- work=$(mktemp -d 2>/dev/null || mktemp -d -t giz) || fail "cannot create a temporary directory"
220
- trap 'rm -rf "$work"' EXIT
221
- installer="$work/$command-installer"
222
- if [ -n "$local_installer" ]; then
223
- cp "$local_installer" "$installer" || fail "cannot read the installer $local_installer"
224
- else
225
- resolve_access
226
- if ! download "$SITE/objects/sha256/$digest" "$installer"; then
227
- [ -n "$KEY" ] || fail "the installer download was refused: $name is in private preview. Signed in at $SITE, your install command on $SITE/download carries your access key (or set GIZ_ACCESS_TOKEN). No invitation yet: $SITE/access-request"
228
- fail "the installer download failed: $SITE/objects/sha256/$digest"
229
- fi
230
- fi
231
- actual=$(sha256 "$installer")
232
- [ "$actual" = "$digest" ] || fail "the installer SHA-256 is $actual, not $digest; nothing was installed"
233
- chmod u+x "$installer"
234
-
235
- store_access
236
- mkdir -p "$root" || fail "cannot create $root"
237
- # The installer's own report is for a direct run; here the one summary line below says it.
238
- report=$("$installer" --root "$root") || { printf '%s\n' "$report" >&2; fail "the installer failed; the previous version, if any, stays active"; }
239
-
240
- changed=""
241
- if [ "$path_changes" = 1 ]; then modify_path; fi
242
- if [ "$only" = gizdb ]; then
243
- # gizdb has no --version; its usage proves the installed server runs here.
244
- "$root/bin/gizdb" --help >/dev/null || fail "$root/bin/gizdb does not run on this computer"
245
- next="GIZDB_PASSWORD=... gizdb serve --dir ~/gizdb-data --port 5432"
246
- else
247
- "$root/bin/giz" --version >/dev/null || fail "$root/bin/giz does not run on this computer"
248
- next="giz init hello && cd hello && giz run main.giz"
249
- fi
250
- shown=$root
251
- case "$root" in "${HOME:-/nonexistent}"/*) shown="~${root#"$HOME"}" ;; esac
252
- kb=$(du -sk "$root/versions" 2>/dev/null | cut -f 1)
253
- say "$name $version installed ($(( (${kb:-0} + 512) / 1024 )) MB in $shown). Next: $next"
254
- # PATH text only when a profile changed: under --no-modify-path (the npm package) the command is already found.
255
- if [ -n "$changed" ]; then
256
- say "Added $shown/bin to PATH in:$(printf %s "$changed" | sed "s#$HOME/#~/#g"). Open a new terminal, or run: source $(printf %s "$rc" | sed "s#^$HOME/#~/#")"
257
- fi
258
- }
259
-
260
- main "$@"