From a5b1812e2891670be2be3f5674c596969a71c8d2 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@robotics.uk.to>
Date: Wed, 6 Jul 2016 16:47:55 +0100
Subject: [PATCH] Selecting apps from variant name

---
 src/freedombone-app-babel       |  3 ++-
 src/freedombone-app-batman      |  3 ++-
 src/freedombone-app-blog        |  2 ++
 src/freedombone-app-cjdns       |  3 ++-
 src/freedombone-app-dlna        |  2 ++
 src/freedombone-app-emacs       |  2 ++
 src/freedombone-app-gnusocial   |  2 ++
 src/freedombone-app-gogs        |  2 ++
 src/freedombone-app-hubzilla    |  2 ++
 src/freedombone-app-ipfs        |  2 ++
 src/freedombone-app-irc         |  2 ++
 src/freedombone-app-mediagoblin |  2 ++
 src/freedombone-app-mumble      |  2 ++
 src/freedombone-app-rss         |  2 ++
 src/freedombone-app-searx       |  2 ++
 src/freedombone-app-sip         |  2 ++
 src/freedombone-app-syncthing   |  2 ++
 src/freedombone-app-tox         |  2 ++
 src/freedombone-app-vpn         |  2 ++
 src/freedombone-app-webmail     |  2 ++
 src/freedombone-app-wiki        |  2 ++
 src/freedombone-app-xmpp        |  2 ++
 src/freedombone-app-zeronet     |  2 ++
 src/freedombone-utils-selector  | 44 +++++++++++++++++++++++++++++++++
 src/freedombone-utils-setup     | 13 +++++++---
 25 files changed, 99 insertions(+), 7 deletions(-)

diff --git a/src/freedombone-app-babel b/src/freedombone-app-babel
index 55b1e31ea..6cc383c26 100755
--- a/src/freedombone-app-babel
+++ b/src/freedombone-app-babel
@@ -28,7 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Babel mesh
+VARIANTS=''
+
 ENABLE_BABEL="no"
 BABEL_PORT=6696
 
diff --git a/src/freedombone-app-batman b/src/freedombone-app-batman
index 01525f5e1..d259c2d09 100755
--- a/src/freedombone-app-batman
+++ b/src/freedombone-app-batman
@@ -28,7 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# B.A.T.M.A.N settings
+VARIANTS='mesh'
+
 ENABLE_BATMAN="no"
 BATMAN_CELLID='any'
 
diff --git a/src/freedombone-app-blog b/src/freedombone-app-blog
index 671ec7cc3..838ad2c8e 100755
--- a/src/freedombone-app-blog
+++ b/src/freedombone-app-blog
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS="full writer"
+
 FULLBLOG_DOMAIN_NAME=
 FULLBLOG_CODE=
 FULLBLOG_ONION_PORT=8086
diff --git a/src/freedombone-app-cjdns b/src/freedombone-app-cjdns
index 35957ad78..963b76dcf 100755
--- a/src/freedombone-app-cjdns
+++ b/src/freedombone-app-cjdns
@@ -28,7 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# cjdns settings
+VARIANTS=''
+
 ENABLE_CJDNS="no"
 CJDNS_PRIVATE_KEY=
 CJDNS_PUBLIC_KEY=
diff --git a/src/freedombone-app-dlna b/src/freedombone-app-dlna
index 6744dd1b0..f8f11f335 100755
--- a/src/freedombone-app-dlna
+++ b/src/freedombone-app-dlna
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full media'
+
 function upgrade_dlna {
     echo ''
 }
diff --git a/src/freedombone-app-emacs b/src/freedombone-app-emacs
index f5861578d..0dd52745a 100755
--- a/src/freedombone-app-emacs
+++ b/src/freedombone-app-emacs
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='all'
+
 function upgrade_emacs {
     echo ''
 }
diff --git a/src/freedombone-app-gnusocial b/src/freedombone-app-gnusocial
index f47d972ce..df0fd0167 100755
--- a/src/freedombone-app-gnusocial
+++ b/src/freedombone-app-gnusocial
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full media'
+
 MICROBLOG_DOMAIN_NAME=
 MICROBLOG_CODE=
 MICROBLOG_ONION_PORT=8087
diff --git a/src/freedombone-app-gogs b/src/freedombone-app-gogs
index f5d4c2f20..51cd80888 100755
--- a/src/freedombone-app-gogs
+++ b/src/freedombone-app-gogs
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full developer'
+
 GIT_DOMAIN_NAME=
 GIT_CODE=
 GIT_ONION_PORT=8090
diff --git a/src/freedombone-app-hubzilla b/src/freedombone-app-hubzilla
index 7cdd30d51..afd06c442 100755
--- a/src/freedombone-app-hubzilla
+++ b/src/freedombone-app-hubzilla
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full social'
+
 HUBZILLA_DOMAIN_NAME=
 HUBZILLA_CODE=
 HUBZILLA_ONION_PORT=8085
diff --git a/src/freedombone-app-ipfs b/src/freedombone-app-ipfs
index 8a0607d12..690434b90 100755
--- a/src/freedombone-app-ipfs
+++ b/src/freedombone-app-ipfs
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='mesh'
+
 IPFS_GO_REPO="https://github.com/ipfs/go-ipfs"
 IPFS_COMMIT='20b06a4cbce8884f5b194da6e98cb11f2c77f166'
 IPFS_PORT=4001
diff --git a/src/freedombone-app-irc b/src/freedombone-app-irc
index 526c26c0f..bd0494f99 100755
--- a/src/freedombone-app-irc
+++ b/src/freedombone-app-irc
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full chat'
+
 IRC_PORT=6697
 IRC_ONION_PORT=6697
 
diff --git a/src/freedombone-app-mediagoblin b/src/freedombone-app-mediagoblin
index b5a8c8997..dae87f579 100755
--- a/src/freedombone-app-mediagoblin
+++ b/src/freedombone-app-mediagoblin
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS=''
+
 MEDIAGOBLIN_DOMAIN_NAME=
 MEDIAGOBLIN_CODE=
 MEDIAGOBLIN_REPO="git://git.savannah.gnu.org/mediagoblin.git"
diff --git a/src/freedombone-app-mumble b/src/freedombone-app-mumble
index 6d80eda70..971c4d4be 100755
--- a/src/freedombone-app-mumble
+++ b/src/freedombone-app-mumble
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full chat'
+
 # Password used for VoIP server
 VOIP_SERVER_PASSWORD=
 # Port on which VoIP server listens
diff --git a/src/freedombone-app-rss b/src/freedombone-app-rss
index f9270286f..e238e04f2 100755
--- a/src/freedombone-app-rss
+++ b/src/freedombone-app-rss
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full writer'
+
 RSS_READER_REPO="https://tt-rss.org/git/tt-rss.git"
 RSS_READER_COMMIT='9e84bab449f9ed55e02e60378b0af1521026f3b8'
 RSS_READER_ADMIN_PASSWORD=
diff --git a/src/freedombone-app-searx b/src/freedombone-app-searx
index cab470ebe..0a7ff61b4 100755
--- a/src/freedombone-app-searx
+++ b/src/freedombone-app-searx
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS=''
+
 SEARX_REPO="https://github.com/asciimoo/searx"
 SEARX_COMMIT='fee556c9904637051a9ba874ba7e71cd9f10789f'
 SEARX_PATH=/etc
diff --git a/src/freedombone-app-sip b/src/freedombone-app-sip
index c46984cd5..5eafbc42b 100755
--- a/src/freedombone-app-sip
+++ b/src/freedombone-app-sip
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full chat'
+
 SIP_SERVER_PASSWORD=
 SIP_PORT=5060
 SIP_TLS_PORT=5061
diff --git a/src/freedombone-app-syncthing b/src/freedombone-app-syncthing
index 5e46cc2c4..7a55226a5 100755
--- a/src/freedombone-app-syncthing
+++ b/src/freedombone-app-syncthing
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full cloud'
+
 SYNCTHING_ID=
 SYNCTHING_CONFIG_PATH=/root/.config/syncthing
 SYNCTHING_CONFIG_FILE=$SYNCTHING_CONFIG_PATH/config.xml
diff --git a/src/freedombone-app-tox b/src/freedombone-app-tox
index 68b762592..66ed8137e 100755
--- a/src/freedombone-app-tox
+++ b/src/freedombone-app-tox
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full chat'
+
 TOX_PORT=33445
 TOXCORE_REPO="git://github.com/irungentoo/toxcore.git"
 TOXCORE_COMMIT='532629d486e3361c7d8d95b38293cc7d61dc4ee5'
diff --git a/src/freedombone-app-vpn b/src/freedombone-app-vpn
index 85bc234d0..37facbe9c 100755
--- a/src/freedombone-app-vpn
+++ b/src/freedombone-app-vpn
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS=''
+
 function upgrade_vpn {
     echo ''
 }
diff --git a/src/freedombone-app-webmail b/src/freedombone-app-webmail
index cc1cdf358..9efd0380f 100755
--- a/src/freedombone-app-webmail
+++ b/src/freedombone-app-webmail
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS=''
+
 WEBMAIL_REPO="https://github.com/roundcube/roundcubemail"
 WEBMAIL_COMMIT='78cf9c2e5cff2d78cd8beb647d60570f195a2a9c'
 WEBMAIL_ONION_HOSTNAME=
diff --git a/src/freedombone-app-wiki b/src/freedombone-app-wiki
index db2a119f5..93345481e 100755
--- a/src/freedombone-app-wiki
+++ b/src/freedombone-app-wiki
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full writer'
+
 WIKI_DOMAIN_NAME=
 WIKI_ADMIN_PASSWORD=
 WIKI_TITLE="${PROJECT_NAME} Wiki"
diff --git a/src/freedombone-app-xmpp b/src/freedombone-app-xmpp
index 78374412b..252dcd145 100755
--- a/src/freedombone-app-xmpp
+++ b/src/freedombone-app-xmpp
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='full chat'
+
 # Directory where XMPP settings are stored
 XMPP_DIRECTORY="/var/lib/prosody"
 XMPP_PASSWORD=
diff --git a/src/freedombone-app-zeronet b/src/freedombone-app-zeronet
index 4e1528c2d..3f884f8a1 100755
--- a/src/freedombone-app-zeronet
+++ b/src/freedombone-app-zeronet
@@ -28,6 +28,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+VARIANTS='mesh'
+
 ZERONET_REPO="https://github.com/HelloZeroNet/ZeroNet.git"
 ZERONET_COMMIT='675bd462556c541d65e2d95f91f899146a373aad'
 ZERONET_BLOG_REPO="https://github.com/HelloZeroNet/ZeroBlog"
diff --git a/src/freedombone-utils-selector b/src/freedombone-utils-selector
index 53b57426c..3b6984895 100755
--- a/src/freedombone-utils-selector
+++ b/src/freedombone-utils-selector
@@ -82,6 +82,50 @@ function detect_apps {
 	get_apps_installed
 }
 
+# creates the APPS_AVAILABLE and APPS_CHOSEN arrays based on
+# the given variant name
+function choose_apps_for_variant {
+	variant_name="$1"
+
+	FILES=$PROJECT_INSTALL_DIR/${PROJECT_NAME}-app-*
+
+	APPS_AVAILABLE=()
+	APPS_CHOSEN=()
+
+	# for all the app scripts
+	for filename in $FILES
+	do
+		app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
+		if [[ $(item_in_array ${app_name} ${APPS_AVAILABLE[@]}) != 0 ]]; then
+			APPS_AVAILABLE+=("${app_name}")
+
+			if grep -q "VARIANTS=" ${filename}; then
+				variants_list=$(cat ${filename} | grep "VARIANTS=" | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
+				if [[ ${variants_list} == "$variant_name "* || ${variants_list} == *" $variant_name "* || ${variants_list} == *" $variant_name" ]]; then
+					APPS_CHOSEN+=("1")
+				else
+					APPS_CHOSEN+=("0")
+				fi
+			else
+				APPS_CHOSEN+=("0")
+			fi
+
+		fi
+	done
+	get_apps_installed
+}
+
+function list_chosen_apps {
+	app_index=0
+	for a in "${APPS_AVAILABLE[@]}"
+	do
+		if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
+			echo $"${a}"
+		fi
+		app_index=$[app_index+1]
+	done
+}
+
 function remove_apps {
 	app_index=0
 	for a in "${APPS_AVAILABLE[@]}"
diff --git a/src/freedombone-utils-setup b/src/freedombone-utils-setup
index 0ca307611..2293b8177 100755
--- a/src/freedombone-utils-setup
+++ b/src/freedombone-utils-setup
@@ -319,10 +319,15 @@ function setup_web {
 }
 
 function setup_apps {
-	function_check detect_apps
-	detect_apps
-
-	# TODO choose apps based upon variants
+	function_check choose_apps_for_variant
+	choose_apps_for_variant "$SYSTEM_TYPE"
+
+	echo $"System variant: $SYSTEM_TYPE"
+	echo $'The following apps have been selected'
+	echo ''
+	function_check list_chosen_apps
+	list_chosen_apps
+	echo ''
 
 	function_check install_apps
 	install_apps
-- 
GitLab