/
build-appbin-in-container.sh
executable file
·82 lines (67 loc) · 2.09 KB
/
build-appbin-in-container.sh
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
80
81
82
#!/bin/sh -eu
tag="${1?pass a verisigner-tag to build from (tkey-verification repo)}"
appsrepotag="${2?pass the tag in tillitis-key1-apps repo to use}"
cd "${0%/*}"
destd="internal/appbins/bins"
destf="$tag.bin"
if ! hash 2>/dev/stderr sha512sum; then
sha512sum() {
shasum -a 512 "$@"
}
fi
if [ -e "$destd/$destf" ]; then
cd "$destd"
printf "%s already exists.\n" "$destf"
if [ ! -e "$destf.sha512" ]; then
printf "%s is missing though\n" "$destf.sha512"
exit 1
fi
if [ ! -e "$destf.deps" ]; then
printf "Missing file %s while %s is present\n" "$destf.deps" "$destf.sha512"
exit 1
fi
printf "Going to verify hash.\n"
sha512sum -c "$destf.sha512"
exit $?
fi
foundappsrepotag=
if [ -e "$destd/$destf.deps" ]; then
printf "Found file %s\n" "$destf.deps"
if [ ! -e "$destd/$destf.sha512" ]; then
printf "Missing file %s while %s is present\n" "$destf.sha512" "$destf.deps"
exit 1
fi
foundappsrepotag="$(sed -n "s:^appsrepotag=\(.\{1,\}\)$:\1:p" "$destd/$destf.deps")"
if [ -z "$foundappsrepotag" ]; then
printf "No appsrepotag defined in %s\n" "$destf.deps"
exit 1
fi
appsrepotag="$foundappsrepotag"
fi
printf "Building verisigner from tag %s using apps-repo tag %s" "$tag" "$appsrepotag"
if [ -n "$foundappsrepotag" ]; then
printf " (found in .deps-file)"
fi
printf "\n"
cname="tkey-build"
podman run -it --name "$cname" \
--mount type=bind,source="$(pwd)",target=/contrib \
ghcr.io/tillitis/tkey-builder:2 \
/bin/bash /contrib/containerbuild "$tag" "$appsrepotag"
podman cp "$cname":/tkey-verification/apps/verisigner/app.bin "$destd/$destf"
podman >/dev/null rm "$cname"
printf "Built %s\n" "$destf"
cd "$destd"
if [ -z "$foundappsrepotag" ]; then
tagstr="$(printf 'appsrepotag=%s' "$appsrepotag")"
printf "Writing \`%s\` to new file %s\n" "$tagstr" "$destf.deps"
printf >"$destf.deps" "%s\n" "$tagstr"
fi
if [ ! -e "$destf.sha512" ]; then
printf "Hash file doesn't exist. Creating %s\n" "$destf.sha512"
sha512sum >"$destf.sha512" "$destf"
exit 0
fi
printf "Going to verify hash.\n"
sha512sum -c "$destf.sha512"
exit $?