Skip to content

Commit abf2409

Browse files
committed
ci: install jq on arch bootstrap and keep bootstrap cli self-contained
1 parent 498fd60 commit abf2409

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

bin/baudbot

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,30 @@ if [ -z "${BAUDBOT_ROOT:-}" ]; then
1818
# Handle relative symlinks
1919
[[ "$SCRIPT" != /* ]] && SCRIPT="$DIR/$SCRIPT"
2020
done
21-
BAUDBOT_ROOT="$(cd "$(dirname "$SCRIPT")/.." && pwd)"
21+
22+
CANDIDATE_ROOT="$(cd "$(dirname "$SCRIPT")/.." && pwd)"
23+
if [ -f "$CANDIDATE_ROOT/bin/baudbot" ] && [ -f "$CANDIDATE_ROOT/package.json" ]; then
24+
BAUDBOT_ROOT="$CANDIDATE_ROOT"
25+
elif [ -d /opt/baudbot/current/bin ]; then
26+
BAUDBOT_ROOT="$(readlink -f /opt/baudbot/current 2>/dev/null || echo /opt/baudbot/current)"
27+
else
28+
BAUDBOT_ROOT="$CANDIDATE_ROOT"
29+
fi
2230
fi
2331

24-
# shellcheck source=bin/lib/json-common.sh
25-
source "$BAUDBOT_ROOT/bin/lib/json-common.sh"
32+
json_get_string_or_empty() {
33+
local file="$1"
34+
local key="$2"
35+
[ -r "$file" ] || return 0
36+
command -v jq >/dev/null 2>&1 || return 0
37+
jq -er --arg k "$key" 'if (type == "object") and has($k) and (.[$k] | type == "string") then .[$k] else empty end' "$file" 2>/dev/null || true
38+
}
39+
40+
json_get_string_stdin_or_empty() {
41+
local key="$1"
42+
command -v jq >/dev/null 2>&1 || return 0
43+
jq -er --arg k "$key" 'if (type == "object") and has($k) and (.[$k] | type == "string") then .[$k] else empty end' 2>/dev/null || true
44+
}
2645

2746
# Colors (disabled if not a terminal)
2847
if [ -t 1 ]; then
@@ -301,10 +320,10 @@ print_deployed_version() {
301320
branch="$(json_get_string_or_empty "$version_file" "branch")"
302321
deployed_at="$(json_get_string_or_empty "$version_file" "deployed_at")"
303322
elif [ "$(id -u)" -eq 0 ] && id "$agent_user" >/dev/null 2>&1; then
304-
short="$(sudo -u "$agent_user" sh -c "cat '$version_file' 2>/dev/null" | json_get_string_stdin "short" 2>/dev/null || true)"
305-
sha="$(sudo -u "$agent_user" sh -c "cat '$version_file' 2>/dev/null" | json_get_string_stdin "sha" 2>/dev/null || true)"
306-
branch="$(sudo -u "$agent_user" sh -c "cat '$version_file' 2>/dev/null" | json_get_string_stdin "branch" 2>/dev/null || true)"
307-
deployed_at="$(sudo -u "$agent_user" sh -c "cat '$version_file' 2>/dev/null" | json_get_string_stdin "deployed_at" 2>/dev/null || true)"
323+
short="$(sudo -u "$agent_user" sh -c "cat '$version_file' 2>/dev/null" | json_get_string_stdin_or_empty "short" 2>/dev/null || true)"
324+
sha="$(sudo -u "$agent_user" sh -c "cat '$version_file' 2>/dev/null" | json_get_string_stdin_or_empty "sha" 2>/dev/null || true)"
325+
branch="$(sudo -u "$agent_user" sh -c "cat '$version_file' 2>/dev/null" | json_get_string_stdin_or_empty "branch" 2>/dev/null || true)"
326+
deployed_at="$(sudo -u "$agent_user" sh -c "cat '$version_file' 2>/dev/null" | json_get_string_stdin_or_empty "deployed_at" 2>/dev/null || true)"
308327
fi
309328

310329
if [ -z "$short" ] && [ -z "$sha" ] && [ -z "$branch" ] && [ -z "$deployed_at" ]; then

bin/ci/setup-arch.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
set -euo pipefail
99

10-
echo "=== [Arch] Installing git (needed to init test repo) ==="
11-
pacman -Sy --noconfirm --needed git sudo 2>&1 | tail -3
10+
echo "=== [Arch] Installing base CI deps ==="
11+
pacman -Sy --noconfirm --needed git jq sudo 2>&1 | tail -3
1212

1313
echo "=== Preparing source ==="
1414
useradd -m -s /bin/bash baudbot_admin

0 commit comments

Comments
 (0)