forked from forknote/cryptonote-generator
-
Notifications
You must be signed in to change notification settings - Fork 7
/
generator.sh
executable file
·113 lines (90 loc) · 2.84 KB
/
generator.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
#! /usr/bin/env bash
# Bash script for automatic generation and deployment
# Exit immediately if an error occurs, or if an undeclared variable is used
set -o errexit
set -o nounset
[ "$OSTYPE" != "win"* ] || die "Install Cygwin to use on Windows"
# Set directory vars
. "vars.cfg"
# Perform cleanup on exit
function finish {
# Remove temporary files if exist
echo "Remove temporary files..."
rm -f "${UPDATES_PATH}"
rm -rf "${TEMP_PATH}"
}
trap finish EXIT
# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} [-h] [-f FILE] [-c <string>]
Reads a config file and creates and compiles Cryptonote coin. "config.json" as default
-h display this help and exit
-f config file
-c compile arguments
EOF
}
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize our own variables:
CONFIG_FILE='config.json'
COMPILE_ARGS='--jobs=3'
while getopts "h?f:c:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
f) CONFIG_FILE=${OPTARG}
;;
c) COMPILE_ARGS+=${OPTARG}
;;
esac
done
shift $((OPTIND-1))
# Setting config file
if [[ "${CONFIG_FILE}" != /* ]]; then
CONFIG_FILE="${CONFIG_PATH}/${CONFIG_FILE}"
fi
if [ ! -f ${CONFIG_FILE} ]; then
echo "ERROR: config file does not exits"
exit
fi
NEW_COIN_NAME=`grep -E "CRYPTONOTE_NAME" ${CONFIG_FILE} | grep -E -o ':\"[^\"]+\"' | grep -E -o "[a-zA-Z0-9]+"`
NEW_COIN_PATH="${WORK_FOLDERS_PATH}/${NEW_COIN_NAME}"
echo $NEW_COIN_PATH
if [ -d "${BASE_COIN_PATH}" ]; then
echo "Updating CryptoNote starter..."
git pull
else
echo "Cloning CryptoNote starter..."
git clone https://github.com/cryptonotefoundation/cryptonote.git "${BASE_COIN_PATH}"
fi
echo "Make temporary base coin copy..."
[ -d "${TEMP_PATH}" ] || mkdir -p "${TEMP_PATH}"
cp -af "${BASE_COIN_PATH}/." "${TEMP_PATH}"
# Plugins
echo "Personalize base coin source..."
python "${SCRIPTS_PATH}/plugins/core/bytecoin.py" --config=$CONFIG_FILE --source=${TEMP_PATH}
# Tests
bash "${SCRIPTS_PATH}/plugins/tests/core/bytecoin-test.sh" $CONFIG_FILE
if [[ $? != 0 ]]; then
echo "A test failed. Generation will not continue"
exit 1
fi
echo "Tests passed successfully"
[ -d "${NEW_COIN_PATH}" ] || mkdir -p "${NEW_COIN_PATH}"
echo "Create patch"
cd ${WORK_FOLDERS_PATH};
EXCLUDE_FROM_DIFF="-x '.git'"
if [ -d "${BASE_COIN_PATH}/build" ]; then
EXCLUDE_FROM_DIFF="${EXCLUDE_FROM_DIFF} -x 'build'"
fi
diff -Naur -x .git ${NEW_COIN_PATH##${WORK_FOLDERS_PATH}/} ${TEMP_PATH##${WORK_FOLDERS_PATH}/} > "${UPDATES_PATH}" || [ $? -eq 1 ]
echo "Apply patch"
[ -d "${NEW_COIN_PATH}" ] || mkdir -p "${NEW_COIN_PATH}"
if [ ! -z "${UPDATES_PATH}" ]; then
# Generate new coin
cd "${NEW_COIN_PATH}" && patch -s -p1 < "${UPDATES_PATH}" && cd "${SCRIPTS_PATH}"
bash "${SCRIPTS_PATH}/compile.sh" -f $CONFIG_FILE -c $COMPILE_ARGS -p ${NEW_COIN_PATH}
fi