From b587a0ff004696ad63bcabca7c5e62fed8ac5c9c Mon Sep 17 00:00:00 2001 From: Rohan Garg Date: Tue, 21 Oct 2014 18:59:02 +0200 Subject: [PATCH 1/4] Add support to set the hostname --- src/modules/users/CMakeLists.txt | 1 + src/modules/users/SetHostNameJob.cpp | 69 ++++++++++++++++++++++++++++ src/modules/users/SetHostNameJob.h | 37 +++++++++++++++ src/modules/users/UsersPage.cpp | 8 +++- 4 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 src/modules/users/SetHostNameJob.cpp create mode 100644 src/modules/users/SetHostNameJob.h diff --git a/src/modules/users/CMakeLists.txt b/src/modules/users/CMakeLists.txt index 4d4ef208f..fc1f26d0f 100644 --- a/src/modules/users/CMakeLists.txt +++ b/src/modules/users/CMakeLists.txt @@ -11,6 +11,7 @@ calamares_add_plugin( users SetPasswordJob.cpp UsersViewStep.cpp UsersPage.cpp + SetHostNameJob.cpp UI page_usersetup.ui RESOURCES diff --git a/src/modules/users/SetHostNameJob.cpp b/src/modules/users/SetHostNameJob.cpp new file mode 100644 index 000000000..50efe644c --- /dev/null +++ b/src/modules/users/SetHostNameJob.cpp @@ -0,0 +1,69 @@ +/* + * + * Copyright (C) 2014 Rohan Garg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "SetHostNameJob.h" + +#include "GlobalStorage.h" +#include "utils/Logger.h" +#include "JobQueue.h" + +#include +#include + +SetHostNameJob::SetHostNameJob(const QString& hostname) + : Calamares::Job() + , m_hostname(hostname) +{ +} + +QString SetHostNameJob::prettyName() const +{ + return tr( "Set hostname %1" ).arg( m_hostname ); +} + +Calamares::JobResult SetHostNameJob::exec() +{ + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + + if ( !gs || !gs->contains( "rootMountPoint" ) ) + { + cLog() << "No rootMountPoint in global storage"; + return Calamares::JobResult::error( tr( "Internal Error" ) ); + } + + QString destDir = gs->value( "rootMountPoint" ).toString(); + if ( !QDir( destDir ).exists() ) + { + cLog() << "rootMountPoint points to a dir which does not exist"; + return Calamares::JobResult::error( tr( "Internal Error" ) ); + } + + QFile hostfile(destDir + "/etc/hostname"); + if (!hostfile.open(QFile::WriteOnly)) + { + cLog() << "Can't write to hostname file"; + return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) ); + } + + QTextStream out(&hostfile); + out << m_hostname << "\n"; + hostfile.close(); + + return Calamares::JobResult::ok(); +} diff --git a/src/modules/users/SetHostNameJob.h b/src/modules/users/SetHostNameJob.h new file mode 100644 index 000000000..9f5a5cbae --- /dev/null +++ b/src/modules/users/SetHostNameJob.h @@ -0,0 +1,37 @@ +/* + * + * Copyright (C) 2014 Rohan Garg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef SETHOSTNAMEJOB_CPP_H +#define SETHOSTNAMEJOB_CPP_H + +#include + +class SetHostNameJob : public Calamares::Job +{ + Q_OBJECT +public: + SetHostNameJob(const QString &hostname); + QString prettyName() const override; + Calamares::JobResult exec() override; +private: + const QString m_hostname; +}; + + +#endif // SETHOSTNAMEJOB_CPP_H diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 3b44814fd..db4c577cf 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -24,6 +24,7 @@ #include "ui_page_usersetup.h" #include "CreateUserJob.h" #include "SetPasswordJob.h" +#include "SetHostNameJob.h" #include "JobQueue.h" #include "GlobalStorage.h" #include "utils/Logger.h" @@ -109,6 +110,9 @@ UsersPage::createJobs( const QString& defaultUserGroup, const QStringList& defau ui->textBoxRootPassword->text() ); list.append( Calamares::job_ptr( j ) ); + j = new SetHostNameJob( ui->textBoxHostname->text() ); + list.append( Calamares::job_ptr( j ) ); + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); gs->insert( "hostname", ui->textBoxHostname->text() ); if ( ui->checkBoxLoginAuto->isChecked() ) @@ -270,11 +274,11 @@ UsersPage::validateHostnameText( const QString& textRef ) if ( pos >= 0 && pos < text.size() ) ui->labelHostnameError->setText( - tr( "Your username contains an invalid character '%1'" ) + tr( "Your hostname contains an invalid character '%1'" ) .arg( text.at( pos ) ) ); else ui->labelHostnameError->setText( - tr( "Your username contains invalid characters!" ) ); + tr( "Your hostname contains invalid characters!" ) ); m_readyHostname = false; } From 4a4dc74f5cdff0b6f85342d7c1fd0c750b31f5f5 Mon Sep 17 00:00:00 2001 From: Rohan Garg Date: Wed, 22 Oct 2014 15:54:07 +0200 Subject: [PATCH 2/4] Drop useless line --- src/modules/users/SetHostNameJob.cpp | 1 - src/modules/users/SetHostNameJob.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/modules/users/SetHostNameJob.cpp b/src/modules/users/SetHostNameJob.cpp index 50efe644c..6f7c0c626 100644 --- a/src/modules/users/SetHostNameJob.cpp +++ b/src/modules/users/SetHostNameJob.cpp @@ -1,5 +1,4 @@ /* - * * Copyright (C) 2014 Rohan Garg * * This program is free software: you can redistribute it and/or modify diff --git a/src/modules/users/SetHostNameJob.h b/src/modules/users/SetHostNameJob.h index 9f5a5cbae..f87ac0077 100644 --- a/src/modules/users/SetHostNameJob.h +++ b/src/modules/users/SetHostNameJob.h @@ -1,5 +1,4 @@ /* - * * Copyright (C) 2014 Rohan Garg * * This program is free software: you can redistribute it and/or modify From a0a3b4dc49095260af283a164262ee736c65e9a8 Mon Sep 17 00:00:00 2001 From: Rohan Garg Date: Mon, 27 Oct 2014 16:53:57 +0100 Subject: [PATCH 3/4] Style fixes Run calamaresstyle over new classes --- src/modules/users/SetHostNameJob.cpp | 24 ++++++++++++------------ src/modules/users/SetHostNameJob.h | 14 +++++++------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/modules/users/SetHostNameJob.cpp b/src/modules/users/SetHostNameJob.cpp index 6f7c0c626..5b04de1ac 100644 --- a/src/modules/users/SetHostNameJob.cpp +++ b/src/modules/users/SetHostNameJob.cpp @@ -1,19 +1,19 @@ /* * Copyright (C) 2014 Rohan Garg - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * */ #include "SetHostNameJob.h" @@ -25,21 +25,21 @@ #include #include -SetHostNameJob::SetHostNameJob(const QString& hostname) +SetHostNameJob::SetHostNameJob( const QString& hostname ) : Calamares::Job() - , m_hostname(hostname) + , m_hostname( hostname ) { } QString SetHostNameJob::prettyName() const { - return tr( "Set hostname %1" ).arg( m_hostname ); + return tr( "Set hostname %1" ).arg( m_hostname ); } Calamares::JobResult SetHostNameJob::exec() { Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - + if ( !gs || !gs->contains( "rootMountPoint" ) ) { cLog() << "No rootMountPoint in global storage"; @@ -53,16 +53,16 @@ Calamares::JobResult SetHostNameJob::exec() return Calamares::JobResult::error( tr( "Internal Error" ) ); } - QFile hostfile(destDir + "/etc/hostname"); - if (!hostfile.open(QFile::WriteOnly)) + QFile hostfile( destDir + "/etc/hostname" ); + if ( !hostfile.open( QFile::WriteOnly ) ) { cLog() << "Can't write to hostname file"; return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) ); } - QTextStream out(&hostfile); + QTextStream out( &hostfile ); out << m_hostname << "\n"; hostfile.close(); - + return Calamares::JobResult::ok(); } diff --git a/src/modules/users/SetHostNameJob.h b/src/modules/users/SetHostNameJob.h index f87ac0077..2f32063ff 100644 --- a/src/modules/users/SetHostNameJob.h +++ b/src/modules/users/SetHostNameJob.h @@ -1,19 +1,19 @@ /* * Copyright (C) 2014 Rohan Garg - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * */ #ifndef SETHOSTNAMEJOB_CPP_H @@ -23,13 +23,13 @@ class SetHostNameJob : public Calamares::Job { - Q_OBJECT + Q_OBJECT public: - SetHostNameJob(const QString &hostname); + SetHostNameJob( const QString& hostname ); QString prettyName() const override; Calamares::JobResult exec() override; private: - const QString m_hostname; + const QString m_hostname; }; From fdd84d1f9950ee8ba97c4c9a0c70654107ba9015 Mon Sep 17 00:00:00 2001 From: Rohan Garg Date: Mon, 27 Oct 2014 16:58:42 +0100 Subject: [PATCH 4/4] Don't crash when packageOperations is empty --- src/modules/packages/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index 2413990b4..d132c8ce9 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -76,8 +76,9 @@ def run(): for entry in operations: run_operations(pkgman, entry) - operations = libcalamares.globalstorage.value("packageOperations") - for entry in operations: - run_operations(pkgman, entry) + if libcalamares.globalstorage.contains("pagkageOperations"): + operations = libcalamares.globalstorage.value("packageOperations") + for entry in operations: + run_operations(pkgman, entry) return None