-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild-dist
executable file
·99 lines (80 loc) · 3.3 KB
/
build-dist
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
#!/bin/bash
pushd $(dirname $0) > /dev/null
ROOT_DIR=$(pwd)
if [[ $# -lt 6 ]]; then
echo "Usage: $0 <destination path> <checkpoint> <minimum difficulty> <network> <ui_iteration> <ui_authorizers>"
exit 1
fi
# Check docker images exist
CHECK_IMAGE=$ROOT_DIR/docker/check-image
for img in hsm:ledger hsm:mware hsm:packer; do
DOCKER_IMAGE=$img
source $CHECK_IMAGE
done
DEST_DIR=$1
CHECKPOINT=$2
DIFFICULTY=$3
NETWORK=$4
UI_ITERATION=$5
UI_AUTHORIZERS=$6
FIRMWARE_DIR=$DEST_DIR/firmware
BIN_DIR=$DEST_DIR/bin
SCRIPTS_DIR=$DEST_DIR/scripts
if [[ -e $DEST_DIR ]]; then
echo -e "\e[31mDestination directory $DEST_DIR exists"
exit 1
fi
echo -e "\e[32mBuilding into \e[93m$DEST_DIR\e[32m with checkpoint \e[93m$CHECKPOINT\e[32m, minimum difficulty \e[93m$DIFFICULTY\e[32m, network \e[93m$NETWORK\e[32m and UI iteration \e[93m$UI_ITERATION\e[32m...\e[0m"
echo -e "\e[33mCopying files and creating directories...\e[0m"
rm -rf $DEST_DIR
cp -Rf $ROOT_DIR/dist $DEST_DIR
rm -rf $FIRMWARE_DIR
mkdir -p $FIRMWARE_DIR
rm -rf $BIN_DIR
mkdir -p $BIN_DIR
rm -f $DEST_DIR/pin.txt
rm -f $DEST_DIR/public-keys.txt $DEST_DIR/public-keys.json
rm -f $DEST_DIR/attestation.json $DEST_DIR/device_attestation.json
echo
echo -e "\e[33mBuilding middleware...\e[0m"
$ROOT_DIR/middleware/build/dist
cp $ROOT_DIR/middleware/bin/adm.tgz $BIN_DIR
cp $ROOT_DIR/middleware/bin/lbutils.tgz $BIN_DIR
cp $ROOT_DIR/middleware/bin/manager.tgz $BIN_DIR
cp $ROOT_DIR/middleware/bin/signapp.tgz $BIN_DIR
echo
computeHash() {
APP_HASH=$($ROOT_DIR/docker/mware/do-notty-nousb /hsm2 "python middleware/signapp.py hash -a $HEX_PATH" | \
grep "Computed hash:" | \
sed "s/Computed hash: //g")
printf "\e[33m$HEX_NAME hash: $APP_HASH\e[93m"
echo -e "\e[0m"
}
echo -e "\e[33mBuilding signer...\e[0m"
$ROOT_DIR/firmware/build/build-ledger-signer $CHECKPOINT $DIFFICULTY $NETWORK > /dev/null
cp $ROOT_DIR/firmware/src/ledger/signer/bin/app.hex $FIRMWARE_DIR/signer.hex
cp $ROOT_DIR/firmware/src/ledger/signer/icon.hex $FIRMWARE_DIR/signer.icon.hex
HEX_NAME="Signer"
HEX_PATH="firmware/src/ledger/signer/bin/app.hex"
computeHash
SIGNER_HASH=$APP_HASH
echo -e "\e[33mBuilding UI...\e[0m"
$ROOT_DIR/firmware/build/build-ledger-ui $SIGNER_HASH $UI_ITERATION $UI_AUTHORIZERS > /dev/null
cp $ROOT_DIR/firmware/src/ledger/ui/bin/token.hex $FIRMWARE_DIR/ui.hex
cp $ROOT_DIR/firmware/src/ledger/ui/icon.hex $FIRMWARE_DIR/ui.icon.hex
HEX_NAME="UI"
HEX_PATH="firmware/src/ledger/ui/bin/token.hex"
CA_FILE="rsk-ca.txt"
computeHash
echo -e "\e[33mSigning apps...\e[0m"
$ROOT_DIR/docker/mware/do-notty-nousb /hsm2 "python middleware/signonetime.py -a firmware/src/ledger/ui/bin/token.hex,firmware/src/ledger/signer/bin/app.hex -p $CA_FILE" > /dev/null
mv -f $ROOT_DIR/firmware/src/ledger/ui/bin/token.hex.sig $FIRMWARE_DIR/ui.hex.sig
mv -f $ROOT_DIR/firmware/src/ledger/signer/bin/app.hex.sig $FIRMWARE_DIR/signer.hex.sig
mv -f $ROOT_DIR/$CA_FILE $SCRIPTS_DIR/$CA_FILE
SIGNER_AUTH_FILE="signer_auth.json"
echo -e "\e[33mCreating empty signer authorization for upgrades...\e[0m"
$ROOT_DIR/docker/mware/do-notty-nousb /hsm2 "python middleware/signapp.py message -a firmware/src/ledger/signer/bin/app.hex -i $UI_ITERATION -o $SIGNER_AUTH_FILE" > /dev/null
mv -f $ROOT_DIR/$SIGNER_AUTH_FILE $FIRMWARE_DIR/$SIGNER_AUTH_FILE
echo
echo -e "\e[32mBuild complete.\e[0m"
popd > /dev/null