-
Notifications
You must be signed in to change notification settings - Fork 606
Expand file tree
/
Copy pathbuild-safe.sh
More file actions
executable file
·79 lines (66 loc) · 1.68 KB
/
build-safe.sh
File metadata and controls
executable file
·79 lines (66 loc) · 1.68 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
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
usage() {
cat >&2 <<'USAGE'
Usage: ./build-safe.sh <profile.yaml> [-o output]
Examples:
./build-safe.sh safety-profiles/readonly.yaml
./build-safe.sh safety-profiles/agent-safe.yaml -o /usr/local/bin/gog-safe
USAGE
}
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
if [[ -z "${1:-}" || "${1:-}" == -* ]]; then
usage
exit 2
fi
PROFILE="$1"
shift
OUTPUT="bin/gog-safe"
while [[ $# -gt 0 ]]; do
case "$1" in
-o|--output)
if [[ -z "${2:-}" ]]; then
echo "error: $1 requires a path" >&2
exit 2
fi
OUTPUT="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "error: unknown flag: $1" >&2
usage
exit 2
;;
esac
done
if [[ ! -f "$PROFILE" ]]; then
echo "error: profile not found: $PROFILE" >&2
exit 1
fi
GEN_FILE="internal/cmd/safety_profile_baked_gen.go"
cleanup() {
rm -f "$GEN_FILE"
}
trap cleanup EXIT
cleanup
go run ./cmd/bake-safety-profile "$PROFILE" "$GEN_FILE"
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT=$(git rev-parse --short=12 HEAD 2>/dev/null || echo "")
DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS="-X github.com/steipete/gogcli/internal/cmd.version=${VERSION}-safe -X github.com/steipete/gogcli/internal/cmd.commit=${COMMIT} -X github.com/steipete/gogcli/internal/cmd.date=${DATE}"
mkdir -p "$(dirname "$OUTPUT")"
go build -tags safety_profile -ldflags "$LDFLAGS" -o "$OUTPUT" ./cmd/gog
RUN_OUTPUT="$OUTPUT"
if [[ "$RUN_OUTPUT" != */* ]]; then
RUN_OUTPUT="./$RUN_OUTPUT"
fi
"$RUN_OUTPUT" --version
echo "built $OUTPUT with baked safety profile $PROFILE"