forked from forknote/cryptonote-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.sh
141 lines (115 loc) · 3.58 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
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
#! /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
[ "$OSTYPE" != "win"* ] || die "Install MinGW to use on Windows"
# For bold text
if [ "$OSTYPE" != "msys" ]; then
bold=$(tput bold)
normal=$(tput sgr0)
fi
# 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 -f "${BASH_CONFIG}"
rm -rf "${TEMP_PATH}"
}
trap finish EXIT
# Generate source code and compile
function generate_coin {
# Define coin paths
export BASE_COIN_PATH="${WORK_FOLDERS_PATH}/${__CONFIG_base_coin_name}"
export NEW_COIN_PATH="${WORK_FOLDERS_PATH}/${__CONFIG_core_CRYPTONOTE_NAME}"
if [ -d "${BASE_COIN_PATH}" ]; then
cd "${BASE_COIN_PATH}"
echo "Updating ${__CONFIG_base_coin_name}..."
git pull
cd "${PROJECT_DIR}"
else
echo "Cloning ${__CONFIG_base_coin_name}..."
git clone "${__CONFIG_base_coin_git}" "${BASE_COIN_PATH}"
fi
# Exit if base coin does not exists
if [ ! -d "${BASE_COIN_PATH}" ]; then
echo "Base coin does not exists"
echo "Abort clone generation"
exit 4
fi
echo "Make temporary ${__CONFIG_base_coin_name} copy..."
[ -d "${TEMP_PATH}" ] || mkdir -p "${TEMP_PATH}"
cp -af "${BASE_COIN_PATH}/." "${TEMP_PATH}"
# Extensions
echo "Personalize base coin source..."
export __CONFIG_extensions_text="${__CONFIG_extensions[@]}"
for extension in "${__CONFIG_extensions[@]}"
do
echo "${bold}Execute ${EXTENSIONS_PATH}/${extension}${normal}"
python "lib/file-modification.py" --extension "${EXTENSIONS_PATH}/${extension}" --config=$CONFIG_FILE --source=${TEMP_PATH}
done
[ -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}"
chmod -R 755 ${NEW_COIN_PATH}
bash "${SCRIPTS_PATH}/compile.sh" -c "${COMPILE_ARGS}" -z
fi
}
# 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=''
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
[ -d "${WORK_FOLDERS_PATH}" ] || mkdir -p "${WORK_FOLDERS_PATH}"
# Get environment environment_variables
python "lib/environment_variables.py" --config=$CONFIG_FILE --output=$BASH_CONFIG
if [ ! -f ${BASH_CONFIG} ]; then
echo "Config file was not translated to bash."
echo "Abort coin generation"
exit 3
fi
source ${BASH_CONFIG}
generate_coin