From ee2dd373ef3f6f151b67113d99556a2ff79e068c Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob.mottram@codethink.co.uk>
Date: Mon, 6 Jun 2016 17:31:23 +0100
Subject: [PATCH] Beginning of usb client builds with user interfaces

---
 src/freedombone-image           |  7 -------
 src/freedombone-image-customise | 29 ++++++++++++++++++++++++-----
 src/freedombone-image-make      | 10 ++++++++++
 3 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/src/freedombone-image b/src/freedombone-image
index c36d72bb..828015c7 100755
--- a/src/freedombone-image
+++ b/src/freedombone-image
@@ -285,13 +285,6 @@ if [[ $GENERIC_IMAGE == "yes" ]]; then
 	PASSWORD=$GENERIC_IMAGE_PASSWORD
 fi
 
-# If this is a mesh variant then create an appropriate script
-#if [[ $VARIANT == "mesh"* ]]; then
-#CONFIG_FILENAME=/tmp/${PROJECT_NAME}_mesh.cfg
-#mesh_router_setup_script $CONFIG_FILENAME
-#DEFAULT_DOMAIN_NAME=$(cat $CONFIG_FILENAME | grep 'DEFAULT_DOMAIN_NAME' | awk -F '=' '{print $2}')
-#fi
-
 if [ ! $PASSWORD ]; then
 	# generate a random password
 	PASSWORD="$(openssl rand -base64 30 | cut -c1-${MINIMUM_PASSWORD_LENGTH})"
diff --git a/src/freedombone-image-customise b/src/freedombone-image-customise
index 401171dc..2b73ef27 100755
--- a/src/freedombone-image-customise
+++ b/src/freedombone-image-customise
@@ -242,7 +242,7 @@ create_generic_image() {
 	fi
 
 	# Don't install any configuration. This will be a base system
-	if [[ $VARIANT != "mesh" ]]; then
+	if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" ]]; then
 		CONFIG_FILENAME=
 	else
 		touch $rootdir/root/.initial_mesh_setup
@@ -319,7 +319,7 @@ EOF
 	echo "    git pull" >> $rootdir/root/.bashrc
 	echo "    make install" >> $rootdir/root/.bashrc
 
-	if [[ $VARIANT != "mesh" ]]; then
+	if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "usb" ]]; then
 		if [[ $ONION_ONLY == "no" ]]; then
 			if [[ $MINIMAL_INSTALL == "no" ]]; then
 				echo "    ${PROJECT_NAME} menuconfig-full" >> $rootdir/root/.bashrc
@@ -340,7 +340,7 @@ EOF
 	echo "            touch /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
 	echo '            shred -zu ~/login.txt' >> $rootdir/root/.bashrc
 	END_MESSAGE1=$'Congratulations!'
-	if [[ $VARIANT != "mesh" ]]; then
+	if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" && $VARIANT != "usb" ]]; then
 		END_MESSAGE2=$'\nYour system has now installed\n\nThe onion ssh service is at $SSH_ONION_HOSTNAME\n\nPress any key to reboot and begin using it'
 		echo '            SSH_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_ssh/hostname)' >> $rootdir/root/.bashrc
 	else
@@ -400,7 +400,7 @@ atheros_wifi() {
 }
 
 configure_wifi() {
-	if [[ $VARIANT == "mesh" ]]; then
+	if [[ $VARIANT == "mesh" || $VARIANT == "meshclient" ]]; then
 		return
 	fi
 
@@ -953,7 +953,10 @@ function mesh_zeronet {
 }
 
 initialise_mesh() {
-	if [[ $VARIANT != "mesh" || $DEBIAN_INSTALL_ONLY != "no" ]]; then
+	if [[ $VARIANT != "mesh" && $VARIANT != "meshclient" ]]; then
+		return
+	fi
+	if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
 		return
 	fi
 
@@ -986,6 +989,21 @@ initialise_mesh() {
 	chroot "$rootdir" systemctl enable $MESH_SERVICE
 }
 
+# User interface for USB drive installs ######################################
+
+function configure_user_interface {
+	if [[ $VARIANT != "meshclient" && $VARIANT != "usb" ]]; then
+		return
+	fi
+
+	chroot "$rootdir" apt-get -y install mate-desktop-environment
+
+	if [[ $VARIANT == "usb" ]]; then
+		chroot "$rootdir" apt-get -y install tor
+		# TODO
+	fi
+}
+
 ##############################################################################
 
 
@@ -1110,6 +1128,7 @@ atheros_wifi
 continue_installation
 initialise_mesh
 configure_wifi
+configure_user_interface
 
 cd /
 echo $"info: killing leftover processes in chroot"
diff --git a/src/freedombone-image-make b/src/freedombone-image-make
index e79f3ad9..bdb21489 100755
--- a/src/freedombone-image-make
+++ b/src/freedombone-image-make
@@ -126,6 +126,16 @@ case "$MACHINE" in
 		extra_opts="\
  --grub \
  --roottype btrfs \
+"   ;;
+	usb)
+		extra_opts="\
+ --grub \
+ --roottype btrfs \
+"   ;;
+	meshclient)
+		extra_opts="\
+ --grub \
+ --roottype btrfs \
 "   ;;
 	all)
 		extra_opts="\