From 8027616270e07e7839e43699163c701271404aee Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
Date: Wed, 29 Aug 2018 13:21:28 +0100
Subject: [PATCH] Admin username

---
 src/freedombone-installer | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/freedombone-installer b/src/freedombone-installer
index a2aab95c9..9570bc573 100755
--- a/src/freedombone-installer
+++ b/src/freedombone-installer
@@ -1140,6 +1140,8 @@ function backup_and_restore {
     if [ -f "$restore_file" ]; then
         rm "$restore_file"
 
+        ADMIN_USERNAME=$(grep 'MY_USERNAME=' "/root/${PROJECT_NAME}.cfg" | awk -F '=' '{print $2}')
+
         restore_title=$'Restore status'
         restore_failed_message=$"Restore failed. See http://${HOSTNAME}/admin/restore.txt for details"
         restore_success_message=$"Restore succeeded"
@@ -1154,10 +1156,10 @@ function backup_and_restore {
           echo 'backup_password=';
           echo 'if [ -f /tmp/backup_password.txt ]; then';
           echo "    backup_password=\$(cat /tmp/backup_password.txt)";
-          echo "    ${PROJECT_NAME}-pass -u admin -a simplebackup -p \"\$backup_password\"";
+          echo "    ${PROJECT_NAME}-pass -u \"$ADMIN_USERNAME\" -a simplebackup -p \"\$backup_password\"";
           echo '    rm /tmp/backup_password.txt';
           echo 'else';
-          echo "    backup_password=$(${PROJECT_NAME}-pass -u admin -a simplebackup)";
+          echo "    backup_password=\$(${PROJECT_NAME}-pass -u "$ADMIN_USERNAME" -a simplebackup)";
           echo 'fi';
           echo '';
           echo "if /usr/bin/timeout $APP_INSTALL_TIMEOUT_SEC /usr/local/bin/${PROJECT_NAME}-restore-local simple \"\$backup_password\" >> $webadmin_install_dir/restore.txt; then";
@@ -1183,6 +1185,8 @@ function backup_and_restore {
         if [ -f "$backup_file" ]; then
             rm "$backup_file"
 
+            ADMIN_USERNAME=$(grep 'MY_USERNAME=' "/root/${PROJECT_NAME}.cfg" | awk -F '=' '{print $2}')
+
             backup_title=$'Backup status'
             backup_failed_message=$"Backup failed. See http://${HOSTNAME}/admin/backup.txt for details"
             backup_success_message=$"Backup succeeded"
@@ -1204,7 +1208,7 @@ function backup_and_restore {
               echo 'backup_password=';
               echo 'if [ -f /tmp/backup_password.txt ]; then';
               echo "    backup_password=\$(cat /tmp/backup_password.txt)";
-              echo "    ${PROJECT_NAME}-pass -u admin -a simplebackup -p \"\$backup_password\"";
+              echo "    ${PROJECT_NAME}-pass -u \"$ADMIN_USERNAME\" -a simplebackup -p \"\$backup_password\"";
               echo '    rm /tmp/backup_password.txt';
               echo "    sed -i \"s|\\\"backup_password\\\".*|\\\"backup_password\\\" value=\\\"\$backup_password\\\"></p>|g\" $webadmin_install_dir/backup_password.html";
               echo "    sed -i \"s|\\\"backup_password_confirm\\\".*|\\\"backup_password_confirm\\\" value=\\\"\$backup_password\\\"></p>|g\" $webadmin_install_dir/backup_password.html";
@@ -1212,7 +1216,7 @@ function backup_and_restore {
               echo "    sed -i \"s|\\\"backup_password\\\".*|\\\"backup_password\\\" value=\\\"\$backup_password\\\"></p>|g\" $webadmin_install_dir/restore_password.html";
               echo "    chown www-data:www-data $webadmin_install_dir/restore_password.html";
               echo 'else';
-              echo "    backup_password=$(${PROJECT_NAME}-pass -u admin -a simplebackup)";
+              echo "    backup_password=\$(${PROJECT_NAME}-pass -u \"$ADMIN_USERNAME\" -a simplebackup)";
               echo 'fi';
               echo '';
               echo "if /usr/bin/timeout $APP_INSTALL_TIMEOUT_SEC /usr/local/bin/${PROJECT_NAME}-backup-local simple \"\$backup_password\" >> $webadmin_install_dir/backup.txt; then";
-- 
GitLab