From ce4afbf5a1c4ffabd3ab8d1be87e002260bcce1d Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@robotics.uk.to>
Date: Fri, 30 Sep 2016 16:00:45 +0100
Subject: [PATCH] Tidying

---
 src/freedombone-app-babel       | 4 ++--
 src/freedombone-app-batman      | 4 ++--
 src/freedombone-app-blog        | 4 ++--
 src/freedombone-app-blogstatic  | 4 ++--
 src/freedombone-app-cjdns       | 4 ++--
 src/freedombone-app-dlna        | 4 ++--
 src/freedombone-app-emacs       | 4 ++--
 src/freedombone-app-gnusocial   | 4 ++--
 src/freedombone-app-gogs        | 4 ++--
 src/freedombone-app-hubzilla    | 4 ++--
 src/freedombone-app-ipfs        | 8 ++++----
 src/freedombone-app-irc         | 4 ++--
 src/freedombone-app-librevault  | 4 ++--
 src/freedombone-app-mediagoblin | 4 ++--
 src/freedombone-app-mumble      | 7 ++-----
 src/freedombone-app-rss         | 4 ++--
 src/freedombone-app-searx       | 4 ++--
 src/freedombone-app-sip         | 4 ++--
 src/freedombone-app-syncthing   | 4 ++--
 src/freedombone-app-tahoelafs   | 4 ++--
 src/freedombone-app-tox         | 4 ++--
 src/freedombone-app-vpn         | 4 ++--
 src/freedombone-app-webmail     | 4 ++--
 src/freedombone-app-wiki        | 4 ++--
 src/freedombone-app-xmpp        | 4 ++--
 src/freedombone-app-zeronet     | 4 ++--
 src/freedombone-utils-selector  | 7 +++++++
 27 files changed, 61 insertions(+), 57 deletions(-)

diff --git a/src/freedombone-app-babel b/src/freedombone-app-babel
index 8d9b4946e..4d81f900c 100755
--- a/src/freedombone-app-babel
+++ b/src/freedombone-app-babel
@@ -100,7 +100,7 @@ function configure_firewall_for_babel {
 }
 
 function install_babel {
-    if grep -Fxq "install_babel" $COMPLETION_FILE; then
+    if [[ $(app_is_installed babel) == "1" ]]; then
         return
     fi
     if [[ $ENABLE_BABEL != "yes" ]]; then
@@ -115,7 +115,7 @@ function install_babel {
 
     function_check configure_firewall_for_babel
     configure_firewall_for_babel
-    echo 'install_babel' >> $COMPLETION_FILE
+    install_completed babel
 }
 
 # NOTE: deliberately there is no "exit 0"
diff --git a/src/freedombone-app-batman b/src/freedombone-app-batman
index 23b262a8f..b3f65fef9 100755
--- a/src/freedombone-app-batman
+++ b/src/freedombone-app-batman
@@ -135,7 +135,7 @@ function install_batman {
         mesh_install_batman
         return
     fi
-    if grep -Fxq "install_batman" $COMPLETION_FILE; then
+    if [[ $(app_is_installed batman) == "1" ]]; then
         return
     fi
     if [[ $ENABLE_BATMAN != "yes" ]]; then
@@ -162,7 +162,7 @@ function install_batman {
 
     function_check configure_firewall_for_batman
     configure_firewall_for_batman
-    echo 'install_batman' >> $COMPLETION_FILE
+    install_completed batman
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-blog b/src/freedombone-app-blog
index c2d4cb578..ee46a8ab4 100755
--- a/src/freedombone-app-blog
+++ b/src/freedombone-app-blog
@@ -500,7 +500,7 @@ function install_blog {
         exit 5062
     fi
 
-    if grep -Fxq "install_blog" $COMPLETION_FILE; then
+    if [[ $(app_is_installed blog) == "1" ]]; then
         return
     fi
 
@@ -560,7 +560,7 @@ function install_blog {
         echo "Blog domain:$FULLBLOG_DOMAIN_NAME" >> $COMPLETION_FILE
     fi
 
-    echo 'install_blog' >> $COMPLETION_FILE
+    install_completed blog
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-blogstatic b/src/freedombone-app-blogstatic
index 844c7efc4..f412ef15c 100755
--- a/src/freedombone-app-blogstatic
+++ b/src/freedombone-app-blogstatic
@@ -305,7 +305,7 @@ function install_blogstatic {
         return
     fi
 
-    if grep -Fxq "install_blogstatic" $COMPLETION_FILE; then
+    if [[ $(app_is_installed blogstatic) == "1" ]]; then
         return
     fi
 
@@ -343,7 +343,7 @@ function install_blogstatic {
     chown -R $MY_USERNAME:$MY_USERNAME $STATIC_BLOG_INSTALL_DIR
     chown -R www-data:www-data $STATIC_BLOG_PATH
 
-    echo 'install_blogstatic' >> $COMPLETION_FILE
+    install_completed blogstatic
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-cjdns b/src/freedombone-app-cjdns
index bcd8d8146..02b422e92 100755
--- a/src/freedombone-app-cjdns
+++ b/src/freedombone-app-cjdns
@@ -533,12 +533,12 @@ function install_cjdns_tools {
 }
 
 function install_cjdns {
-    if grep -Fxq "install_cjdns" $COMPLETION_FILE; then
+    if [[ $(app_is_installed cjdns) == "1" ]]; then
         return
     fi
     install_cjdns_main
     install_cjdns_tools
-    echo 'install_cjdns' >> $COMPLETION_FILE
+    install_completed cjdns
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-dlna b/src/freedombone-app-dlna
index 99c34e717..c8af424c8 100755
--- a/src/freedombone-app-dlna
+++ b/src/freedombone-app-dlna
@@ -257,12 +257,12 @@ function script_for_attaching_usb_drive {
 }
 
 function install_dlna {
-    if grep -Fxq "install_dlna" $COMPLETION_FILE; then
+    if [[ $(app_is_installed dlna) == "1" ]]; then
         return
     fi
     install_dlna_main
     script_for_attaching_usb_drive
-    echo 'install_dlna' >> $COMPLETION_FILE
+    install_completed dlna
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-emacs b/src/freedombone-app-emacs
index 6320d66db..a3445e027 100755
--- a/src/freedombone-app-emacs
+++ b/src/freedombone-app-emacs
@@ -108,7 +108,7 @@ function remove_emacs {
 }
 
 function install_emacs {
-    if grep -Fxq "install_emacs" $COMPLETION_FILE; then
+    if [[ $(app_is_installed emacs) == "1" ]]; then
         return
     fi
     update-alternatives --set editor /usr/bin/emacs24
@@ -186,7 +186,7 @@ function install_emacs {
     cp /home/$MY_USERNAME/.emacs /root/.emacs
     chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
 
-    echo 'install_emacs' >> $COMPLETION_FILE
+    install_completed emacs
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-gnusocial b/src/freedombone-app-gnusocial
index 0aa3d7d49..e689b5974 100755
--- a/src/freedombone-app-gnusocial
+++ b/src/freedombone-app-gnusocial
@@ -876,7 +876,7 @@ function install_gnusocial_plugin_nsfw {
 }
 
 function install_gnusocial {
-    if grep -Fxq "install_gnusocial" $COMPLETION_FILE; then
+    if [[ $(app_is_installed gnusocial) == "1" ]]; then
         return
     fi
     install_gnusocial_main
@@ -886,7 +886,7 @@ function install_gnusocial {
     install_gnusocial_plugin_sharings
     install_gnusocial_plugin_sharings_theme
     install_gnusocial_plugin_nsfw
-    echo 'install_gnusocial' >> $COMPLETION_FILE
+    install_completed gnusocial
 }
 
 # NOTE: deliberately there is no "exit 0"
diff --git a/src/freedombone-app-gogs b/src/freedombone-app-gogs
index 2110417f9..edfabfada 100755
--- a/src/freedombone-app-gogs
+++ b/src/freedombone-app-gogs
@@ -345,7 +345,7 @@ function install_gogs {
         return
     fi
 
-    if grep -Fxq "install_gogs" $COMPLETION_FILE; then
+    if [[ $(app_is_installed gogs) == "1" ]]; then
         return
     fi
 
@@ -666,7 +666,7 @@ function install_gogs {
     else
         sed -i "s|Gogs version.*|Gogs version:$GOGS_VERSION|g" $COMPLETION_FILE
     fi
-    echo 'install_gogs' >> $COMPLETION_FILE
+    install_completed gogs
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-hubzilla b/src/freedombone-app-hubzilla
index e847e2c10..e35dff9c5 100755
--- a/src/freedombone-app-hubzilla
+++ b/src/freedombone-app-hubzilla
@@ -310,7 +310,7 @@ function install_hubzilla {
         return
     fi
 
-    if grep -Fxq "install_hubzilla" $COMPLETION_FILE; then
+    if [[ $(app_is_installed hubzilla) == "1" ]]; then
         return
     fi
 
@@ -611,7 +611,7 @@ function install_hubzilla {
     ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$HUBZILLA_DOMAIN_NAME" -g hubzilla --public no
 
     echo "Hubzilla domain:${HUBZILLA_DOMAIN_NAME}" >> $COMPLETION_FILE
-    echo 'install_hubzilla' >> $COMPLETION_FILE
+    install_completed hubzilla
 }
 
 # NOTE: deliberately there is no "exit 0"
diff --git a/src/freedombone-app-ipfs b/src/freedombone-app-ipfs
index 611b2933e..7dcde766c 100755
--- a/src/freedombone-app-ipfs
+++ b/src/freedombone-app-ipfs
@@ -288,7 +288,7 @@ function install_ipfs_js {
         mesh_install_ipfs_js
         return
     fi
-    if grep -Fxq "install_ipfs_js" $COMPLETION_FILE; then
+    if [[ $(app_is_installed ipfs_js) == "1" ]]; then
         return
     fi
 
@@ -378,7 +378,7 @@ function install_ipfs_js {
     function_check configure_firewall_for_ipfs
     configure_firewall_for_ipfs
 
-    echo 'install_ipfs_js' >> $COMPLETION_FILE
+    install_completed ipfs_js
 }
 
 function mesh_install_ipfs_go {
@@ -455,7 +455,7 @@ function install_ipfs_go {
         mesh_install_ipfs_go
         return
     fi
-    if grep -Fxq "install_ipfs_go" $COMPLETION_FILE; then
+    if [[ $(app_is_installed ipfs_go) == "1" ]]; then
         return
     fi
 
@@ -590,7 +590,7 @@ function install_ipfs_go {
     function_check configure_firewall_for_ipfs
     configure_firewall_for_ipfs
 
-    echo 'install_ipfs_go' >> $COMPLETION_FILE
+    install_completed ipfs_go
 }
 
 function install_ipfs {
diff --git a/src/freedombone-app-irc b/src/freedombone-app-irc
index d01c49ef5..60bd7ec26 100755
--- a/src/freedombone-app-irc
+++ b/src/freedombone-app-irc
@@ -381,12 +381,12 @@ function install_irc_client {
 }
 
 function install_irc {
-    if grep -Fxq "install_irc" $COMPLETION_FILE; then
+    if [[ $(app_is_installed irc) == "1" ]]; then
         return
     fi
     install_irc_server
     install_irc_client
-    echo 'install_irc' >> $COMPLETION_FILE
+    install_completed irc
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-librevault b/src/freedombone-app-librevault
index 427a1043c..aa1e73dcc 100755
--- a/src/freedombone-app-librevault
+++ b/src/freedombone-app-librevault
@@ -231,7 +231,7 @@ function install_librevault {
         return
     fi
 
-    if grep -Fxq "install_librevalut" $COMPLETION_FILE; then
+    if [[ $(app_is_installed librevault) == "1" ]]; then
         return
     fi
 
@@ -327,7 +327,7 @@ function install_librevault {
     systemctl enable librevault-daemon
     systemctl start librevault-daemon
 
-    echo 'install_librevault' >> $COMPLETION_FILE
+    install_completed librevault
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-mediagoblin b/src/freedombone-app-mediagoblin
index 92d4b2a38..729a7c348 100755
--- a/src/freedombone-app-mediagoblin
+++ b/src/freedombone-app-mediagoblin
@@ -115,7 +115,7 @@ function install_mediagoblin {
         chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
     fi
 
-    if grep -Fxq "install_mediagoblin" $COMPLETION_FILE; then
+    if [[ $(app_is_installed mediagoblin) == "1" ]]; then
         return
     fi
 
@@ -427,7 +427,7 @@ function install_mediagoblin {
         sed -i "s/Mediagoblin domain.*/Mediagoblin domain:$MEDIAGOBLIN_DOMAIN_NAME/g" $COMPLETION_FILE
     fi
 
-    echo 'install_mediagoblin' >> $COMPLETION_FILE
+    install_completed mediagoblin
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-mumble b/src/freedombone-app-mumble
index 1f843d3a1..b52a2467d 100755
--- a/src/freedombone-app-mumble
+++ b/src/freedombone-app-mumble
@@ -201,10 +201,7 @@ function configure_firewall_for_voip {
 }
 
 function install_mumble {
-    if grep -Fxq "install_mumble" $COMPLETION_FILE; then
-        return
-    fi
-    if grep -Fxq "install_voip" $COMPLETION_FILE; then
+    if [[ $(app_is_installed mumble) == "1" ]]; then
         return
     fi
     apt-get -y install mumble-server
@@ -297,7 +294,7 @@ function install_mumble {
 
     function_check configure_firewall_for_voip
     configure_firewall_for_voip
-    echo 'install_mumble' >> $COMPLETION_FILE
+    install_completed mumble
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-rss b/src/freedombone-app-rss
index 2376722a8..4a310c9c9 100755
--- a/src/freedombone-app-rss
+++ b/src/freedombone-app-rss
@@ -621,13 +621,13 @@ function install_rss_mobile_reader {
 }
 
 function install_rss {
-    if grep -Fxq "install_rss" $COMPLETION_FILE; then
+    if [[ $(app_is_installed rss) == "1" ]]; then
         return
     fi
     install_rss_main
     install_rss_gnusocial
     install_rss_mobile_reader
-    echo 'install_rss' >> $COMPLETION_FILE
+    install_completed rss
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-searx b/src/freedombone-app-searx
index 9900c39fb..b948b7bd9 100755
--- a/src/freedombone-app-searx
+++ b/src/freedombone-app-searx
@@ -122,7 +122,7 @@ function install_searx {
         exit 62429
     fi
 
-    if grep -Fxq "install_searx" $COMPLETION_FILE; then
+    if [[ $(app_is_installed searx) == "1" ]]; then
         return
     fi
 
@@ -298,7 +298,7 @@ function install_searx {
         chmod 600 /home/$MY_USERNAME/README
     fi
 
-    echo 'install_searx' >> $COMPLETION_FILE
+    install_completed searx
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-sip b/src/freedombone-app-sip
index 89b8f2d3d..00506c1a1 100755
--- a/src/freedombone-app-sip
+++ b/src/freedombone-app-sip
@@ -449,12 +449,12 @@ function install_sip_turn {
 }
 
 function install_sip {
-    if grep -Fxq "install_sip" $COMPLETION_FILE; then
+    if [[ $(app_is_installed sip) == "1" ]]; then
         return
     fi
     install_sip_main
     update_sipwitch_daemon
-    echo 'install_sip' >> $COMPLETION_FILE
+    install_completed sip
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-syncthing b/src/freedombone-app-syncthing
index f936805a9..19d7c446d 100755
--- a/src/freedombone-app-syncthing
+++ b/src/freedombone-app-syncthing
@@ -470,7 +470,7 @@ function install_syncthing {
         return
     fi
 
-    if grep -Fxq "install_syncthing" $COMPLETION_FILE; then
+    if [[ $(app_is_installed syncthing) == "1" ]]; then
         return
     fi
 
@@ -508,7 +508,7 @@ function install_syncthing {
 
     function_check configure_firewall_for_syncthing
     configure_firewall_for_syncthing
-    echo 'install_syncthing' >> $COMPLETION_FILE
+    install_completed syncthing
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-tahoelafs b/src/freedombone-app-tahoelafs
index 7a50647e9..f448d1af7 100755
--- a/src/freedombone-app-tahoelafs
+++ b/src/freedombone-app-tahoelafs
@@ -292,7 +292,7 @@ function install_tahoelafs {
         return
     fi
 
-    if grep -Fxq "install_tahoelafs" $COMPLETION_FILE; then
+    if [[ $(app_is_installed tahoelafs) == "1" ]]; then
         return
     fi
 
@@ -358,7 +358,7 @@ function install_tahoelafs {
     systemctl daemon-reload
     systemctl start tahoelafs
 
-    echo 'install_tahoelafs' >> $COMPLETION_FILE
+    install_completed tahoelafs
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-tox b/src/freedombone-app-tox
index 40ac7a940..2f27771ca 100755
--- a/src/freedombone-app-tox
+++ b/src/freedombone-app-tox
@@ -666,7 +666,7 @@ function enable_tox_repo {
 
 function install_tox {
     if [ ! $INSTALLING_MESH ]; then
-        if grep -Fxq "install_tox" $COMPLETION_FILE; then
+        if [[ $(app_is_installed tox) == "1" ]]; then
             return
         fi
     fi
@@ -683,7 +683,7 @@ function install_tox {
         install_tox_client
     fi
 
-    echo 'install_tox' >> $COMPLETION_FILE
+    install_completed tox
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-vpn b/src/freedombone-app-vpn
index 0dc29b735..1ce70deaf 100755
--- a/src/freedombone-app-vpn
+++ b/src/freedombone-app-vpn
@@ -68,7 +68,7 @@ function remove_vpn {
 }
 
 function install_vpn {
-    if grep -Fxq "install_vpn" $COMPLETION_FILE; then
+    if [[ $(app_is_installed vpn) == "1" ]]; then
         return
     fi
     if ! grep -q "repo.universe-factory.net" /etc/apt/sources.list; then
@@ -84,7 +84,7 @@ function install_vpn {
             exit 52026
         fi
     fi
-    echo 'install_vpn' >> $COMPLETION_FILE
+    install_completed vpn
 }
 
 # NOTE: deliberately there is no "exit 0"
diff --git a/src/freedombone-app-webmail b/src/freedombone-app-webmail
index 7f9a048e0..34554d6bf 100755
--- a/src/freedombone-app-webmail
+++ b/src/freedombone-app-webmail
@@ -138,7 +138,7 @@ function remove_webmail {
 }
 
 function install_webmail {
-    if grep -Fxq "install_webmail" $COMPLETION_FILE; then
+    if [[ $(app_is_installed webmail) == "1" ]]; then
         return
     fi
     if [ -d /etc/apache2 ]; then
@@ -261,7 +261,7 @@ function install_webmail {
         chmod 600 /home/$MY_USERNAME/README
     fi
 
-    echo 'install_webmail' >> $COMPLETION_FILE
+    install_completed webmail
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-wiki b/src/freedombone-app-wiki
index ea057968b..478b1c803 100755
--- a/src/freedombone-app-wiki
+++ b/src/freedombone-app-wiki
@@ -178,7 +178,7 @@ function get_wiki_admin_password {
 }
 
 function install_wiki {
-    if grep -Fxq "install_wiki" $COMPLETION_FILE; then
+    if [[ $(app_is_installed wiki) == "1" ]]; then
         return
     fi
     if [ ! $WIKI_DOMAIN_NAME ]; then
@@ -539,7 +539,7 @@ function install_wiki {
     fi
 
     echo "Wiki domain:$WIKI_DOMAIN_NAME" >> $COMPLETION_FILE
-    echo 'install_wiki' >> $COMPLETION_FILE
+    install_completed wiki
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-xmpp b/src/freedombone-app-xmpp
index 0317b81c9..bb4343327 100755
--- a/src/freedombone-app-xmpp
+++ b/src/freedombone-app-xmpp
@@ -502,12 +502,12 @@ function install_xmpp_client {
 }
 
 function install_xmpp {
-    if grep -Fxq "install_xmpp" $COMPLETION_FILE; then
+    if [[ $(app_is_installed xmpp) == "1" ]]; then
         return
     fi
     install_xmpp_main
     install_xmpp_client
-    echo 'install_xmpp' >> $COMPLETION_FILE
+    install_completed xmpp
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-app-zeronet b/src/freedombone-app-zeronet
index 4c64a3559..bf14880b6 100755
--- a/src/freedombone-app-zeronet
+++ b/src/freedombone-app-zeronet
@@ -675,14 +675,14 @@ function install_zeronet {
         mesh_zeronet_forum
         return
     fi
-    if grep -Fxq "install_zeronet" $COMPLETION_FILE; then
+    if [[ $(app_is_installed zeronet) == "1" ]]; then
         return
     fi
     install_zeronet_main
     install_zeronet_blog
     install_zeronet_mail
     install_zeronet_forum
-    echo 'install_zeronet' >> $COMPLETION_FILE
+    install_completed zeronet
 }
 
 # NOTE: deliberately no exit 0
diff --git a/src/freedombone-utils-selector b/src/freedombone-utils-selector
index c65181994..718293d18 100755
--- a/src/freedombone-utils-selector
+++ b/src/freedombone-utils-selector
@@ -71,6 +71,13 @@ function app_is_installed {
     fi
 }
 
+function install_completed {
+    if [ ! ${1} ]; then
+        exit 673935
+    fi
+    echo "install_${1}" >> $COMPLETION_FILE
+}
+
 function get_apps_installed {
     for a in "${APPS_AVAILABLE[@]}"
     do
-- 
GitLab