@@ -13,11 +13,8 @@ FILTRON_ETC="/etc/filtron"
1313
1414FILTRON_RULES="$FILTRON_ETC/rules.json"
1515
16−# shellcheck disable=SC2034
1716FILTRON_API="127.0.0.1:4005"
18−# shellcheck disable=SC2034
1917FILTRON_LISTEN="127.0.0.1:4004"
20−# shellcheck disable=SC2034
2118FILTRON_TARGET="127.0.0.1:8888"
2219
2320SERVICE_NAME="filtron"
@@ -32,6 +29,8 @@ GO_ENV="${SERVICE_HOME}/.go_env"
3229GO_PKG_URL="https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz"
3330GO_TAR=$(basename "$GO_PKG_URL")
3431
32+APACHE_SITE="searx.conf"
33+
3534# shellcheck disable=SC2034
3635CONFIG_FILES=(
3736 "${FILTRON_RULES}"
@@ -39,7 +38,7 @@ CONFIG_FILES=(
3938)
4039
4140# ----------------------------------------------------------------------------
42−usage(){
41+usage() {
4342# ----------------------------------------------------------------------------
4443
4544 # shellcheck disable=SC1117
@@ -73,7 +72,7 @@ EOF
7372 [ ! -z ${1+x} ] && echo -e "$1"
7473}
7574
76−main(){
75+main() {
7776 rst_title "$SERVICE_NAME" part
7877
7978 local _usage="ERROR: unknown or missing $1 command $2"
@@ -140,6 +139,10 @@ install_all() {
140139 wait_key
141140 install_service
142141 wait_key
142+ if apache_is_installed; then
143+ install_apache_site
144+ wait_key
145+ fi
143146}
144147
145148remove_all() {
@@ -151,10 +154,22 @@ remove_all() {
151154 wait_key
152155}
153156
157+filtron_is_available() {
158+ curl --insecure "http://${FILTRON_LISTEN}" &>/dev/null
159+}
160+
161+api_is_available() {
162+ curl --insecure "http://${FILTRON_API}" &>/dev/null
163+}
164+
165+target_is_available() {
166+ curl --insecure "http://${FILTRON_TARGET}" &>/dev/null
167+}
168+
154169install_service() {
155170 rst_title "Install System-D Unit ${SERVICE_NAME}.service" section
156171 echo
157− install_template ${SERVICE_SYSTEMD_UNIT} root root 644
172+ install_template "${SERVICE_SYSTEMD_UNIT}" root root 644
158173 wait_key
159174 activate_service
160175}
@@ -167,19 +182,19 @@ remove_service() {
167182 rm "${SERVICE_SYSTEMD_UNIT}" 2>&1 | prefix_stdout
168183}
169184
170−activate_service () {
185+activate_service() {
171186 rst_title "Activate $SERVICE_NAME (service)" section
172187 echo
173− tee_stderr <<EOF | bash 2>&1 | prefix_stdout
188+ tee_stderr <<EOF | bash 2>&1
174189systemctl enable $SERVICE_NAME.service
175190systemctl restart $SERVICE_NAME.service
176191EOF
177− tee_stderr <<EOF | bash 2>&1 | prefix_stdout
192+ tee_stderr <<EOF | bash 2>&1
178193systemctl status $SERVICE_NAME.service
179194EOF
180195}
181196
182−deactivate_service () {
197+deactivate_service() {
183198 rst_title "De-Activate $SERVICE_NAME (service)" section
184199 echo
185200 tee_stderr <<EOF | bash 2>&1 | prefix_stdout
@@ -188,6 +203,10 @@ systemctl disable $SERVICE_NAME.service
188203EOF
189204}
190205
206+user_is_available() {
207+ sudo -i -u "$SERVICE_USER" echo \$HOME &>/dev/null
208+}
209+
191210assert_user() {
192211 rst_title "user $SERVICE_USER" section
193212 echo
@@ -228,7 +247,11 @@ interactive_shell(){
228247
229248_service_prefix=" |$SERVICE_USER| "
230249
231−install_go(){
250+go_is_available() {
251+ sudo -i -u "$SERVICE_USER" which go &>/dev/null
252+}
253+
254+install_go() {
232255 rst_title "Install Go in user's HOME" section
233256
234257 rst_para "download and install go binary .."
@@ -248,6 +271,10 @@ which go >/dev/null && go version && echo "congratulations -- Go installation O
248271EOF
249272}
250273
274+filtron_is_installed() {
275+ [[ -f $SERVICE_HOME/go-apps/bin/filtron ]]
276+}
277+
251278install_filtron() {
252279 rst_title "Install filtron in user's ~/go-apps" section
253280 echo
@@ -265,12 +292,48 @@ go get -v -u github.com/asciimoo/filtron
265292EOF
266293}
267294
268−show_service () {
295+show_service() {
269296 rst_title "service status & log"
270297 echo
271− systemctl status filtron.service
298+
299+ apache_is_installed && info_msg "Apache is installed."
300+
301+ if user_is_available; then
302+ info_msg "service account $SERVICE_USER available."
303+ else
304+ err_msg "service account $SERVICE_USER not available!"
305+ fi
306+ if go_is_available; then
307+ info_msg "~$SERVICE_USER: go is installed"
308+ else
309+ err_msg "~$SERVICE_USER: go is not installed"
310+ fi
311+ if filtron_is_installed; then
312+ info_msg "~$SERVICE_USER: filtron app is installed"
313+ else
314+ err_msg "~$SERVICE_USER: filtron app is not installed!"
315+ fi
316+ if api_is_available; then
317+ info_msg "API available at: http://${FILTRON_API}"
318+ else
319+ err_msg "API not available at: http://${FILTRON_API}"
320+ fi
321+ if filtron_is_available; then
322+ info_msg "Filtron listening on: http://${FILTRON_LISTEN}"
323+ else
324+ err_msg "Filtron does not listening on: http://${FILTRON_LISTEN}"
325+ fi
326+ if target_is_available; then
327+ info_msg "Filtron's target is available at: http://${FILTRON_TARGET}"
328+ else
329+ err_msg "Filtron's target is not available at: http://${FILTRON_TARGET}"
330+ fi
331+
332+ wait_key
272333 echo
273− read -r -s -n1 -t 5 -p "// use CTRL-C to stop monitoring the log"
334+ systemctl --no-pager -l status filtron.service
335+ echo
336+ read -r -s -n1 -t 2 -p "// use CTRL-C to stop monitoring the log"
274337 echo
275338 while true; do
276339 trap break 2
@@ -279,6 +342,13 @@ show_service () {
279342 return 0
280343}
281344
345+install_apache_site() {
346+ rst_title "Install Apache site $APACHE_SITE" section
347+ echo
348+ err_msg "not yet implemented (${APACHE_SITE})"; return 42
349+ # apache_install_site "${APACHE_SITE}"
350+}
351+
282352# ----------------------------------------------------------------------------
283353main "$@"
284354# ----------------------------------------------------------------------------