@jigw/install 0.0.0-stage → 0.1.0-review.1

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.
Files changed (3) hide show
  1. package/install.sh +82 -0
  2. package/package.json +6 -4
  3. package/README.md +0 -3
package/install.sh ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ umask 077
4
+ fail() { printf '%s\n' "$1" >&2; exit 1; }
5
+ root="$HOME/.jigw-hermes"
6
+ [[ $OSTYPE == linux* ]] || fail "이 설치기는 Linux에서 실행해야 합니다. 에이전트를 운영할 Linux 서버에서 다시 실행하세요."
7
+ if (( EUID == 0 )); then
8
+ printf '%s\n' 'JIGW host installer stopped before setup: current Linux user is root (UID 0).' >&2
9
+ printf '%s\n' 'Use the account that will own the agent files and run its own rootless Docker engine.' >&2
10
+ if [[ -n ${SUDO_USER:-} && $SUDO_USER != root ]]; then
11
+ printf '%s\n' 'If you opened this shell with sudo -i, type exit to leave it.' >&2
12
+ fi
13
+ fail 'In that account, run id -un to confirm the username, then run npx @jigw/install without sudo.'
14
+ fi
15
+ for tool in curl tar sha256sum mktemp install mv base64 flock timeout loginctl grep; do
16
+ command -v "$tool" >/dev/null || fail "Install the missing tool: $tool. Then run this command again."
17
+ done
18
+ [[ -x /usr/bin/node ]] && /usr/bin/node -e 'process.exit(Number(process.versions.node.split(".")[0]) >= 22 ? 0 : 1)' || fail "Install Node.js 22 or later at /usr/bin/node and retry."
19
+ mkdir -m 700 -- "$root" 2>/dev/null || [[ -d $root && ! -L $root && -O $root && $(stat -c %a "$root") == 700 ]] || fail "Check ownership and permissions on ~/.jigw-hermes (mode 700)."
20
+ stage=$(mktemp -d -- "$root/.setup.XXXXXXXX") || fail "Check free space and write access in ~/.jigw-hermes."
21
+ trap 'rm -rf -- "$stage"' EXIT
22
+ check_worker_host() {
23
+ command -v systemctl >/dev/null && timeout 10 systemctl --user show-environment >/dev/null ||
24
+ fail "현재 계정의 systemd 사용자 서비스에 연결할 수 없습니다. 설치 계정으로 직접 로그인한 뒤 systemctl --user status를 확인하세요."
25
+ local runtime endpoint options
26
+ runtime=$(loginctl show-user "$EUID" -p RuntimePath --value) ||
27
+ fail "설치 계정의 systemd 런타임 경로를 확인할 수 없습니다. loginctl user 설정을 확인하세요."
28
+ [[ $runtime == /* ]] || fail "설치 계정의 systemd 런타임 경로가 비어 있습니다. 로그인 세션을 확인하세요."
29
+ endpoint=${DOCKER_HOST:-"unix://$runtime/docker.sock"}
30
+ [[ $endpoint == "unix://$runtime/"* && $endpoint != *'/../'* && $endpoint != *'/..' ]] ||
31
+ fail "설치 계정의 런타임 경로 아래에 있는 rootless Docker Unix 소켓을 DOCKER_HOST에 지정한 뒤 다시 실행하세요."
32
+ command -v docker >/dev/null || fail "Docker CLI가 없습니다. 이 계정에 rootless Docker를 준비하세요."
33
+ local socket=${endpoint#unix://} source='default for this user' rc
34
+ [[ -z ${DOCKER_HOST:-} ]] || source=DOCKER_HOST
35
+ if [[ ! -S $socket ]]; then
36
+ printf 'JIGW Docker check stopped: no Unix socket found at %q (%s, UID %s).\n' "$socket" "$source" "$EUID" >&2
37
+ fail "Check the socket path and whether this user can access its parent directory. Check that this user's rootless Docker service has started and is listening at that path. Then retry."
38
+ fi
39
+ timeout 15 docker --host "$endpoint" version --format '{{.Server.Version}}' >/dev/null || {
40
+ rc=$?
41
+ printf 'JIGW Docker check stopped: Unix socket found at %q (%s, UID %s).\n' "$socket" "$source" "$EUID" >&2
42
+ if (( rc == 124 )); then
43
+ printf '%s\n' 'Docker did not return its server version within 15 seconds.' >&2
44
+ else
45
+ printf 'Docker could not read the server version (exit %s). See the Docker error above.\n' "$rc" >&2
46
+ fi
47
+ printf 'From the same account, run: docker --host %q version\n' "$endpoint" >&2
48
+ fail "Check the rootless Docker service status and logs for this socket. Retry when the command shows a Server version."
49
+ }
50
+ options=$(timeout 15 docker --host "$endpoint" info --format '{{range .SecurityOptions}}{{println .}}{{end}}') ||
51
+ fail "JIGW Docker check stopped: the engine returned its version, but docker info failed. Check the Docker error above and run docker info against the same socket."
52
+ grep -Fxq 'name=rootless' <<<"$options" ||
53
+ fail "이 소켓의 Docker는 rootless가 아닙니다. 설치 계정의 rootless Docker 소켓을 확인하세요."
54
+ printf '%s\n' 'services:' ' probe:' ' image: busybox:latest' |
55
+ timeout 15 docker --host "$endpoint" compose -f - config -q ||
56
+ fail "Docker Compose가 실행되지 않습니다. 이 계정의 Docker Compose v2 플러그인을 설치하거나 복구한 뒤 다시 시도하세요."
57
+ }
58
+ case ${1:-install} in
59
+ install)
60
+ check_worker_host
61
+ install -m 700 -- "$0" "$stage/launcher"
62
+ mv -Tf -- "$stage/launcher" "$root/jigw-host-install.sh"
63
+ echo "설치 완료. 서버 실행 환경 확인을 통과했습니다. JIGW 관리자 화면에서 서버 등록 명령을 발급하세요."
64
+ ;;
65
+ register)
66
+ [[ $# == 6 && $2 =~ ^https://[a-zA-Z0-9.-]+(:[0-9]+)?$ && $3 =~ ^[a-z0-9][a-z0-9_-]{0,63}$ && $4 =~ ^[a-f0-9-]{36}$ && $5 =~ ^[a-f0-9]{64}$ ]] || fail "관리자 화면에서 발급한 등록 명령 전체를 다시 복사하세요."
67
+ check_worker_host
68
+ IFS= read -r code || fail "등록 코드가 없습니다. 관리자 화면에서 명령을 다시 복사하세요."
69
+ tls=()
70
+ if [[ -n $6 ]]; then printf '%s' "$6" | base64 -d > "$stage/ca.pem"; tls=(--cacert "$stage/ca.pem"); fi
71
+ url="$2/api/managed-agent/host-release?invite=$4&host=$3&sha256=$5"
72
+ status=$(printf '%s' "$code" | curl -q --proto '=https' --silent --show-error --connect-timeout 10 --max-time 120 "${tls[@]}" -H 'Content-Type: text/plain' --data-binary @- -o "$stage/archive" -w '%{http_code}' "$url") || fail "설치는 완료됐습니다. 이 서버에서 등록 주소의 네트워크 경로와 TLS 인증서를 확인한 뒤 등록만 재시도하세요."
73
+ [[ $status == 200 ]] || fail "JIGW 응답 HTTP $status. 401이면 등록 명령을 새로 발급하고, 404이면 화면에서 현재 배포본을 확인하세요."
74
+ printf '%s %s\n' "$5" "$stage/archive" | sha256sum -c || fail "배포본 해시 불일치. 관리자 화면에서 현재 등록 명령을 다시 받으세요."
75
+ dest="$root/release-$5"
76
+ if [[ ! -d $dest ]]; then mkdir "$stage/release"; tar --no-same-owner --no-same-permissions -xzf "$stage/archive" -C "$stage/release"; mv -T "$stage/release" "$dest" || [[ -d $dest ]]; fi
77
+ state="$root/enrollment-$4"
78
+ mkdir -p -m 700 -- "$state"
79
+ printf '%s\n' "$code" | /usr/bin/node "$dest/host/enroll.mjs" enroll --origin "$2" --host "$3" --invite "$4" --state-dir "$state/host-identity" --start-worker
80
+ ;;
81
+ *) fail "Run without arguments to install. Obtain the registration command from your administrator." ;;
82
+ esac
package/package.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "name": "@jigw/install",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-review.1",
4
+ "description": "JIGW agent server installer",
5
+ "os": ["linux"],
6
+ "bin": { "jigw-install": "install.sh" },
7
+ "files": ["install.sh"]
8
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.