-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·260 lines (218 loc) · 6.7 KB
/
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/bash
#
# Excellent Regards, the Alveare Solutions #!/Society -x
#
# Build WizZard
declare -a DEPENDENCIES
declare -a BUILD_DIRS
# Hot parameters
MODE='BUILD' # (SETUP | TEST | BUILD | INSTALL | CLEANUP)
BUILD='off'
INSTALL='off'
PUBLISH='off'
YES='off'
# Cold parameters
SCRIPT_NAME='Build WizZard'
VERSION='SpeedBall'
VERSION_NO='1.0'
DEPENDENCIES=('python3' 'python3-pip', 'python3-venv', 'steghide')
DISTRIBUTION_DIR='./dist'
VENV_DIR='./.venv'
CONF_DIR='./conf'
BATCH_DIR='./batch'
REQUIREMENTS_FILE='./requirements.txt'
PACKAGE_NAME='hipscipher'
BUILD_DIRS=('_build/' "${DISTRIBUTION_DIR}" "${PACKAGE_NAME}.egg-info/" "${PACKAGE_NAME}")
PARENT_DIR="$(basename "$(dirname "$(realpath ./setup.py)")")"
function format_banner() {
cat <<EOF
_____________________________________________________________________________
* * ${SCRIPT_NAME} * *
___________________________________________________v${VERSION_NO}${VERSION}_____________
Excellent Regards, the Alveare Solutions #!/Society -x
EOF
}
function display_usage() {
format_banner
cat <<EOF
[ Usage ]: ~$ $0 (BUILD | INSTALL)
-h | --help Display this message.
-s | --setup Install build dependencies.
-t | --test Run autotesters.
-c | --cleanup Cleanup project directory. Removes directories
| created during the build process, removes
| compiled python __pycache__'s, the mypy cahe
| and overwrites all log files with a timestamp.
-y | --yes Skips all user interactive prompts.
-r | --run Execute installed python package with no arguments.
[ Example ]: Install dependencies -
~$ sudo $0 --setup
[ Example ]: Run autotesters and check type hints in source files -
~$ $0 --test --cleanup -y
[ Example ]: Build the source and binary distributions -
~$ $0
~$ $0 BUILD
[ NOTE ]: Build is set as the default, so it doesn't need to be
specified unless this build wizzard script is modified.
[ Example ]: Build distributions and install source -
~$ $0 BUILD INSTALL
[ Example ]: Time saver -
~$ $0 --cleanup -y --setup --test BUILD INSTALL; $PACKAGE_NAME
EOF
}
# ACTIONS
function run() {
source ${VENV_DIR}/bin/activate
${PACKAGE_NAME}
return $?
}
function setup() {
echo "[ SETUP ]: Dependencies..."
local FAILURES=0
if [ $EUID -eq 0 ]; then
for package in "${DEPENDENCIES[@]}"; do
if ! apt-get install "${package}" -y $?; then
echo "[ NOK ]: Failed to install ${package}"
local FAILURES=$((FAILURES + 1))
fi
done
else
echo "[ WARNING ]: Superuser privileges not detected! Skipping system dependency installs."
fi
if [ ! -d "${VENV_DIR}" ] && ! python3 -m venv ${VENV_DIR}; then
echo "[ NOK ]: Failed to create virtual environment in (${VENV_DIR})"
local FAILURES=$((FAILURES + 1))
fi
if ! ${VENV_DIR}/bin/python3 -m pip install -i 'https://pypi.python.org/simple/' -r "${REQUIREMENTS_FILE}"; then
echo "[ NOK ]: Failed to install requirements file ${REQUIREMENTS_FILE}"
local FAILURES=$((FAILURES + 1))
fi
echo; return $FAILURES
}
function build() {
echo "[ BUILD ]: Source and binary distributions..."
local FAILURES=0
if ! mkdir ${PACKAGE_NAME} &> /dev/null; then
rm -rf ${PACKAGE_NAME} &> /dev/null
mkdir ${PACKAGE_NAME} &> /dev/null
fi
cp -r ./* ${PACKAGE_NAME} 2>/dev/null
if ! ${VENV_DIR}/bin/python3 setup.py sdist; then
local FAILURES=$((FAILURES + 1))
echo "[ NOK ]: Could not build project source distribution!"
fi
if [ $FAILURES -ne 0 ]; then
echo "[ NOK ]: Consumable artifact build terminated with (${FAILURES}) failures!"
else
echo "[ OK ]: Consumable artifact build!"
fi
echo; return $FAILURES
}
function install() {
echo "[ INSTALL ]: Source distribution archive..."
if ! ${VENV_DIR}/bin/python3 -m pip install -i 'https://pypi.python.org/simple/' $(find ./dist -type f -name '*.tar.gz'); then
echo "[ NOK ]: Failed to install source distribution package!"
return 1
else
echo "[ OK ]: Installed source distribution package!"
fi
echo; return 0
}
function cleanup() {
echo "[ CLEANING ]: Files, Directories and Installed Artifacts...
"
local FAILURES=0
echo "[ ... ]: Compiled Python __pycache__ directories"
if ! rm -rf $(find . -type d -name '__pycache__'); then
local FAILURES=$((FAILURES + 1))
fi
echo "[ ... ]: Python build directories"
if ! rm -rf "${BUILD_DIRS[@]}"; then
local FAILURES=$((FAILURES + 1))
fi
echo "[ ... ]: Package directory"
if ! rm -rf "${PACKAGE_NAME}"; then
local FAILURES=$((FAILURES + 1))
fi
echo "[ ... ]: Batch directory"
if ! rm -rf "${BATCH_DIR}"; then
local FAILURES=$((FAILURES + 1))
fi
echo "[ ... ]: Python package"
if [[ "${YES}" == 'on' ]]; then
${VENV_DIR}/bin/python3 -m pip uninstall "${PACKAGE_NAME}" -y
else
${VENV_DIR}/bin/python3 -m pip uninstall "${PACKAGE_NAME}"
fi
if [ $? -ne 0 ]; then
local FAILURES=$((FAILURES + 1))
fi
echo; return $FAILURES
}
# INIT
function init_build_wizzard() {
local EXIT_CODE=0
if [[ "$BUILD" == 'on' ]]; then
build
EXIT_CODE=$((EXIT_CODE + $?))
fi
if [[ "$INSTALL" == 'on' ]]; then
install
EXIT_CODE=$((EXIT_CODE + $?))
fi
return $EXIT_CODE
}
# MISCELLANEOUS
EXIT_CODE=0
for opt in "${@}"; do
case "$opt" in
-h | --help)
display_usage
exit 0
;;
-r | --run)
run
exit $?
;;
-y | --yes)
YES='on'
;;
esac
done
format_banner
for opt in "${@}"; do
case "$opt" in
-s | --setup)
MODE='SETUP'
setup
EXIT_CODE=$((EXIT_CODE + $?))
;;
-t | --test)
MODE='TEST'
${VENV_DIR}/bin/python3 -m pytest -v
EXIT_CODE=$((EXIT_CODE + $?))
;;
-c | --cleanup)
MODE='CLEANUP'
cleanup
EXIT_CODE=$((EXIT_CODE + $?))
;;
build | Build | BUILD)
MODE='BUILD'
BUILD='on'
;;
install | Install | INSTALL)
MODE='BUILD'
INSTALL='on'
;;
esac
done
# Defaul CLI call with no arguments
if [[ ${#@} -eq 0 ]]; then
BUILD='on'
fi
if [[ "${MODE}" == 'BUILD' ]]; then
init_build_wizzard
EXIT_CODE=$?
fi
exit $EXIT_CODE