forked from ikipro/aos
-
Notifications
You must be signed in to change notification settings - Fork 2
/
whonix_build
executable file
·125 lines (101 loc) · 3.87 KB
/
whonix_build
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
#!/bin/bash
## Copyright (C) 2012 - 2021 ENCRYPTED SUPPORT LP <[email protected]>
## See the file COPYING for copying conditions.
set -x
set -e
true "INFO: Currently running script: $BASH_SOURCE $@"
MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$MYDIR"
source ./help-steps/pre
source ./help-steps/colors
error_handler_whonix_build_one() {
true "${red}${bold}ERROR in $0${reset}"
true "${red}${bold}BASH_COMMAND${reset}: $BASH_COMMAND"
true "${red}${bold}whonix_build_one_build_step_current${reset}: $whonix_build_one_build_step_current"
true "${red}args: $args${reset}"
true "${red}${bold}INFO: Now exiting from $0 (because error was detected, see above).${reset}"
exit 1
}
trap "error_handler_whonix_build_one" ERR
export WHONIX_BUILD_ONE_SCRIPT_STARTED="1"
whonix_build_preparation() {
cd help-steps
source parse-cmd
whonix_build_one_parse_cmd "$@"
export whonix_build_one_parsed="1"
cd ..
}
whonix_build_machine() {
run-parts --verbose --test ./build-steps.d
## Not using:
#run-parts --verbose --exit-on-error ./build-steps.d
## Because of an issue,
## "run-parts, trap INT, read error":
## https://lists.gnu.org/archive/html/help-bash/2015-03/msg00066.html
for whonix_build_one_build_step_current in ./build-steps.d/*; do
if [ -x "$whonix_build_one_build_step_current" ]; then
## If the last character is a ~, ignore that file,
## because it was created by some editor,
## which creates backup files.
if [ "${whonix_build_one_build_step_current: -1}" = "~" ]; then
continue
fi
## Skipping files such as .dpkg-old and .dpkg-dist.
if ( echo "$whonix_build_one_build_step_current" | grep -q ".dpkg-" ); then
true "skip $whonix_build_one_build_step_current"
continue
fi
true "${cyan}${bold}${under}############################################################${reset}"
true "${cyan}${bold}${under}############################################################${reset}"
true "${cyan}${bold}${under}############################################################${reset}"
true "${cyan}${bold}${under}INFO: BEGIN: whonix_build_one_build_step_current: $whonix_build_one_build_step_current${reset}"
"./$whonix_build_one_build_step_current"
true "${cyan}${bold}${under}INFO: END : whonix_build_one_build_step_current: $whonix_build_one_build_step_current${reset}"
true "${cyan}${bold}${under}############################################################${reset}"
true "${cyan}${bold}${under}############################################################${reset}"
true "${cyan}${bold}${under}############################################################${reset}"
fi
done
}
whonix_build_clean() {
local cleaned_up
## Fallback
cleaned_up="false"
if [ "$WHONIX_BUILD_VIRTUALBOX" = "true" ]; then
cleaned_up="true"
./help-steps/delete-vbox-vm
fi
## TODO: WHONIX_BUILD_RAW
# if [ "$WHONIX_BUILD_RAW" = "true" ]; then
# cleaned_up="true"
# ./help-steps/delete-raw
# fi
if [ "$WHONIX_BUILD_QCOW2" = "true" ]; then
cleaned_up="true"
./help-steps/delete-qcow
fi
if [ "$ANON_BUILD_INSTALL_TO_ROOT" = "1" ]; then
error "${red}${bold}For --flavor root builds, --clean is not implemented.${reset}"
fi
if [ "$cleaned_up" = "false" ]; then
parse_cmd_target_error
fi
}
main() {
root_check
args=""$@""
whonix_build_preparation "$@"
## XXX
trap "error_handler_whonix_build_one" ERR
trap - INT
trap - TERM
if [ "$WHONIX_BUILD_CLEAN" = "1" ]; then
whonix_build_clean
elif [ "$WHONIX_BUILD_BUILD" = "1" ]; then
whonix_build_machine
else
true "${bold}${red}ERROR $BASH_SOURCE: You must either use --build or --clean. ${reset}"
exit 1
fi
}
main "$@"