From 9083b43a67467e9cc7d07ae0d88f55d483055007 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@robotics.uk.to>
Date: Tue, 26 Dec 2017 21:11:22 +0000
Subject: [PATCH] Ensure that default fbone user gets removed on first boot of
 the non-mesh system

---
 src/freedombone-utils-final | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/freedombone-utils-final b/src/freedombone-utils-final
index 0dedf6379..c38b4a826 100755
--- a/src/freedombone-utils-final
+++ b/src/freedombone-utils-final
@@ -91,10 +91,46 @@ function update_installed_apps_list {
     cat $COMPLETION_FILE | grep "install_" > /usr/share/${PROJECT_NAME}/installed.txt
 }
 
+function create_default_user_removal_daemon {
+    # This daemon runs on first boot and removes the default fbone user
+
+    first_start_daemon_filename=/etc/systemd/system/firststart.service
+    first_start_script=/usr/local/bin/firststart
+    echo '#!/bin/bash' > $first_start_script
+    echo 'if [ -d /home/fbone]; then' >> $first_start_script
+    echo '    userdel -r fbone' >> $first_start_script
+    echo '    if [ -d /home/fbone]; then' >> $first_start_script
+    echo '        rm -rf /home/fbone' >> $first_start_script
+    echo '    fi' >> $first_start_script
+    echo 'fi' >> $first_start_script
+    echo 'systemctl disable firststart' >> $first_start_script
+    echo "rm $first_start_daemon_filename" >> $first_start_script
+    chmod +x $first_start_script
+
+    echo '[Unit]' > $first_start_daemon_filename
+    echo 'Description=Daemon run on first boot' >> $first_start_daemon_filename
+    echo 'After=syslog.target' >> $first_start_daemon_filename
+    echo 'After=network.target' >> $first_start_daemon_filename
+    echo '' >> $first_start_daemon_filename
+    echo '[Service]' >> $first_start_daemon_filename
+    echo 'User=root' >> $first_start_daemon_filename
+    echo 'Group=root' >> $first_start_daemon_filename
+    echo "ExecStart=$first_start_script" >> $first_start_daemon_filename
+    echo 'StandardOutput=syslog' >> $first_start_daemon_filename
+    echo 'StandardError=syslog' >> $first_start_daemon_filename
+    echo '' >> $first_start_daemon_filename
+    echo '[Install]' >> $first_start_daemon_filename
+    echo 'WantedBy=multi-user.target' >> $first_start_daemon_filename
+    systemctl enable firststart
+}
+
 function setup_final {
     function_check update_installed_apps_list
     update_installed_apps_list
 
+    function_check create_default_user_removal_daemon
+    create_default_user_removal_daemon
+
     function_check install_tripwire
     install_tripwire
 
-- 
GitLab