@@ -109,7 +109,7 @@ main() {
109109
110110 shell)
111111 sudo_or_exit
112− interactive_shell
112+ interactive_shell "${SERVICE_USER}"
113113 ;;
114114 inspect)
115115 case $2 in
@@ -136,19 +136,19 @@ main() {
136136 sudo_or_exit
137137 case $2 in
138138 all) remove_all;;
139− user) remove_user ;;
139+ user) drop_service_account "${SERVICE_USER}" ;;
140140 *) usage "$_usage"; exit 42;;
141141 esac ;;
142142 activate)
143143 sudo_or_exit
144144 case $2 in
145− service) activate_service ;;
145+ service) systemd_activate_service "${SERVICE_NAME}" ;;
146146 *) usage "$_usage"; exit 42;;
147147 esac ;;
148148 deactivate)
149149 sudo_or_exit
150150 case $2 in
151− service) deactivate_service ;;
151+ service) systemd_deactivate_service "${SERVICE_NAME}" ;;
152152 *) usage "$_usage"; exit 42;;
153153 esac ;;
154154 apache)
@@ -174,11 +174,11 @@ install_all() {
174174 rst_title "Install $SERVICE_NAME (service)"
175175 assert_user
176176 wait_key
177− install_go
177+ install_go "${GO_PKG_URL}" "${GO_TAR}" "${SERVICE_USER}"
178178 wait_key
179179 install_filtron
180180 wait_key
181− install_service
181+ systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
182182 wait_key
183183 echo
184184 if ! service_is_available "http://${FILTRON_LISTEN}" ; then
@@ -203,56 +203,15 @@ remove_all() {
203203It goes without saying that this script can only be used to remove
204204installations that were installed with this script."
205205
206− remove_service
206+ systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
207207 wait_key
208− remove_user
208+ drop_service_account "${SERVICE_USER}"
209209 rm -r "$FILTRON_ETC" 2>&1 | prefix_stdout
210210 if service_is_available "${PUBLIC_URL}"; then
211211 MSG="** Don't forget to remove your public site! (${PUBLIC_URL}) **" wait_key 10
212212 fi
213213}
214214
215−install_service() {
216− rst_title "Install System-D Unit ${SERVICE_NAME}.service" section
217− echo
218− install_template "${SERVICE_SYSTEMD_UNIT}" root root 644
219− wait_key
220− activate_service
221−}
222−
223−remove_service() {
224− if ! ask_yn "Do you really want to deinstall $SERVICE_NAME?"; then
225− return
226− fi
227− deactivate_service
228− rm "${SERVICE_SYSTEMD_UNIT}" 2>&1 | prefix_stdout
229−}
230−
231−activate_service() {
232− rst_title "Activate $SERVICE_NAME (service)" section
233− echo
234− tee_stderr <<EOF | bash 2>&1
235−systemctl enable $SERVICE_NAME.service
236−systemctl restart $SERVICE_NAME.service
237−EOF
238− tee_stderr <<EOF | bash 2>&1
239−systemctl status --no-pager $SERVICE_NAME.service
240−EOF
241−}
242−
243−deactivate_service() {
244− rst_title "De-Activate $SERVICE_NAME (service)" section
245− echo
246− tee_stderr <<EOF | bash 2>&1 | prefix_stdout
247−systemctl stop $SERVICE_NAME.service
248−systemctl disable $SERVICE_NAME.service
249−EOF
250−}
251−
252−user_is_available() {
253− sudo -i -u "$SERVICE_USER" echo \$HOME &>/dev/null
254−}
255−
256215assert_user() {
257216 rst_title "user $SERVICE_USER" section
258217 echo
@@ -277,44 +236,6 @@ grep -qFs -- 'source $GO_ENV' ~/.profile || echo 'source $GO_ENV' >> ~/.profile
277236EOF
278237}
279238
280−remove_user() {
281− rst_title "Drop $SERVICE_USER HOME" section
282− if ask_yn "Do you really want to drop $SERVICE_USER home folder?"; then
283− userdel -r -f "$SERVICE_USER" 2>&1 | prefix_stdout
284− else
285− rst_para "Leave HOME folder $(du -sh "$SERVICE_HOME") unchanged."
286− fi
287−}
288−
289−interactive_shell(){
290− echo "// exit with ${_BCyan}CTRL-D${_creset}"
291− sudo -H -u ${SERVICE_USER} -i
292−}
293−
294−_service_prefix=" |$SERVICE_USER| "
295−
296−go_is_available() {
297− sudo -i -u "$SERVICE_USER" which go &>/dev/null
298−}
299−
300−install_go() {
301− rst_title "Install Go in user's HOME" section
302−
303− rst_para "download and install go binary .."
304− cache_download "${GO_PKG_URL}" "${GO_TAR}"
305−
306− tee_stderr 0.1 <<EOF | sudo -i -u "$SERVICE_USER" | prefix_stdout "$_service_prefix"
307−echo \$PATH
308−echo \$GOPATH
309−mkdir -p \$HOME/local
310−rm -rf \$HOME/local/go
311−tar -C \$HOME/local -xzf ${CACHE}/${GO_TAR}
312−EOF
313− sudo -i -u "$SERVICE_USER" <<EOF | prefix_stdout
314−! which go >/dev/null && echo "ERROR - Go Installation not found in PATH!?!"
315−which go >/dev/null && go version && echo "congratulations -- Go installation OK :)"
316−EOF
317−}
318239
319240filtron_is_installed() {
320241 [[ -f $SERVICE_HOME/go-apps/bin/filtron ]]
@@ -356,12 +277,12 @@ EOF
356277
357278 apache_is_installed && info_msg "Apache is installed."
358279
359− if user_is_available; then
280+ if service_account_is_available "$SERVICE_USER"; then
360281 info_msg "service account $SERVICE_USER available."
361282 else
362283 err_msg "service account $SERVICE_USER not available!"
363284 fi
364− if go_is_available; then
285+ if go_is_available "$SERVICE_USER"; then
365286 info_msg "~$SERVICE_USER: go is installed"
366287 else
367288 err_msg "~$SERVICE_USER: go is not installed"