Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions recovery/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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");

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) */
backupFile("/mnt/wpa_supplicant.conf");

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");
Expand Down
1 change: 1 addition & 0 deletions recovery/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions recovery/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ void putFileContents(const QString &filename, const QByteArray &data)
f.close();
}

bool backupFile(const QString &filename, const QString &ext)
{
QString backupName = filename + "." + ext;

if (QFile::exists(backupName))
{
QFile::remove(backupName);
}
return QFile::rename(filename,backupName);
}

/* Utility function to query current overscan setting */
#define VCMSG_GET_OVERSCAN 0x0004000a
#define VCMSG_SET_OVERSCAN 0x0004800a
Expand Down
1 change: 1 addition & 0 deletions recovery/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

QByteArray getFileContents(const QString &filename);
void putFileContents(const QString &filename, const QByteArray &data);
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();
Expand Down