|
1 |
| -#/bin/sh |
2 |
| - |
3 |
| -set -ex |
4 |
| - |
5 |
| -export WORK=`pwd` |
6 |
| - |
7 |
| -if [ -z "$CODESIGN_IDENTITY" ]; then |
8 |
| - export CODESIGN_IDENTITY="-" |
9 |
| -fi |
10 |
| - |
11 |
| -rm -rf ./out |
12 |
| -mkdir -p ./out |
13 |
| -export GOARCH=arm64 |
14 |
| -export GOOS=darwin |
15 |
| - |
16 |
| -# Gvp |
17 |
| -echo "Building gvp..." |
18 |
| -rm -rf gvisor-tap-vsock |
19 |
| -git clone https://github.com/containers/gvisor-tap-vsock.git |
20 |
| -cd gvisor-tap-vsock |
21 |
| -git checkout v0.8.1 |
22 |
| -eval "$(goenv init -)" |
23 |
| -goenv install 1.22.0 -s |
24 |
| -goenv shell 1.22.0 |
25 |
| -make gvproxy |
26 |
| -mv ./bin/gvproxy $WORK/out/gvproxy |
27 |
| - |
28 |
| -# krun |
29 |
| -echo "Dwonloading krun..." |
30 |
| -cd $WORK |
31 |
| -rm -rf ./krunkit |
32 |
| -mkdir -p krunkit |
33 |
| -cd krunkit |
34 |
| -gh release download v0.1.4 -R containers/krunkit --pattern "krunkit-*" --clobber |
35 |
| -tar -zxvf krunkit-*.tgz -C ./ |
36 |
| -mv bin/krunkit $WORK/out/krunkit |
37 |
| -mv lib/* $WORK/out/ |
38 |
| - |
39 |
| -cd $WORK |
40 |
| - |
41 |
| -# codesign |
42 |
| -echo "Signing gvproxy..." |
43 |
| -codesign --force --sign $CODESIGN_IDENTITY --options=runtime --timestamp $WORK/out/gvproxy |
44 |
| - |
45 |
| -echo "Signing krunkit..." |
46 |
| -codesign --force --sign $CODESIGN_IDENTITY --options=runtime --timestamp --entitlements krunkit.entitlements $WORK/out/krunkit |
47 |
| - |
48 |
| -find $WORK/out -name "*.dylib" -type f -exec sh -c "echo 'Set {} permission to 755'; chmod 755 {}" ';' |
49 |
| -find $WORK/out -name "*.dylib" -type f -exec sh -c "echo 'Signing {}...'; codesign --force --sign $CODESIGN_IDENTITY --options=runtime --timestamp {}" ';' |
50 |
| - |
51 |
| -# pack |
52 |
| -echo "Packing..." |
53 |
| -cd $WORK/out |
54 |
| -tar --no-mac-metadata -czvf ./libexec-$GOOS-$GOARCH.tar.gz . |
55 |
| - |
56 |
| -# generate sha256 |
57 |
| -cd $WORK/out |
58 |
| -echo "Generating sha256..." |
59 |
| -shasum -a 256 ./* > sha256.txt |
60 |
| -cat ./sha256.txt |
| 1 | +#! /usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +_get_krunkit() { |
| 6 | + cd "$workspace" |
| 7 | + mkdir -p "$workspace/krunkit_temp" |
| 8 | + cd "$workspace/krunkit_temp" |
| 9 | + gh release download v0.1.4 -R containers/krunkit --pattern "krunkit-*" --clobber |
| 10 | + tar -zxvf krunkit-*.tgz -C ./ |
| 11 | + mv bin/* lib/* "$workspace/out" |
| 12 | + cd "$workspace" |
| 13 | +} |
| 14 | + |
| 15 | +_build_vfkit() { |
| 16 | + cd "$workspace" |
| 17 | + v_tag="v0.6.0" |
| 18 | + rm -rf ./vfkit_temp |
| 19 | + git clone https://github.com/crc-org/vfkit vfkit_temp |
| 20 | + cd ./vfkit_temp |
| 21 | + git checkout $v_tag |
| 22 | + make out/vfkit-amd64 |
| 23 | + mv ./out/vfkit-amd64 "$workspace/out/vfkit" |
| 24 | + cd "$workspace" |
| 25 | +} |
| 26 | + |
| 27 | +_build_gvproxy() { |
| 28 | + cd "$workspace" |
| 29 | + rm -rf gvisor-tap-vsock_temp |
| 30 | + git clone https://github.com/containers/gvisor-tap-vsock.git ./gvisor-tap-vsock_temp |
| 31 | + cd ./gvisor-tap-vsock_temp |
| 32 | + git checkout v0.8.1 |
| 33 | + make gvproxy |
| 34 | + mv ./bin/gvproxy "$workspace/out/gvproxy" |
| 35 | + cd "$workspace" |
| 36 | +} |
| 37 | + |
| 38 | +_pack_output() { |
| 39 | + cd "$workspace/out" |
| 40 | + tar --no-mac-metadata -zcvf "$workspace/libexec-$GOOS-$GOARCH.tar.gz" . |
| 41 | + cd "$workspace" |
| 42 | +} |
| 43 | + |
| 44 | +_do_codesign() { |
| 45 | + if [[ -z "$CODESIGN_IDENTITY" ]]; then |
| 46 | + CODESIGN_IDENTITY="-" |
| 47 | + fi |
| 48 | + |
| 49 | + test -f "$workspace/out/gvproxy" && { |
| 50 | + echo "Signing gvproxy..." |
| 51 | + codesign --force --sign "$CODESIGN_IDENTITY" --options=runtime --timestamp "$workspace/out/gvproxy" |
| 52 | + } |
| 53 | + |
| 54 | + test -f "$workspace/out/vfkit" && { |
| 55 | + echo "Signing vfkit..." |
| 56 | + codesign --force --sign "$CODESIGN_IDENTITY" --options=runtime --timestamp --entitlements "$workspace/vf.entitlements" "$workspace/out/vfkit" |
| 57 | + } |
| 58 | + |
| 59 | + test -f "$workspace/out/krunkit" && { |
| 60 | + echo "Signing krunkit..." |
| 61 | + codesign --force --sign "$CODESIGN_IDENTITY" --options=runtime --timestamp --entitlements "$workspace/krunkit.entitlements" "$workspace/out/krunkit" |
| 62 | + } |
| 63 | + |
| 64 | + find "$workspace/out" -name "*.dylib" -type f -exec sh -c "echo 'Set {} permission to 755'; chmod 755 {}" ';' |
| 65 | + find "$workspace/out" -name "*.dylib" -type f -exec sh -c "echo 'Signing {}...'; codesign --force --sign $CODESIGN_IDENTITY --options=runtime --timestamp {}" ';' |
| 66 | +} |
| 67 | + |
| 68 | +build_darwin_arm64() { |
| 69 | + export GOOS=darwin |
| 70 | + export GOARCH=arm64 |
| 71 | + |
| 72 | + echo "Build gvproxy" |
| 73 | + _build_gvproxy |
| 74 | + |
| 75 | + echo "Download krunkit" |
| 76 | + _get_krunkit |
| 77 | + |
| 78 | + echo "Do codesign" |
| 79 | + _do_codesign |
| 80 | + |
| 81 | + echo "Packup output" |
| 82 | + _pack_output |
| 83 | +} |
| 84 | + |
| 85 | +build_darwin_amd64() { |
| 86 | + export GOOS=darwin |
| 87 | + export GOARCH=amd64 |
| 88 | + |
| 89 | + echo "Build gvproxy" |
| 90 | + _build_gvproxy |
| 91 | + |
| 92 | + echo "Build vfkit" |
| 93 | + _build_vfkit |
| 94 | + |
| 95 | + echo "Do codesign" |
| 96 | + _do_codesign |
| 97 | + |
| 98 | + echo "Packup output" |
| 99 | + _pack_output |
| 100 | +} |
| 101 | + |
| 102 | +main() { |
| 103 | + target_arch=$1 |
| 104 | + workspace="$(pwd)" |
| 105 | + if [[ -z $target_arch ]]; then |
| 106 | + echo "Error: missing target" |
| 107 | + exit 2 |
| 108 | + fi |
| 109 | + |
| 110 | + # Clean out dir first |
| 111 | + rm -rf "$workspace/out" |
| 112 | + mkdir -p "$workspace/out" |
| 113 | + |
| 114 | + if [[ $target_arch == arm64 ]]; then |
| 115 | + echo "Building binaries for darwin arm64" |
| 116 | + build_darwin_arm64 |
| 117 | + elif [[ $target_arch == amd64 ]]; then |
| 118 | + echo "Building binaries for darwin amd64" |
| 119 | + build_darwin_amd64 |
| 120 | + else |
| 121 | + echo "Not support targer $target_arch" |
| 122 | + exit 2 |
| 123 | + fi |
| 124 | +} |
| 125 | + |
| 126 | +main "$@" |
0 commit comments