Repository navigation
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·78 lines (73 loc) · 2.18 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·78 lines (73 loc) · 2.18 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
#!/usr/bin/env bash
set -euo pipefail
if repository_root=$(git rev-parse --show-toplevel 2>/dev/null); then
:
else
repository_root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
fi
nix_binary() {
if command -v nix >/dev/null 2>&1; then
command -v nix
elif [[ -x /nix/var/nix/profiles/default/bin/nix ]]; then
printf '%s\n' /nix/var/nix/profiles/default/bin/nix
else
printf 'bootstrap: Nix is required\n' >&2
exit 1
fi
}
run_in_shell() {
local nix_cmd
nix_cmd=$(nix_binary)
"$nix_cmd" develop "$repository_root" --command "$@"
}
case "${1:-shell}" in
shell)
exec "$(nix_binary)" develop "$repository_root"
;;
--pi)
shift
if [[ ${SDK_FACTORY_EVENT_STREAM:-0} == 1 ]]; then
run_in_shell node scripts/factory-tools/audit-pi.mjs --enforce-config >&2
run_in_shell node scripts/factory-tools/pi-package-cache.mjs >&2
else
run_in_shell node scripts/factory-tools/audit-pi.mjs --enforce-config
run_in_shell node scripts/factory-tools/pi-package-cache.mjs
fi
exec "$(nix_binary)" develop "$repository_root" --command pi "$@"
;;
--prepare-pi-cache)
shift
run_in_shell node scripts/factory-tools/pi-package-cache.mjs "$@"
;;
--audit-pi)
shift
run_in_shell node scripts/factory-tools/audit-pi.mjs "$@"
;;
--configure-pi)
shift
run_in_shell node scripts/factory-tools/pi-policy.mjs apply --execute "$@"
;;
--configure-git)
shift
run_in_shell node scripts/git-hooks/configure.mjs apply --execute "$@"
;;
--check)
shift
run_in_shell bash -c 'scripts/factory check && scripts/factory audit && node --test scripts/tests/factory-operations.mjs' bash "$@"
;;
--)
shift
(($# > 0)) || { printf 'bootstrap: command required after --\n' >&2; exit 2; }
exec "$(nix_binary)" develop "$repository_root" --command "$@"
;;
--help | -h)
printf '%s\n' \
'Usage: ./bootstrap.sh [shell|--pi|--prepare-pi-cache|--audit-pi|--configure-pi|--configure-git|--check|-- COMMAND]' \
'' \
'Configuration mutations are explicit. The default only enters the pinned Nix shell.'
;;
*)
printf 'bootstrap: unknown option: %s\n' "$1" >&2
exit 2
;;
esac