forked from Xandyhoss/blockbank-cc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateTar.sh
executable file
·78 lines (68 loc) · 2.22 KB
/
generateTar.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
#!/usr/bin/bash
# Default values for the flags
FLAG_CCAPI="none"
FLAG_LABEL="1.0"
# You can change this if you want to avoid using the --name flag
FLAG_NAME="cc-tools-demo"
# Process command-line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--ccapi | -c)
FLAG_CCAPI="go"
shift 1
;;
--label | -l)
if [[ $# -gt 1 ]]; then
FLAG_LABEL=$2
shift 2
else
echo "Error: --label flag requires a value."
exit 1
fi
;;
--name | -n)
if [[ $# -gt 1 ]]; then
FLAG_NAME=$2
shift 2
else
echo "Error: --name flag requires a value."
exit 1
fi
;;
--help | -h)
echo "Usage: ./generateTar.sh [--ccapi] [--label <label>] [--name <name>]"
echo " --ccapi, -c: Include rest-server in the tar file. Default is no ccapi."
echo " --help , -h: Show this help message."
echo " --label, -l: Label to be used for the chaincode package. Default is 1.0."
echo " --name , -n: Name of the chaincode package. Default is ${FLAG_NAME}."
exit 0
;;
*)
# Ignore unrecognized arguments
shift
;;
esac
done
# Remove previous tar file
rm -f ${FLAG_NAME}.tar.gz
# Make sure go mod is up to date
cd chaincode && go mod vendor && cd ..
# Pack chaincode
export FABRIC_CFG_PATH=fabric/config
peer lifecycle chaincode package chaincode.tar.gz --path chaincode --lang golang --label ${FLAG_NAME}_${FLAG_LABEL}
case $FLAG_CCAPI in
go)
# Create temporary directory for rest-server
mkdir -p tmp/rest-server
cp -r ccapi/* tmp/rest-server
# Compress file with rest-server (GoFabric will use the one provided)
tar -c --exclude=vendor -zf ${FLAG_NAME}.tar.gz chaincode.tar.gz -C tmp rest-server
;;
none)
# Compress file without rest-server (GoFabric will use the standard CC API)
tar -czf ${FLAG_NAME}.tar.gz chaincode.tar.gz
esac
# Remove chaincode.tar.gz
rm -f chaincode.tar.gz
# Remove temporary directory
rm -rf tmp