-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.cc.wallet.sh
More file actions
228 lines (185 loc) · 10.2 KB
/
setup.cc.wallet.sh
File metadata and controls
228 lines (185 loc) · 10.2 KB
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
#!/bin/bash
# include tools
source "./src/tools.sh" || exit 1
# default arguments
cc_script_cfg_path_default="./src/cfg.cc.blocknet.sh"
cc_action1_default="build"
cc_action2_default="install"
cc_firejail_default="firejail"
cc_proxychains_default="proxychains4 -q"
# include specific tools
source "./src/tools.cc.wallet.sh" || exit 1
# showhelp is auto set by tools
tool_wallet_show_help
# handle arguments
cc_script_cfg_path=
cc_action1=
cc_action2=
cc_firejail=${cc_firejail_default}
cc_proxychains=${cc_proxychains_default}
cc_install_dir_path=
# process command line arguments
argc=$#
argv=("$@")
tool_wallet_process_arguments ${argc} ${argv}
# start measuring time
tool_time_start
tool_variable_info cc_firejail
tool_variable_info cc_proxychains
# check make script exist
cc_script_make_path="./src/setup.cc.make.sh"
tool_realpath cc_script_make_path "make script path"
tool_file_if_notexist_exit ${cc_script_make_path} "make script path"
# check download script exist
cc_script_download_path="./src/setup.download.extract.sh"
tool_realpath cc_script_download_path "download script path"
tool_file_if_notexist_exit ${cc_script_download_path} "download script path"
# include main cc cfg script IE: ./src/cfg.cc.blocknet.sh
tool_variable_check_load_default cc_script_cfg_path cc_script_cfg_path_default
tool_realpath cc_script_cfg_path "parameter #1 cc cfg script path"
tool_check_version_and_include_script ${cc_script_cfg_path} "loading cc cfg script"
# check included cfg variables
tool_variable_check_load_default cc_bin_file_name_prefix "" "cc cfg"
tool_variable_check_load_default cc_install_dir_path_default "" "wallet default install dir path"
# check download build install update purge arguments
tool_variable_check_load_default cc_action1 cc_action1_default "download|build action"
tool_variable_check_load_default cc_action2 cc_action2_default "install|update|continue|purge action"
# prepare install directory path
cc_install_dir_path_default_tmp=${cc_dexsetup_dir_path}"/../"${cc_install_dir_path_default}
tool_variable_check_load_default cc_install_dir_path cc_install_dir_path_default_tmp
tool_realpath cc_install_dir_path "cc install dir path"
tool_make_and_check_dir_path cc_install_dir_path "cc install dir path"
# prepare package files path
cc_pkg_path=${cc_install_dir_path}"/pkg"
tool_realpath cc_pkg_path "pkg file dir"
# prepare extracted bin files path
cc_extracted_pkg_bin_files_path=${cc_pkg_path}"/"${cc_download_extracted_bin_files_dir}
tool_realpath cc_extracted_pkg_bin_files_path "extracted pkg bin files path"
# prepare git source files path
cc_git_src_path=${cc_install_dir_path}"/git.src"
tool_realpath cc_git_src_path "src files dir"
# prepare bin files path
cc_bin_path=${cc_install_dir_path}"/bin"
tool_realpath cc_bin_path "binary files dir"
# custom predefined pre build command if specified
if [ "${cc_action1}" = "build" ]; then
if [ "${cc_command_pre_build}" != "" ]; then
echo "INFO >> using custom pre build command >> cc_command_pre_build >> "
echo "${cc_command_pre_build}"
echo ""
eval `echo ${cc_command_pre_build}`
(test $? != 0) && echo "ERROR >> custom pre dependencies command >> ${cc_command_pre_build} >> failed" && exit 1
echo "INFO >> cc_command_pre_build >> finish success"
fi
fi
if [ "${cc_action1}" = "download" ]; then
tool_variable_check_load_default cc_download_extracted_bin_files_dir "" "cc download extracted bin files dir"
elif [ "${cc_action1}" = "build" ]; then
tool_variable_check_load_default cc_git_src_url ""
tool_variable_check_load_default cc_git_src_branch ""
tool_variable_check_load_default cc_git_commit_id ""
fi
# solve install update continue purge arguments initialization
if [ "${cc_action2}" = "install" ]; then
tool_dir_if_exist_exit cc_pkg_path "checking if pkg not already installed" "please try update|purge argument"
tool_dir_if_exist_exit cc_bin_path "checking if bin not already installed" "please try update|purge argument"
tool_dir_if_exist_exit cc_git_src_path "checking if git src not already installed" "please try update|purge argument"
tool_make_and_check_dir_path cc_pkg_path "pkg directory"
tool_make_and_check_dir_path cc_bin_path "bin directory"
tool_make_and_check_dir_path cc_git_src_path "git src directory"
elif [ "${cc_action2}" = "update" ] || [ "${cc_action2}" = "continue" ]; then
# downloaded package sha512sum could be actually up to date so do not need to remove pkg dir
tool_make_and_check_dir_path cc_pkg_path "pkg directory"
tool_make_and_check_dir_path cc_git_src_path "git src directory"
# any previous binary files must be removed to be sure we update correctly
rm -rfv "${cc_bin_path}"
(test $? != 0) && echo "WARNING >> directories >> ${cc_bin_path} >> remove failed"
tool_make_and_check_dir_path cc_bin_path "bin directory"
elif [ "${cc_action2}" = "purge" ]; then
if [ "${cc_action1}" = "download" ]; then
rm -rfv "${cc_pkg_path}"
(test $? != 0) && echo "WARNING >> directories >> ${cc_pkg_path} >> remove failed"
else
rm -rfv "${cc_git_src_path}"
(test $? != 0) && echo "WARNING >> directories >> ${cc_git_src_path} >> remove failed"
fi
rm -rfv "${cc_bin_path}"
(test $? != 0) && echo "WARNING >> directories >> ${cc_bin_path} >> remove failed"
exit 0
else
echo "ERROR >> action<install|update|continue|purge> not specified"
exit 1
fi
# run download or checkout and build script inside sandbox
# download binary files directly
if [ "${cc_action2}" = "install" ] || [ "${cc_action2}" = "update" ] || [ "${cc_action2}" = "continue" ]; then
echo "********************** ENTER FIREJAIL SANDBOX ******************************"
if [ "${cc_action1}" = "download" ]; then
if [ "${cc_firejail}" != "" ]; then
# process securely sandboxed by firejail
cc_firejail_make_args_expand=`eval echo ${cc_firejail_make_args}`
firejail --profile=./src/setup.cc.make.firejail.profile \
--whitelist=`pwd` --read-only=`pwd` \
--whitelist=${cc_pkg_path} \
${cc_firejail_make_args_expand} \
${cc_script_download_path} ${cc_script_cfg_path} ${cc_action2} ${cc_pkg_path} "${cc_proxychains}"
(test $? != 0) && echo "ERROR >> checkout and build script failed" && exit 1
else
# process not sandboxed
${cc_script_download_path} ${cc_script_cfg_path} ${cc_action2} ${cc_pkg_path} "${cc_proxychains}"
(test $? != 0) && echo "ERROR >> checkout and build script failed" && exit 1
fi
elif [ "${cc_action1}" = "build" ]; then
if [ "${cc_firejail}" != "" ]; then
# process securely sandboxed by firejail
cc_firejail_make_args_expand=`eval echo ${cc_firejail_make_args}`
firejail --profile=./src/setup.cc.make.firejail.profile \
--whitelist=`pwd` --read-only=`pwd` \
--whitelist=${cc_git_src_path} \
${cc_firejail_make_args_expand} \
${cc_script_make_path} ${cc_script_cfg_path} ${cc_action2} ${cc_git_src_path} "${cc_proxychains}"
(test $? != 0) && echo "ERROR >> checkout and build script failed" && exit 1
else
# process not sandboxed
${cc_script_make_path} ${cc_script_cfg_path} ${cc_action2} ${cc_git_src_path} "${cc_proxychains}"
(test $? != 0) && echo "ERROR >> checkout and build script failed" && exit 1
fi
fi
echo "********************** EXIT FIREJAIL SANDBOX ******************************"
fi
# copy binary files
# copy bin files extracted from package
if [ "${cc_action1}" = "download" ]; then
cp -u ${cc_extracted_pkg_bin_files_path}"/"${cc_bin_file_name_prefix}d ${cc_bin_path}"/"${cc_bin_file_name_prefix}.d.bin
(test $? != 0) && echo "ERROR >> file >> ${cc_bin_file_name_prefix}d >> copy failed" && exit 1
tool_info "copy daemon file to bin" cc_bin_file_name_prefix "success"
cp -u ${cc_extracted_pkg_bin_files_path}"/"${cc_bin_file_name_prefix}-cli ${cc_bin_path}"/"${cc_bin_file_name_prefix}.cli.bin
(test $? != 0) && echo "ERROR >> file >> ${cc_bin_file_name_prefix}-cli >> copy failed" && exit 1
tool_info "copy cli file to bin" cc_bin_file_name_prefix "success"
cp -u ${cc_extracted_pkg_bin_files_path}"/"${cc_bin_file_name_prefix}-qt ${cc_bin_path}"/"${cc_bin_file_name_prefix}.qt.bin
(test $? != 0) && tool_info "copy qt file to bin" cc_bin_file_name_prefix "failed-not-error" || tool_info "copy qt file to bin" cc_bin_file_name_prefix "success"
# copy bin files build from source
elif [ "${cc_action1}" = "build" ]; then
cp -u ${cc_git_src_path}"/src/"${cc_bin_file_name_prefix}d ${cc_bin_path}"/"${cc_bin_file_name_prefix}.d.bin
(test $? != 0) && echo "ERROR >> file >> ${cc_bin_file_name_prefix} >> copy failed" && exit 1
tool_info "copy daemon file to bin" cc_bin_file_name_prefix "success"
cp -u ${cc_git_src_path}"/src/"${cc_bin_file_name_prefix}-cli ${cc_bin_path}"/"${cc_bin_file_name_prefix}.cli.bin
(test $? != 0) && echo "ERROR >> file >> ${cc_bin_file_name_prefix}-cli >> copy failed" && exit 1
tool_info "copy cli file to bin" cc_bin_file_name_prefix "success"
cp -u ${cc_git_src_path}"/src/qt/"${cc_bin_file_name_prefix}-qt ${cc_bin_path}"/"${cc_bin_file_name_prefix}.qt.bin || cp -u ${cc_git_src_path}"/src/"${cc_bin_file_name_prefix}-qt ${cc_bin_path}"/"${cc_bin_file_name_prefix}.qt.bin
(test $? != 0) && tool_info "copy qt file to bin" cc_bin_file_name_prefix "failed-not-error" || tool_info "copy qt file to bin" cc_bin_file_name_prefix "success"
else
echo "ERROR >> action<download|build> not specified"
exit 1
fi
# finally check by antivirus if present and scan all files in sandbox
clamscan_path="/usr/bin/clamscan"
if [ -f "${clamscan_path}" ]; then
echo "INFO >> using clamscan_path >> ${clamscan_path}"
${clamscan_path} -r -v -z --no-summary ${cc_bin_path}"/"*
(test $? != 0) && echo "ERROR >> AV SCAN >> ${clamscan_path} ${cc_bin_path}/* >> FAILED" && rm -rf ${cc_bin_path}"/"* && exit 1
echo "INFO >> AV SCAN >> ${cc_bin_path}/* >> success"
fi
echo "*** MAIN CC SETUP SUCCESS ***"
tool_time_finish_print
exit 0