-
Notifications
You must be signed in to change notification settings - Fork 7
/
btcpay-build.sh
executable file
·186 lines (169 loc) · 4.84 KB
/
btcpay-build.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
set -e
HELP=true
DEPLOY=false
BUILD=false
UPDATE=false
DEPLOY_ON=""
BOARD=""
PROD=false
while (( "$#" )); do
case "$1" in
deploy)
HELP=false
DEPLOY=true
shift 1
;;
build)
BUILD=true
HELP=false
shift 1
;;
update)
BUILD=true
UPDATE=true
HELP=false
shift 1
;;
--production)
PROD=true
shift 1
;;
--help)
HELP=true
shift 1
;;
--deploy-on)
DEPLOY_ON="$2"
shift 2
;;
--board)
BOARD="$2"
shift 2
;;
--) # end argument parsing
shift
break
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
if $HELP; then cat <<-END
Usage:
------
Build, update or deploy the armbian image
build: Build the kernel, u-boot and create the hack0 image
update: Create the hack0 image without rebuilding the kernel and u-book
deploy: Deploy the last built image on the --deploy-device
--deploy-on /dev/sda: Flash the image on the device /dev/sda
--board rock64: Create an image for rock64 (Available: rockpro64, rock64)
--production: Create a production image (will ignore build-local.conf)
--help: Show this help
END
fi
if $BUILD; then
if ! [[ "$BOARD" ]]; then
echo "The board should be specified with --board (See --help)"
exit 1
fi
BUILD_ARGS="
BOARD=${BOARD}
BUILD_ONLY=no
KERNEL_CONFIGURE=no
RELEASE=jammy
BRANCH=current
BUILD_DESKTOP=no
WIREGUARD=no
BUILD_MINIMAL=yes
FORCE_USE_RAMDISK=no
KERNEL_GIT=shallow"
if $UPDATE; then
BUILD_ARGS="
${BUILD_ARGS}
CLEAN_LEVEL=oldcache
PROGRESS_LOG_TO_FILE=yes"
fi
pushd . 2>/dev/null
rm -f "userpatches/config-docker.conf" "userpatches/Dockerfile"
cd "userpatches/overlay"
OVERLAY_DIRECTORY="$(pwd)"
cd "$OVERLAY_DIRECTORY"
source build.conf
if $PROD; then
touch .production
echo "Building production image..."
else
echo "Building debug image..."
rm -rf .production
[ -f "build-local.conf" ] && source build-local.conf && echo "build-local.conf loaded"
fi
! [ -d "btcpayserver-docker" ] && git clone "$BTCPAY_REPOSITORY"
cd btcpayserver-docker
git checkout "$BTCPAY_BRANCH"
git fetch origin
if ! git diff --quiet remotes/origin/HEAD || ! [ -f ../docker-images.tar ]; then
git pull
rm -f ../docker-images.tar
. ./build.sh -i
cd Generated
export BTCPAY_DOCKER_PULL_FLAGS="--platform arm64"
# https://github.com/docker/docker-ce/blob/master/components/cli/experimental/README.md
# Edit /etc/docker/daemon.json with "experimental": true
./pull-images.sh
./save-images.sh ../../docker-images.tar
# Do not mess up the build environment
export BTCPAY_DOCKER_PULL_FLAGS=""
./pull-images.sh
else
echo "docker-images.tar is up to date"
fi
cd "$OVERLAY_DIRECTORY"
if ! [ -f "utxo-snapshot-bitcoin-mainnet-820852.tar" ]; then
set +e
rm utxo-snapshot-*.tar &> /dev/null
set -e
wget "https://eu2.contabostorage.com/1f50a74c9dc14888a8664415dad3d020:utxosets/utxo-snapshot-bitcoin-mainnet-820852.tar" -c -q --show-progress
fi
popd
# Make sure built images are deleted
mkdir -p output/images
rm -rf output/images
# WSL2 include some windows path in PATH, making the build fail. This remove those.
export PATH=$(/usr/bin/printenv PATH | /usr/bin/perl -ne 'print join(":", grep { !/\/mnt\/[a-z]/ } split(/:/));')
time ./compile.sh ${BUILD_ARGS}
fi
if $DEPLOY; then
IMAGE="$(echo output/images/*.img)"
IMAGE_SHA="$(echo output/images/*.img.sha)"
if ! [[ "$IMAGE" ]] || ! [ -f "$IMAGE" ]; then
echo "No image were found in output/images"
exit 1
fi
if ! [[ "$DEPLOY_ON" ]]; then
echo "The deployment device target should be specified with --deploy-on (See --help)"
exit 1
fi
if ! lsblk "$DEPLOY_ON" 2>/dev/null; then
echo "Device $DEPLOY_ON is not available"
exit 1
fi
echo "Writing image" "$DEPLOY_ON" "info"
ifsha=$(cat $IMAGE_SHA | awk '{print $1}')
[[ -x "$(command -v pv)" ]] || apt-get install -y pv
pv -p -b -r -c -N "[ .... ] dd" $IMAGE | dd of=$DEPLOY_ON bs=1M iflag=fullblock oflag=direct status=none
echo "Verifying. Please wait!"
ofsha=$(dd if=$DEPLOY_ON count=$(du -b $IMAGE | cut -f1) status=none iflag=count_bytes oflag=direct | sha256sum | awk '{print $1}')
if [[ $ifsha == $ofsha ]]; then
echo "Writing succeeded" "$IMAGE" "info"
else
echo "Writing failed" "$IMAGE" "err"
exit 1
fi
fi