From 00d9dc8deb094b45a85df40a5cc323f8cf54a957 Mon Sep 17 00:00:00 2001 From: procount Date: Wed, 31 Jan 2018 14:50:09 +0000 Subject: [PATCH 1/6] Change wpa_supplicant copy --- recovery/mainwindow.cpp | 46 ++++++++++++++++++++++++++++++----------- recovery/mainwindow.h | 1 + 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/recovery/mainwindow.cpp b/recovery/mainwindow.cpp index a2d24242..422e47b5 100644 --- a/recovery/mainwindow.cpp +++ b/recovery/mainwindow.cpp @@ -215,6 +215,9 @@ MainWindow::MainWindow(const QString &drive, const QString &defaultDisplay, QSpl { _fixate = true; } + + copywpa(); + if (cmdline.contains("silentinstall")) { /* If silentinstall is specified, auto-install single image in /os */ @@ -951,29 +954,48 @@ void MainWindow::on_list_doubleClicked(const QModelIndex &index) } } -void MainWindow::startNetworking() +void MainWindow::copyWpa() { + //This file is the one used by dhcpcd QFile f("/settings/wpa_supplicant.conf"); - if ( f.exists() && f.size() == 0 ) { /* Remove corrupt file */ f.remove(); } - if ( !f.exists() ) + + /* If user supplied a wpa_supplicant.conf on the FAT partition copy that one to settings regardless */ + if (QFile::exists("/mnt/wpa_supplicant.conf")) { - /* If user supplied a wpa_supplicant.conf on the FAT partition copy that one to settings - otherwise copy the default one stored in the initramfs */ - if (QFile::exists("/mnt/wpa_supplicant.conf")) - QFile::copy("/mnt/wpa_supplicant.conf", "/settings/wpa_supplicant.conf"); - else - { - qDebug() << "Copying /etc/wpa_supplicant.conf to /settings/wpa_supplicant.conf"; - QFile::copy("/etc/wpa_supplicant.conf", "/settings/wpa_supplicant.conf"); - } + qDebug() << "Copying user wpa_supplicant.conf to /settings/wpa_supplicant.conf"; + + QProcess::execute("mount -o remount,rw /settings"); + QProcess::execute("mount -o remount,rw /mnt"); + + QFile::remove("/settings/wpa_supplicant.conf.bak"); + QFile::rename("/settings/wpa_supplicant.conf","/settings/wpa_supplicant.conf.bak"); + QFile::copy("/mnt/wpa_supplicant.conf", "/settings/wpa_supplicant.conf"); + f.setPermissions( QFile::WriteUser | QFile::ReadGroup | QFile::ReadOther | QFile::ReadUser ); + + /* rename the user file to avoid overwriting any manually set SSIDs */ + QFile::remove("/mnt/wpa_supplicant.conf.bak"); + QFile::rename("/mnt/wpa_supplicant.conf","/mnt/wpa_supplicant.conf.bak"); + + QProcess::execute("sync"); + QProcess::execute("mount -o remount,ro /settings"); + QProcess::execute("mount -o remount,ro /mnt"); + } + else if ( !f.exists() ) + { + /* There is no existing file, must be first installation */ + qDebug() << "Copying /etc/wpa_supplicant.conf to /settings/wpa_supplicant.conf"; + QFile::copy("/etc/wpa_supplicant.conf", "/settings/wpa_supplicant.conf"); } QFile::remove("/etc/wpa_supplicant.conf"); +} +void MainWindow::startNetworking() +{ /* Enable dbus so that we can use it to talk to wpa_supplicant later */ qDebug() << "Starting dbus"; QProcess::execute("/etc/init.d/S30dbus start"); diff --git a/recovery/mainwindow.h b/recovery/mainwindow.h index f5eecf92..78759492 100644 --- a/recovery/mainwindow.h +++ b/recovery/mainwindow.h @@ -78,6 +78,7 @@ class MainWindow : public QMainWindow bool isSupportedOs(const QString &name, const QVariantMap &values); void addImagesFromUSB(const QString &device); void filterList(); + void copyWpa(); protected slots: void populate(); From 669492631b666d4f8675ed2960b027a328f7cd4a Mon Sep 17 00:00:00 2001 From: procount Date: Fri, 2 Mar 2018 17:17:53 +0000 Subject: [PATCH 2/6] Improve copyWpa --- recovery/mainwindow.cpp | 14 +++++++------- recovery/util.cpp | 11 +++++++++++ recovery/util.h | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/recovery/mainwindow.cpp b/recovery/mainwindow.cpp index 422e47b5..b0c73546 100644 --- a/recovery/mainwindow.cpp +++ b/recovery/mainwindow.cpp @@ -216,7 +216,7 @@ MainWindow::MainWindow(const QString &drive, const QString &defaultDisplay, QSpl _fixate = true; } - copywpa(); + copyWpa(); if (cmdline.contains("silentinstall")) { @@ -954,6 +954,7 @@ void MainWindow::on_list_doubleClicked(const QModelIndex &index) } } + void MainWindow::copyWpa() { //This file is the one used by dhcpcd @@ -967,19 +968,18 @@ void MainWindow::copyWpa() /* If user supplied a wpa_supplicant.conf on the FAT partition copy that one to settings regardless */ if (QFile::exists("/mnt/wpa_supplicant.conf")) { - qDebug() << "Copying user wpa_supplicant.conf to /settings/wpa_supplicant.conf"; + qDebug() << "Copying user wpa_supplicant.conf to /settings/wpa_supplicant.conf"; QProcess::execute("mount -o remount,rw /settings"); QProcess::execute("mount -o remount,rw /mnt"); - QFile::remove("/settings/wpa_supplicant.conf.bak"); - QFile::rename("/settings/wpa_supplicant.conf","/settings/wpa_supplicant.conf.bak"); + backup("/settings/wpa_supplicant.conf"); QFile::copy("/mnt/wpa_supplicant.conf", "/settings/wpa_supplicant.conf"); f.setPermissions( QFile::WriteUser | QFile::ReadGroup | QFile::ReadOther | QFile::ReadUser ); - /* rename the user file to avoid overwriting any manually set SSIDs */ - QFile::remove("/mnt/wpa_supplicant.conf.bak"); - QFile::rename("/mnt/wpa_supplicant.conf","/mnt/wpa_supplicant.conf.bak"); + /* rename the user file to indicate that it has been copied (and prevent it being re-copied next time, + which could potentially overwrite any SSIDs created in the NOOBS GUI) */ + backup("/mnt/wpa_supplicant.conf"); QProcess::execute("sync"); QProcess::execute("mount -o remount,ro /settings"); diff --git a/recovery/util.cpp b/recovery/util.cpp index ef6bf2a5..03b61eb1 100644 --- a/recovery/util.cpp +++ b/recovery/util.cpp @@ -39,6 +39,17 @@ void putFileContents(const QString &filename, const QByteArray &data) f.close(); } +bool backup(QString filename, QString ext) +{ + + QString backupName = filename + "." + ext; + const char * backupFile = backupName.toUtf8().constData(); + if( access( backupFile, F_OK ) != -1 ) { + remove(backupFile); + } + return rename(filename.toUtf8().constData(), backupFile); +} + /* Utility function to query current overscan setting */ #define VCMSG_GET_OVERSCAN 0x0004000a #define VCMSG_SET_OVERSCAN 0x0004800a diff --git a/recovery/util.h b/recovery/util.h index 100778e0..7fc5dec0 100644 --- a/recovery/util.h +++ b/recovery/util.h @@ -16,6 +16,7 @@ QByteArray getFileContents(const QString &filename); void putFileContents(const QString &filename, const QByteArray &data); +bool backup(QString filename, QString ext="bak"); void getOverscan(int &top, int &bottom, int &left, int &right); bool nameMatchesRiscOS(const QString &name); uint readBoardRevision(); From f8326b82a1030944539a7b02b9f3eebecb615a68 Mon Sep 17 00:00:00 2001 From: procount Date: Sat, 3 Mar 2018 18:15:24 +0000 Subject: [PATCH 3/6] Reverted to QT style --- recovery/util.cpp | 12 ++++++------ recovery/util.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/recovery/util.cpp b/recovery/util.cpp index 03b61eb1..0247eab0 100644 --- a/recovery/util.cpp +++ b/recovery/util.cpp @@ -39,15 +39,15 @@ void putFileContents(const QString &filename, const QByteArray &data) f.close(); } -bool backup(QString filename, QString ext) +bool backup(const QString &filename, const QString &ext) { - QString backupName = filename + "." + ext; - const char * backupFile = backupName.toUtf8().constData(); - if( access( backupFile, F_OK ) != -1 ) { - remove(backupFile); + + if (QFile::exists(backupName)) + { + QFile::remove(backupName); } - return rename(filename.toUtf8().constData(), backupFile); + return QFile::rename(filename,backupName); } /* Utility function to query current overscan setting */ diff --git a/recovery/util.h b/recovery/util.h index 7fc5dec0..56b7a086 100644 --- a/recovery/util.h +++ b/recovery/util.h @@ -16,7 +16,7 @@ QByteArray getFileContents(const QString &filename); void putFileContents(const QString &filename, const QByteArray &data); -bool backup(QString filename, QString ext="bak"); +bool backup(const QString &filename, const QString &ext="bak"); void getOverscan(int &top, int &bottom, int &left, int &right); bool nameMatchesRiscOS(const QString &name); uint readBoardRevision(); From 88d150c38566034cac429284f1e9892f5d73a47a Mon Sep 17 00:00:00 2001 From: procount Date: Sun, 4 Mar 2018 18:03:43 +0000 Subject: [PATCH 4/6] Update util.h Changed backup ->backupFile --- recovery/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recovery/util.h b/recovery/util.h index 56b7a086..fa954add 100644 --- a/recovery/util.h +++ b/recovery/util.h @@ -16,7 +16,7 @@ QByteArray getFileContents(const QString &filename); void putFileContents(const QString &filename, const QByteArray &data); -bool backup(const QString &filename, const QString &ext="bak"); +bool backupFile(const QString &filename, const QString &ext="bak"); void getOverscan(int &top, int &bottom, int &left, int &right); bool nameMatchesRiscOS(const QString &name); uint readBoardRevision(); From 49f52d0314cd6c9008de6a08947811573f063dfe Mon Sep 17 00:00:00 2001 From: procount Date: Sun, 4 Mar 2018 18:04:43 +0000 Subject: [PATCH 5/6] Update util.cpp Changed backup -> backupFile --- recovery/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recovery/util.cpp b/recovery/util.cpp index 0247eab0..1846030d 100644 --- a/recovery/util.cpp +++ b/recovery/util.cpp @@ -39,7 +39,7 @@ void putFileContents(const QString &filename, const QByteArray &data) f.close(); } -bool backup(const QString &filename, const QString &ext) +bool backupFile(const QString &filename, const QString &ext) { QString backupName = filename + "." + ext; From fad64879626f0cabbf9f3874ca5170bdd9b8ec0b Mon Sep 17 00:00:00 2001 From: procount Date: Sun, 4 Mar 2018 18:07:22 +0000 Subject: [PATCH 6/6] Update mainwindow.cpp Changed backup -> backupFile --- recovery/mainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recovery/mainwindow.cpp b/recovery/mainwindow.cpp index b0c73546..747b77cc 100644 --- a/recovery/mainwindow.cpp +++ b/recovery/mainwindow.cpp @@ -973,13 +973,13 @@ void MainWindow::copyWpa() QProcess::execute("mount -o remount,rw /settings"); QProcess::execute("mount -o remount,rw /mnt"); - backup("/settings/wpa_supplicant.conf"); + backupFile("/settings/wpa_supplicant.conf"); QFile::copy("/mnt/wpa_supplicant.conf", "/settings/wpa_supplicant.conf"); f.setPermissions( QFile::WriteUser | QFile::ReadGroup | QFile::ReadOther | QFile::ReadUser ); /* rename the user file to indicate that it has been copied (and prevent it being re-copied next time, which could potentially overwrite any SSIDs created in the NOOBS GUI) */ - backup("/mnt/wpa_supplicant.conf"); + backupFile("/mnt/wpa_supplicant.conf"); QProcess::execute("sync"); QProcess::execute("mount -o remount,ro /settings");