@@ -13,11 +13,8 @@ FILTRON_ETC="/etc/filtron"
14FILTRON_RULES="$FILTRON_ETC/rules.json"
14FILTRON_RULES="$FILTRON_ETC/rules.json"
16−# shellcheck disable=SC2034
17FILTRON_API="127.0.0.1:4005"
16FILTRON_API="127.0.0.1:4005"
18−# shellcheck disable=SC2034
19FILTRON_LISTEN="127.0.0.1:4004"
17FILTRON_LISTEN="127.0.0.1:4004"
20−# shellcheck disable=SC2034
21FILTRON_TARGET="127.0.0.1:8888"
18FILTRON_TARGET="127.0.0.1:8888"
23SERVICE_NAME="filtron"
20SERVICE_NAME="filtron"
@@ -32,6 +29,8 @@ GO_ENV="${SERVICE_HOME}/.go_env"
32GO_PKG_URL="https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz"
29GO_PKG_URL="https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz"
33GO_TAR=$(basename "$GO_PKG_URL")
30GO_TAR=$(basename "$GO_PKG_URL")
32+APACHE_SITE="searx.conf"
35# shellcheck disable=SC2034
34# shellcheck disable=SC2034
36CONFIG_FILES=(
35CONFIG_FILES=(
37 "${FILTRON_RULES}"
36 "${FILTRON_RULES}"
@@ -39,7 +38,7 @@ CONFIG_FILES=(
41# ----------------------------------------------------------------------------
40# ----------------------------------------------------------------------------
43# ----------------------------------------------------------------------------
42# ----------------------------------------------------------------------------
45 # shellcheck disable=SC1117
44 # shellcheck disable=SC1117
@@ -73,7 +72,7 @@ EOF
73 [ ! -z ${1+x} ] && echo -e "$1"
72 [ ! -z ${1+x} ] && echo -e "$1"
77 rst_title "$SERVICE_NAME" part
76 rst_title "$SERVICE_NAME" part
79 local _usage="ERROR: unknown or missing $1 command $2"
78 local _usage="ERROR: unknown or missing $1 command $2"
@@ -140,6 +139,10 @@ install_all() {
141 install_service
140 install_service
142+ if apache_is_installed; then
145remove_all() {
148remove_all() {
@@ -151,10 +154,22 @@ remove_all() {
157+filtron_is_available() {
158+ curl --insecure "http://${FILTRON_LISTEN}" &>/dev/null
162+ curl --insecure "http://${FILTRON_API}" &>/dev/null
165+target_is_available() {
166+ curl --insecure "http://${FILTRON_TARGET}" &>/dev/null
154install_service() {
169install_service() {
155 rst_title "Install System-D Unit ${SERVICE_NAME}.service" section
170 rst_title "Install System-D Unit ${SERVICE_NAME}.service" section
157− install_template ${SERVICE_SYSTEMD_UNIT} root root 644
172+ install_template "${SERVICE_SYSTEMD_UNIT}" root root 644
159 activate_service
174 activate_service
@@ -167,19 +182,19 @@ remove_service() {
167 rm "${SERVICE_SYSTEMD_UNIT}" 2>&1 | prefix_stdout
182 rm "${SERVICE_SYSTEMD_UNIT}" 2>&1 | prefix_stdout
170−activate_service () {
185+activate_service() {
171 rst_title "Activate $SERVICE_NAME (service)" section
186 rst_title "Activate $SERVICE_NAME (service)" section
173− tee_stderr <<EOF | bash 2>&1 | prefix_stdout
188+ tee_stderr <<EOF | bash 2>&1
174systemctl enable $SERVICE_NAME.service
189systemctl enable $SERVICE_NAME.service
175systemctl restart $SERVICE_NAME.service
190systemctl restart $SERVICE_NAME.service
177− tee_stderr <<EOF | bash 2>&1 | prefix_stdout
192+ tee_stderr <<EOF | bash 2>&1
178systemctl status $SERVICE_NAME.service
193systemctl status $SERVICE_NAME.service
182−deactivate_service () {
197+deactivate_service() {
183 rst_title "De-Activate $SERVICE_NAME (service)" section
198 rst_title "De-Activate $SERVICE_NAME (service)" section
185 tee_stderr <<EOF | bash 2>&1 | prefix_stdout
200 tee_stderr <<EOF | bash 2>&1 | prefix_stdout
@@ -188,6 +203,10 @@ systemctl disable $SERVICE_NAME.service
206+user_is_available() {
207+ sudo -i -u "$SERVICE_USER" echo \$HOME &>/dev/null
191assert_user() {
210assert_user() {
192 rst_title "user $SERVICE_USER" section
211 rst_title "user $SERVICE_USER" section
@@ -228,7 +247,11 @@ interactive_shell(){
229_service_prefix=" |$SERVICE_USER| "
248_service_prefix=" |$SERVICE_USER| "
251+ sudo -i -u "$SERVICE_USER" which go &>/dev/null
231−install_go(){
254+install_go() {
232 rst_title "Install Go in user's HOME" section
255 rst_title "Install Go in user's HOME" section
234 rst_para "download and install go binary .."
257 rst_para "download and install go binary .."
@@ -248,6 +271,10 @@ which go >/dev/null && go version && echo "congratulations -- Go installation O
274+filtron_is_installed() {
275+ [[ -f $SERVICE_HOME/go-apps/bin/filtron ]]
251install_filtron() {
278install_filtron() {
252 rst_title "Install filtron in user's ~/go-apps" section
279 rst_title "Install filtron in user's ~/go-apps" section
@@ -265,12 +292,48 @@ go get -v -u github.com/asciimoo/filtron
268−show_service () {
295+show_service() {
269 rst_title "service status & log"
296 rst_title "service status & log"
271− systemctl status filtron.service
298+
299+ apache_is_installed && info_msg "Apache is installed."
301+ if user_is_available; then
302+ info_msg "service account $SERVICE_USER available."
304+ err_msg "service account $SERVICE_USER not available!"
306+ if go_is_available; then
307+ info_msg "~$SERVICE_USER: go is installed"
309+ err_msg "~$SERVICE_USER: go is not installed"
311+ if filtron_is_installed; then
312+ info_msg "~$SERVICE_USER: filtron app is installed"
314+ err_msg "~$SERVICE_USER: filtron app is not installed!"
316+ if api_is_available; then
317+ info_msg "API available at: http://${FILTRON_API}"
319+ err_msg "API not available at: http://${FILTRON_API}"
321+ if filtron_is_available; then
322+ info_msg "Filtron listening on: http://${FILTRON_LISTEN}"
324+ err_msg "Filtron does not listening on: http://${FILTRON_LISTEN}"
326+ if target_is_available; then
327+ info_msg "Filtron's target is available at: http://${FILTRON_TARGET}"
329+ err_msg "Filtron's target is not available at: http://${FILTRON_TARGET}"
334+ systemctl --no-pager -l status filtron.service
273− read -r -s -n1 -t 5 -p "// use CTRL-C to stop monitoring the log"
336+ read -r -s -n1 -t 2 -p "// use CTRL-C to stop monitoring the log"
275 while true; do
338 while true; do
276 trap break 2
339 trap break 2
@@ -279,6 +342,13 @@ show_service () {
345+install_apache_site() {
346+ rst_title "Install Apache site $APACHE_SITE" section
348+ err_msg "not yet implemented (${APACHE_SITE})"; return 42
349+ # apache_install_site "${APACHE_SITE}"
282# ----------------------------------------------------------------------------
352# ----------------------------------------------------------------------------
284# ----------------------------------------------------------------------------
354# ----------------------------------------------------------------------------