diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2017-10-23 03:03:38 -0400 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2019-06-29 13:58:05 -0400 |
commit | 5f46bccb135a99b8d3fdbe033c4df3d581b03f10 (patch) | |
tree | 19518c18c4fc12cfa61e2c41ba31ee0ac106e265 | |
parent | bf2bdb9c0ef7c74508a94cf8edd339396def0ce3 (diff) |
emit progress
23 files changed, 529 insertions, 507 deletions
diff --git a/data/skel/mate/.bashrc b/data/skel/mate/.bashrc index cf741d7a8..89392d75b 100644 --- a/data/skel/mate/.bashrc +++ b/data/skel/mate/.bashrc @@ -5,6 +5,8 @@ # If not running interactively, don't do anything [[ $- != *i* ]] && return +setxkbmap us + alias ls='ls --color=auto' if [[ "$XDG_VTNR" == "7" ]] diff --git a/src/libcalamares/GlobalStorage.cpp b/src/libcalamares/GlobalStorage.cpp index 36405ce87..ea09dabcb 100644 --- a/src/libcalamares/GlobalStorage.cpp +++ b/src/libcalamares/GlobalStorage.cpp @@ -166,4 +166,15 @@ GlobalStoragePythonWrapper::value( const std::string& key ) const } // namespace CalamaresPython + +const QString GS::HAS_ISOREPO_KEY = "has-isorepo"; +const QString GS::IS_ONLINE_KEY = "hasInternet"; +const QString GS::DESKTOP_PACKAGES_KEY = "default-desktop" ; +const QString GS::PARTITIONS_KEY = "partitions"; +const QString GS::DEVICE_KEY = "device"; +const QString GS::FS_KEY = "fs"; +const QString GS::MOUNTPOINT_KEY = "mountPoint"; +const QString GS::UUID_KEY = "uuid"; + + #endif // WITH_PYTHON diff --git a/src/libcalamares/GlobalStorage.h b/src/libcalamares/GlobalStorage.h index 0ff56ac62..7910e6873 100644 --- a/src/libcalamares/GlobalStorage.h +++ b/src/libcalamares/GlobalStorage.h @@ -100,4 +100,19 @@ private: } // namespace CalamaresPython #endif + +class GS +{ +public: + static const QString HAS_ISOREPO_KEY; + static const QString IS_ONLINE_KEY; + static const QString DESKTOP_PACKAGES_KEY; + static const QString PARTITIONS_KEY; + static const QString DEVICE_KEY; + static const QString FS_KEY; + static const QString MOUNTPOINT_KEY; + static const QString UUID_KEY; +} ; + + #endif // CALAMARES_GLOBALSTORAGE_H diff --git a/src/libcalamares/Job.cpp b/src/libcalamares/Job.cpp index 26ee94464..f69525f48 100644 --- a/src/libcalamares/Job.cpp +++ b/src/libcalamares/Job.cpp @@ -92,6 +92,13 @@ Job::~Job() {} +qreal +Job::getJobWeight() const +{ + return qreal( 1.0 ); +} + + QString Job::prettyDescription() const { diff --git a/src/libcalamares/Job.h b/src/libcalamares/Job.h index 218abb72b..497a88155 100644 --- a/src/libcalamares/Job.h +++ b/src/libcalamares/Job.h @@ -62,6 +62,7 @@ public: explicit Job( QObject* parent = nullptr ); virtual ~Job(); + virtual qreal getJobWeight() const; virtual QString prettyName() const = 0; virtual QString prettyDescription() const; virtual QString prettyStatusMessage() const; diff --git a/src/libcalamares/JobQueue.cpp b/src/libcalamares/JobQueue.cpp index 86e33a0cd..44a9fb62b 100644 --- a/src/libcalamares/JobQueue.cpp +++ b/src/libcalamares/JobQueue.cpp @@ -49,6 +49,17 @@ public: void setJobs( const JobList& jobs ) { m_jobs = jobs; + + qreal totalJobsWeight = 0.0; + for( auto job : m_jobs ) + { + totalJobsWeight += job->getJobWeight(); + } + for( auto job : m_jobs ) + { + qreal jobWeight = qreal( job->getJobWeight() / totalJobsWeight ); + m_jobWeights.append( jobWeight ) ; + } } void run() override @@ -56,8 +67,8 @@ public: m_jobIndex = 0; for( auto job : m_jobs ) { - emitProgress(); cLog() << "Starting job" << job->prettyName(); + emitProgress(); connect( job.data(), &Job::progress, this, &JobThread::emitProgress ); JobResult result = job->exec(); if ( !result ) @@ -74,6 +85,7 @@ public: private: JobList m_jobs; + QList< qreal > m_jobWeights; JobQueue* m_queue; int m_jobIndex; @@ -88,8 +100,22 @@ private: ? m_jobs.at( m_jobIndex )->prettyStatusMessage() : tr( "Done" ); - qreal percent = ( m_jobIndex + jobPercent ) / qreal( jobCount ); + qreal cumulativeProgress = 0.0; + for( auto jobWeight : m_jobWeights.mid( 0, m_jobIndex ) ) + { + cumulativeProgress += jobWeight; + } + qreal percent = m_jobIndex < jobCount + ? cumulativeProgress + ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent ) + : 1.0; + if (m_jobIndex < jobCount) + { + cDebug(LOGVERBOSE) << "[JOBQUEUE]: Progress for Job[" << m_jobIndex << "]: " << ( jobPercent * 100 ) << "% completed"; + cDebug(LOGVERBOSE) << "[JOBQUEUE]: Progress Overall: " << ( cumulativeProgress * 100 ) << "% (accumulated) + " + << ( ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent ) * 100 ) << "% (this job) = " + << ( percent * 100 ) << "% (total)"; + } QMetaObject::invokeMethod( m_queue, "progress", Qt::QueuedConnection, Q_ARG( qreal, percent ), Q_ARG( QString, message ) diff --git a/src/libcalamares/PacstrapCppJob.cpp b/src/libcalamares/PacstrapCppJob.cpp index a24817497..268baf2da 100644 --- a/src/libcalamares/PacstrapCppJob.cpp +++ b/src/libcalamares/PacstrapCppJob.cpp @@ -22,22 +22,11 @@ #include "JobQueue.h" #include <PacstrapCppJob.h> +#include "utils/Logger.h" /* PacstrapCppJob public class constants */ -const QString PacstrapCppJob::DESKTOP_PACKAGES_KEY = "default-desktop" ; - - -/* PacstrapCppJob protected class constants */ - -const QString PacstrapCppJob::MOUNTPOINT = "/tmp/pacstrap" ; -const char* PacstrapCppJob::BASE_JOB_NAME = "Pacstrap Base C++ Job" ; -const char* PacstrapCppJob::GUI_JOB_NAME = "Pacstrap Desktop C++ Job" ; -const char* PacstrapCppJob::BASE_STATUS_MSG = "Installing root filesystem" ; -const char* PacstrapCppJob::GUI_STATUS_MSG = "Installing graphical desktop environment" ; -const qreal PacstrapCppJob::BASE_JOB_WEIGHT = 23.0 ; // progress-bar job weight (1.0 normal) -const qreal PacstrapCppJob::GUI_JOB_WEIGHT = 69.0 ; // progress-bar job weight (1.0 normal) const QString PacstrapCppJob::BASE_PACKAGES_KEY = "base" ; const QString PacstrapCppJob::BOOTLODER_PACKAGES_KEY = "bootloader" ; const QString PacstrapCppJob::KERNEL_PACKAGES_KEY = "kernel" ; @@ -49,31 +38,42 @@ const QString PacstrapCppJob::UTILITIES_PACKAGES_KEY = "utilities" ; const QString PacstrapCppJob::XSERVER_PACKAGES_KEY = "x-server" ; const QString PacstrapCppJob::MATE_PACKAGES_KEY = "mate" ; const QString PacstrapCppJob::LXDE_PACKAGES_KEY = "lxde" ; -const QString PacstrapCppJob::PACSTRAP_FMT = "pacstrap -c -C %1 %2 %3" ; -const QString PacstrapCppJob::PACSTRAP_ERROR_MSG = "Failed to install packages in chroot." ; + + +/* PacstrapCppJob protected class constants */ + +const QString PacstrapCppJob::MOUNTPOINT = "/tmp/pacstrap" ; +const char* PacstrapCppJob::BASE_JOB_NAME = "Pacstrap Base C++ Job" ; +const char* PacstrapCppJob::GUI_JOB_NAME = "Pacstrap Desktop C++ Job" ; +const char* PacstrapCppJob::BASE_STATUS_MSG = "Installing root filesystem" ; +const char* PacstrapCppJob::GUI_STATUS_MSG = "Installing graphical desktop environment" ; +const qreal PacstrapCppJob::BASE_JOB_WEIGHT = 20.0 ; // progress-bar job weight (1.0 normal) +const qreal PacstrapCppJob::GUI_JOB_WEIGHT = 57.0 ; // progress-bar job weight (1.0 normal) +const qreal PacstrapCppJob::PACMAN_SYNC_PROPORTION = 0.05 ; // per task progress-bar proportion +const qreal PacstrapCppJob::LIST_PACKAGES_PROPORTION = 0.05 ; // per task progress-bar proportion +const qreal PacstrapCppJob::CHROOT_TASK_PROPORTION = 0.9 ; // per task progress-bar proportion +const QString PacstrapCppJob::PACSTRAP_CLEANUP_CMD = QString("umount %1/dev/pts %1/dev/shm %1/dev %1/proc %1/run %1/sys %1/tmp %1").arg(MOUNTPOINT) ; +const QString PacstrapCppJob::PACSTRAP_FMT = "pacstrap -C %1 %2 %3 --noprogressbar" ; +const QString PacstrapCppJob::PACSTRAP_ERROR_MSG = "Failed to install packages in chroot." ; /* PacstrapCppJob private class constants */ const QDir PacstrapCppJob::PACKAGES_CACHE_DIR = QDir(MOUNTPOINT + "/var/cache/pacman/pkg") ; const QDir PacstrapCppJob::PACKAGES_METADATA_DIR = QDir(MOUNTPOINT + "/var/lib/pacman/local") ; +const QString PacstrapCppJob::DEFAULT_CONF_FILENAME = "/etc/pacman.conf" ; const QString PacstrapCppJob::ONLINE_CONF_FILENAME = "/etc/pacman-online.conf" ; const QString PacstrapCppJob::OFFLINE_CONF_FILENAME = "/etc/pacman-offline.conf" ; -const QString PacstrapCppJob::IS_ONLINE_KEY = "hasInternet" ; -const QString PacstrapCppJob::PARTITIONS_KEY = "partitions" ; -const QString PacstrapCppJob::DEVICE_KEY = "device" ; -const QString PacstrapCppJob::FS_KEY = "fs" ; -const QString PacstrapCppJob::MOUNTPOINT_KEY = "mountPoint" ; -const QString PacstrapCppJob::UUID_KEY = "uuid" ; const QString PacstrapCppJob::SYSTEM_EXEC_FMT = "/bin/sh -c \"%1\"" ; // const QString PacstrapCppJob::KEYRING_CMD = "pacman -Sy --noconfirm parabola-keyring" ; // const QString PacstrapCppJob::KEYRING_CMD = "pacman -Sy --noconfirm parabola-keyring && \ +// pacman-key --init && \ // pacman-key --populate parabola && \ -// pacman-key --refresh-keys " ; +// pacman-key --refresh-keys " ; const QString PacstrapCppJob::MOUNT_FMT = "mkdir %2 2> /dev/null || true && mount %1 %2" ; const QString PacstrapCppJob::CHROOT_PREP_FMT = "mkdir -m 0755 -p {%1,%2}" ; -const QString PacstrapCppJob::PACKAGES_SYNC_FMT = "pacman --print --config %1 --root %2 -Sy" ; -const QString PacstrapCppJob::LIST_PACKAGES_FMT = "pacman --print --config %1 --root %2 -S %3" ; +const QString PacstrapCppJob::DB_REFRESH_FMT = "pacman -S --print --config %1 --root %2 --refresh" ; +const QString PacstrapCppJob::LIST_PACKAGES_FMT = "pacman -S --print --config %1 --root %2 %3" ; const QString PacstrapCppJob::UMOUNT_FMT = "umount %1" ; const QString PacstrapCppJob::CONFIG_ERROR_MSG = "Invalid configuration map." ; const QString PacstrapCppJob::TARGET_ERROR_MSG = "Target device for root filesystem is unspecified." ; @@ -83,6 +83,9 @@ const QString PacstrapCppJob::MOUNT_ERROR_MSG = "Failed to mount the pacst const QString PacstrapCppJob::CHROOT_PREP_ERROR_MSG = "Failed to prepare the pacstrap chroot." ; const QString PacstrapCppJob::PACMAN_SYNC_ERROR_MSG = "Failed to syncronize packages in the pacstrap chroot." ; const QString PacstrapCppJob::UMOUNT_ERROR_MSG = "Failed to unmount the pacstrap chroot." ; +const QString PacstrapCppJob::STATUS_KEY = QString("status") ; +const QString PacstrapCppJob::STDOUT_KEY = QString("stdout") ; +const QString PacstrapCppJob::STDERR_KEY = QString("stderr") ; /* PacstrapCppJob public constructors/destructors */ @@ -92,19 +95,17 @@ PacstrapCppJob::PacstrapCppJob(QString job_name , QString status_msg , jobName (job_name ) , statusMsg (status_msg) , jobWeight(job_weight) , Calamares::CppJob(parent ) { -printf("PacstrapCppJob::PacstrapCppJob() '%s'\n" , jobName.toStdString().c_str()) ; - - this->globalStorage = Calamares::JobQueue::instance()->globalStorage() ; - this->guiTimerId = startTimer(1000) ; -// this->guiTimerId = -1 ; // deferred to exec() - this->targetDevice = QString("") ; // deferred to exec()->runJob() - this->confFile = QString("") ; // deferred to exec()->runJob() - this->packages = QString("") ; // deferred to exec()->runJob() - this->nPackages = 0 ; // deferred to exec()->runJob() + this->globalStorage = Calamares::JobQueue::instance()->globalStorage() ; + this->localStorage = QVariantMap() ; // deferred to setConfigurationMap() + this->targetDevice = QString("") ; // deferred to exec() + this->confFile = QString("") ; // deferred to exec() + this->packages = QString("") ; // deferred to exec() + this->nPreviousPackages = 0 ; // deferred to exec() + this->nPendingPackages = 0 ; // deferred to exec() + this->progressPercent = 0 ; } -PacstrapCppJob::~PacstrapCppJob() { killTimer(this->guiTimerId) ; } -// PacstrapCppJob::~PacstrapCppJob() {} +PacstrapCppJob::~PacstrapCppJob() {} /* PacstrapCppJob public getters/setters */ @@ -122,41 +123,123 @@ QString PacstrapCppJob::prettyStatusMessage() const { return thi Calamares::JobResult PacstrapCppJob::exec() { -// #include <QTimer> -// QTimer* guiTimer = new QTimer() ; -// connect(guiTimer , SIGNAL(timeout()) , this , SLOT(updateProgress())) ; -// guiTimer->start((std::chrono::milliseconds)1000) ; + // cleanup from possibly aborted previous runs + QProcess::execute(SYSTEM_EXEC_FMT.arg(PACSTRAP_CLEANUP_CMD)) ; + + QVariantList partitions = this->globalStorage->value(GS::PARTITIONS_KEY ).toList() ; + bool has_isorepo = this->globalStorage->value(GS::HAS_ISOREPO_KEY).toBool() ; + bool is_online = this->globalStorage->value(GS::IS_ONLINE_KEY ).toBool() ; + this->targetDevice = FindTargetDevice(partitions) ; + this->confFile = (!has_isorepo) ? DEFAULT_CONF_FILENAME : + (is_online ) ? ONLINE_CONF_FILENAME : OFFLINE_CONF_FILENAME ; + this->packages = getPackageList() ; + +DEBUG_TRACE_EXEC + + if (this->localStorage.empty() ) return JobError(CONFIG_ERROR_MSG) ; + if (this->targetDevice.isEmpty() ) return JobError(TARGET_ERROR_MSG) ; + if (!QFile(this->confFile).exists()) return JobError(CONFFILE_ERROR_MSG.arg(this->confFile)) ; + +// QString keyring_cmd = KEYRING_CMD ; + QString mount_cmd = MOUNT_FMT .arg(this->targetDevice , MOUNTPOINT) ; + QString chroot_prep_cmd = CHROOT_PREP_FMT .arg(PACKAGES_CACHE_DIR .absolutePath() , + PACKAGES_METADATA_DIR.absolutePath() ) ; + QString pacman_sync_cmd = DB_REFRESH_FMT .arg(this->confFile , MOUNTPOINT) ; + QString list_packages_cmd = LIST_PACKAGES_FMT.arg(this->confFile , MOUNTPOINT , this->packages) ; + QString umount_cmd = UMOUNT_FMT .arg(this->targetDevice) ; + +// if (!!execStatus(keyring_cmd )) return JobError(KEYRING_ERROR_MSG) ; + if (!!execStatus(mount_cmd )) return JobError(MOUNT_ERROR_MSG ) ; + if (!!execStatus(chroot_prep_cmd )) return JobError(CHROOT_PREP_ERROR_MSG) ; + if (!!execStatus(pacman_sync_cmd , PACMAN_SYNC_PROPORTION)) return JobError(PACMAN_SYNC_ERROR_MSG) ; + + if (!this->packages.isEmpty()) + { + QString new_packages = execOutput(list_packages_cmd , LIST_PACKAGES_PROPORTION) ; + this->nPreviousPackages = NPackagesInstalled() ; + this->nPendingPackages = new_packages.count(QChar::LineFeed) ; + + if (this->nPendingPackages > 0) + { + QString exec_error_msg = chrootExec() ; -// this->guiTimerId = startTimer(1000) ; - Calamares::JobResult retval = runJob() ; + if (exec_error_msg.isEmpty()) this->nPendingPackages = 0 ; + else return JobError(exec_error_msg) ; + } + } -// killTimer(this->guiTimerId) ; -// guiTimer->stop() ; + if (!execStatus(umount_cmd)) this->progressPercent = emitProgress(1.0) ; + else return JobError(UMOUNT_ERROR_MSG) ; - return retval ; + return JobSuccess() ; } -/* PacstrapCppJob protected class methods */ +/* PacstrapCppJob protected instance methods */ -Calamares::JobResult PacstrapCppJob::JobErrorRetval(QString error_msg) +QVariantMap PacstrapCppJob::execWithProgress(QString command_line , qreal task_proportion) { - return Calamares::JobResult::error(error_msg) ; + QProcess proc ; + int status ; + QString stdout = QString("") ; + QString stderr = QString("") ; + QVariantMap retval ; + + cLog() << "[PACSTRAP]: executing shell command: " << command_line ; + cLog() << "=================== [SHELL OUTPUT BEGIN] ===================" ; + proc.start(QString(SYSTEM_EXEC_FMT).arg(command_line)) ; proc.waitForStarted(-1) ; + while (proc.waitForFinished(250) || proc.state() != QProcess::NotRunning) + { + QString stdout_flush ; stdout += (stdout_flush = proc.readAllStandardOutput()) ; + QString stderr_flush ; stderr += (stderr_flush = proc.readAllStandardError()) ; ; + + if (!stdout_flush.isEmpty()) printf("%s" , stdout_flush.toStdString().c_str()) ; + if (!stderr_flush.isEmpty()) printf("%s" , stderr_flush.toStdString().c_str()) ; + + emitProgress(task_proportion * getTaskCompletion()) ; + } + + this->progressPercent = emitProgress(task_proportion) ; + cLog() << "==================== [SHELL OUTPUT END] ====================" ; + + status = (proc.exitStatus() == QProcess::NormalExit) ? proc.exitCode() : 255 ; + +DEBUG_TRACE_EXECWITHPROGRESS + + retval.insert(STATUS_KEY , QVariant(status)) ; + retval.insert(STDOUT_KEY , QVariant(stdout)) ; + retval.insert(STDERR_KEY , QVariant(stderr)) ; + + return retval ; +} ; + +int PacstrapCppJob::execStatus(QString command_line , qreal task_proportion) +{ + QVariantMap result = execWithProgress(command_line , task_proportion) ; + int status = result.value(STATUS_KEY).toInt() ; + + return status ; } -Calamares::JobResult PacstrapCppJob::JobSuccessRetval() +QString PacstrapCppJob::execOutput(QString command_line , qreal task_proportion) { - return Calamares::JobResult::ok() ; + QVariantMap result = execWithProgress(command_line , task_proportion) ; + QString stdout = result.value(STDOUT_KEY).toString() ; + + return stdout ; } -QString PacstrapCppJob::QListToString(const QVariantList& package_list) +QString PacstrapCppJob::execError(QString command_line , qreal task_proportion) { - QStringList result ; - for (const QVariant& package : package_list) result.append(package.toString()) ; + QVariantMap result = execWithProgress(command_line , task_proportion) ; + QString stderr = result.value(STDERR_KEY).toString() ; - return result.join(' ') ; + return stderr ; } + +/* PacstrapCppJob private class methods */ + QString PacstrapCppJob::FindTargetDevice(const QVariantList& partitions) { QString target_device = QString("") ; @@ -164,124 +247,60 @@ QString PacstrapCppJob::FindTargetDevice(const QVariantList& partitions) // locate target device for root filesystem foreach (const QVariant& partition , partitions) { -QStringList result; for ( auto it = partition.toMap().constBegin(); it != partition.toMap().constEnd(); ++it ) result.append( it.key() + '=' + it.value().toString() ); -printf("[PACSTRAPCPP]: partition=[%s]\n" , result.join(',').toStdString().c_str()) ; - QVariantMap partition_map = partition.toMap() ; - QString device = partition_map.value(DEVICE_KEY ).toString() ; - QString fs = partition_map.value(FS_KEY ).toString() ; - QString mountpoint = partition_map.value(MOUNTPOINT_KEY).toString() ; - QString uuid = partition_map.value(UUID_KEY ).toString() ; + QString device = partition_map.value(GS::DEVICE_KEY ).toString() ; + QString fs = partition_map.value(GS::FS_KEY ).toString() ; + QString mountpoint = partition_map.value(GS::MOUNTPOINT_KEY).toString() ; + QString uuid = partition_map.value(GS::UUID_KEY ).toString() ; if (mountpoint == "/") target_device = device ; - -if (mountpoint == "/") printf("[PACSTRAPCPP]: target_device=%s\n" , device.toStdString().c_str()) ; } - return target_device ; -} +DEBUG_TRACE_FINDTARGETDEVICE -unsigned int PacstrapCppJob::NPackagesInstalled() -{ - return (PACKAGES_CACHE_DIR .entryList(QDir::Files | QDir::NoDotAndDotDot).count() + - PACKAGES_METADATA_DIR.entryList(QDir::Dirs | QDir::NoDotAndDotDot).count() ) / 2 ; -} - -QStringList PacstrapCppJob::Exec(QString command_line) -{ - QProcess proc ; - - proc.start(QString(SYSTEM_EXEC_FMT).arg(command_line)) ; proc.waitForFinished(-1) ; - - int status = proc.exitStatus() ; - QString stdout = proc.readAllStandardOutput() ; - QString stderr = proc.readAllStandardError() ; - -// printf("[PACSTRAPCPP_DEBUG]: PacstrapCppJob::ExecWithOutput() status=%d\n" , status) ; -// printf("[PACSTRAPCPP_DEBUG]: PacstrapCppJob::ExecWithOutput() stdout=%s\n" , stdout) ; -// printf("[PACSTRAPCPP_DEBUG]: PacstrapCppJob::ExecWithOutput() stderr=%s\n" , stderr) ; - - return (QStringList() << QString(status) << stdout << stderr) ; + return target_device ; } -int PacstrapCppJob::ExecWithStatus(QString command_line) +qint16 PacstrapCppJob::NPackagesInstalled() { -printf("PacstrapCppJob::ExecWithStatus() command_line=%s\n" , command_line.toStdString().c_str()) ; + int n_downloaded = PACKAGES_CACHE_DIR .entryList(QDir::Files | QDir::NoDotAndDotDot).count() ; + int n_installed = PACKAGES_METADATA_DIR.entryList(QDir::Dirs | QDir::NoDotAndDotDot).count() ; - return QProcess::execute(QString(SYSTEM_EXEC_FMT).arg(command_line)) ; + return (n_downloaded + n_installed) / 2 ; } -QString PacstrapCppJob::ExecWithOutput(QString command_line) +Calamares::JobResult PacstrapCppJob::JobError(QString error_msg) { - return Exec(command_line).at(1) ; + return Calamares::JobResult::error(error_msg) ; } -QString PacstrapCppJob::ExecWithError(QString command_line) +Calamares::JobResult PacstrapCppJob::JobSuccess() { - return Exec(command_line).at(2) ; + return Calamares::JobResult::ok() ; } -/* PacstrapCppJob protected instance methods */ +/* PacstrapCppJob private instance methods */ -void PacstrapCppJob::timerEvent(QTimerEvent* event) +qreal PacstrapCppJob::emitProgress(qreal transient_percent) { - if (event->timerId() == this->guiTimerId) updateProgress() ; -} + qreal progress_percent = qBound(0.0 , this->progressPercent + transient_percent , 1.0) ; -void PacstrapCppJob::updateProgress() -{ - if (this->nPackages == 0) return ; - - qreal progress_percent = qreal(NPackagesInstalled()) / this->nPackages ; - -printf("\n[PACSTRAPCPP]: n_packages=%d this->nPackages=%d progress_percent=%f\n" , NPackagesInstalled() , this->nPackages , (float)progress_percent) ; +DEBUG_TRACE_EMITPROGRESS emit progress(progress_percent) ; + + return progress_percent ; } -Calamares::JobResult PacstrapCppJob::runJob() +qreal PacstrapCppJob::getTaskCompletion() { - QVariantList partitions = this->globalStorage->value(PARTITIONS_KEY).toList() ; - bool has_internet = this->globalStorage->value(IS_ONLINE_KEY ).toBool() ; - this->targetDevice = FindTargetDevice(partitions) ; - this->confFile = (has_internet) ? ONLINE_CONF_FILENAME : OFFLINE_CONF_FILENAME ; - this->packages = getPackageList() ; - - if (this->localStorage.empty() ) return JobErrorRetval(CONFIG_ERROR_MSG) ; - if (this->targetDevice.isEmpty() ) return JobErrorRetval(TARGET_ERROR_MSG) ; - if (!QFile(this->confFile).exists()) return JobErrorRetval(CONFFILE_ERROR_MSG.arg(this->confFile)) ; - -// QString keyring_cmd = KEYRING_CMD ; - QString mount_cmd = MOUNT_FMT .arg(this->targetDevice , MOUNTPOINT) ; - QString chroot_prep_cmd = CHROOT_PREP_FMT .arg(PACKAGES_CACHE_DIR .absolutePath() , - PACKAGES_METADATA_DIR.absolutePath() ) ; - QString pacman_sync_cmd = PACKAGES_SYNC_FMT.arg(this->confFile , MOUNTPOINT) ; - QString list_packages_cmd = LIST_PACKAGES_FMT.arg(this->confFile , MOUNTPOINT , this->packages) ; - QString umount_cmd = UMOUNT_FMT .arg(this->targetDevice) ; - -// if (!!ExecWithStatus(keyring_cmd )) return JobErrorRetval(KEYRING_ERROR_MSG) ; -// "mkdir %2 2> /dev/null" "mount %1 %2" - if (!!ExecWithStatus(mount_cmd )) return JobErrorRetval(MOUNT_ERROR_MSG ) ; - if (!!ExecWithStatus(chroot_prep_cmd)) return JobErrorRetval(CHROOT_PREP_ERROR_MSG) ; - if (!!ExecWithStatus(pacman_sync_cmd)) return JobErrorRetval(PACMAN_SYNC_ERROR_MSG) ; - - if (!this->packages.isEmpty()) - { - QString new_packages = ExecWithOutput(list_packages_cmd) ; - this->nPackages = NPackagesInstalled() + new_packages.count(QChar::LineFeed) ; + if (this->nPendingPackages == 0) return 0.0 ; - if (this->nPackages > 0) - { -// return Calamares::JobResult::error("just cause") ; - - QString exec_error_msg = chrootExec() ; - if (!exec_error_msg.isEmpty()) return JobErrorRetval(exec_error_msg) ; - } - } - else emit progress(this->jobWeight) ; + qreal n_new_packages = qreal(NPackagesInstalled() - this->nPreviousPackages) ; + qreal completion_percent = qreal(n_new_packages / this->nPendingPackages ) ; - if (!!ExecWithStatus(umount_cmd)) return JobErrorRetval(UMOUNT_ERROR_MSG) ; +DEBUG_TRACE_GETTASKCOMPLETION - return JobSuccessRetval() ; + return completion_percent ; } diff --git a/src/libcalamares/PacstrapCppJob.h b/src/libcalamares/PacstrapCppJob.h index f3017062a..ca0d851ed 100644 --- a/src/libcalamares/PacstrapCppJob.h +++ b/src/libcalamares/PacstrapCppJob.h @@ -50,30 +50,42 @@ public: protected: - static Calamares::JobResult JobErrorRetval (QString error_msg) ; - static Calamares::JobResult JobSuccessRetval () ; - static QString QListToString (const QVariantList& package_list) ; - static QString FindTargetDevice (const QVariantList& partitions) ; - static unsigned int NPackagesInstalled() ; - static QStringList Exec (QString command_line) ; - static int ExecWithStatus (QString command_line) ; - static QString ExecWithOutput (QString command_line) ; - static QString ExecWithError (QString command_line) ; + QVariantMap execWithProgress(QString command_line , qreal task_proportion = 0.0) ; + int execStatus (QString command_line , qreal task_proportion = 0.0) ; + QString execOutput (QString command_line , qreal task_proportion = 0.0) ; + QString execError (QString command_line , qreal task_proportion = 0.0) ; virtual QString getPackageList() = 0 ; virtual QString chrootExec () = 0 ; - void timerEvent (QTimerEvent* event) override ; - void updateProgress() ; - Calamares::JobResult runJob () ; + QString jobName ; + QString statusMsg ; + qreal jobWeight ; + Calamares::GlobalStorage* globalStorage ; + QVariantMap localStorage ; + QString targetDevice ; + QString confFile ; + QString packages ; + qint16 nPreviousPackages ; + qint16 nPendingPackages ; + qreal progressPercent ; + + +private: + + static QString FindTargetDevice (const QVariantList& partitions) ; + static qint16 NPackagesInstalled() ; + static inline Calamares::JobResult JobError (QString error_msg) ; + static inline Calamares::JobResult JobSuccess () ; + + qreal emitProgress (qreal transient_percent) ; + qreal getTaskCompletion() ; + + + /* constants */ + +public: - static const QString MOUNTPOINT ; - static const char* BASE_JOB_NAME ; - static const char* GUI_JOB_NAME ; - static const char* BASE_STATUS_MSG ; - static const char* GUI_STATUS_MSG ; - static const qreal BASE_JOB_WEIGHT ; - static const qreal GUI_JOB_WEIGHT ; static const QString BASE_PACKAGES_KEY ; static const QString BOOTLODER_PACKAGES_KEY ; static const QString KERNEL_PACKAGES_KEY ; @@ -85,38 +97,37 @@ protected: static const QString XSERVER_PACKAGES_KEY ; static const QString MATE_PACKAGES_KEY ; static const QString LXDE_PACKAGES_KEY ; + + +protected: + + static const QString MOUNTPOINT ; + static const char* BASE_JOB_NAME ; + static const char* GUI_JOB_NAME ; + static const char* BASE_STATUS_MSG ; + static const char* GUI_STATUS_MSG ; + static const qreal BASE_JOB_WEIGHT ; + static const qreal GUI_JOB_WEIGHT ; + static const qreal PACMAN_SYNC_PROPORTION ; + static const qreal LIST_PACKAGES_PROPORTION ; + static const qreal CHROOT_TASK_PROPORTION ; + static const QString PACSTRAP_CLEANUP_CMD ; static const QString PACSTRAP_FMT ; static const QString PACSTRAP_ERROR_MSG ; - QString jobName ; - QString statusMsg ; - qreal jobWeight ; - Calamares::GlobalStorage* globalStorage ; - unsigned int guiTimerId ; - QString targetDevice ; - QString confFile ; - QString packages ; - unsigned int nPackages ; - QVariantMap localStorage ; - private: static const QDir PACKAGES_CACHE_DIR ; static const QDir PACKAGES_METADATA_DIR ; + static const QString DEFAULT_CONF_FILENAME ; static const QString ONLINE_CONF_FILENAME ; static const QString OFFLINE_CONF_FILENAME ; - static const QString IS_ONLINE_KEY ; - static const QString PARTITIONS_KEY ; - static const QString DEVICE_KEY ; - static const QString FS_KEY ; - static const QString MOUNTPOINT_KEY ; - static const QString UUID_KEY ; static const QString SYSTEM_EXEC_FMT ; // static const QString KEYRING_CMD ; static const QString MOUNT_FMT ; static const QString CHROOT_PREP_FMT ; - static const QString PACKAGES_SYNC_FMT ; + static const QString DB_REFRESH_FMT ; static const QString LIST_PACKAGES_FMT ; static const QString UMOUNT_FMT ; static const QString CONFIG_ERROR_MSG ; @@ -127,7 +138,51 @@ private: static const QString CHROOT_PREP_ERROR_MSG ; static const QString PACMAN_SYNC_ERROR_MSG ; static const QString UMOUNT_ERROR_MSG ; + static const QString STATUS_KEY ; + static const QString STDOUT_KEY ; + static const QString STDERR_KEY ; } ; +/* DEBUG */ + +#define DEBUG_TRACE_EXEC cDebug() << "[PACSTRAP]: exec()" \ + << " job_name=" << this->jobName \ + << " has_isorepo=" << has_isorepo \ + << " is_online=" << is_online \ + << " targetDevice=" << this->targetDevice \ + << " confFile=" << this->confFile \ + << " n_packages=" << this->packages.count() ; + +#define DEBUG_TRACE_EXECWITHPROGRESS \ + cDebug() << "[PACSTRAP]: shell command exited=" << command_line ; \ + cDebug() << "[PACSTRAP]: status=" << status ; \ + cDebug(LOGVERBOSE) << "[PACSTRAP]: stdout=" << stdout ; \ + cDebug(LOGVERBOSE) << "[PACSTRAP]: stderr=" << stderr ; + +#define DEBUG_TRACE_FINDTARGETDEVICE if (!target_device.isEmpty()) \ + cDebug() << "[PACSTRAP]: mounting target_device: " << target_device ; + +#define DEBUG_TRACE_EMITPROGRESS cDebug(LOGVERBOSE) << "[PACSTRAP]: " << \ + "this->progressPercent=" << this->progressPercent << \ + " transient_percent=" << transient_percent << \ + " emmitting=" << progress_percent ; + +#define DEBUG_TRACE_GETTASKCOMPLETION cDebug(LOGVERBOSE) << "[PACSTRAP]: " << \ + "this->nPreviousPackages=" << this->nPreviousPackages << \ + " NPackagesInstalled()=" << NPackagesInstalled() << \ + "\n " << \ + "n_new_packages=" << (int)n_new_packages << \ + " this->nPendingPackages=" << this->nPendingPackages << \ + " completion_percent=" << completion_percent ; + +#ifndef QT_NO_DEBUG +# define DEBUG_TRACE_DESKTOPPACKAGES \ + printf("[PACSTRAP-GUI]: installing default_desktop: %s\n" , \ + globalStorage->value(GS::DESKTOP_PACKAGES_KEY).toString().toStdString().c_str()) ; +#else // QT_NO_DEBUG +# define DEBUG_TRACE_DESKTOPPACKAGES ; +#endif // QT_NO_DEBUG + + #endif // PACSTRAPCPPJOB_H diff --git a/src/modules/desktop/desktop.cpp b/src/modules/desktop/desktop.cpp deleted file mode 100644 index 7244b5dc6..000000000 --- a/src/modules/desktop/desktop.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* === This file is part of Calamares - <http://github.com/calamares> === - * - * Copyright 2014, Teo Mrnjavac <teo@kde.org> (original dummypython code) - * Copyright 2016, Kevin Kofler <kevin.kofler@chello.at> - * - * Calamares 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. - * - * Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include <QProcess> -#include <QDateTime> -#include <QThread> - -#include "CalamaresVersion.h" -#include "JobQueue.h" -#include "GlobalStorage.h" - -#include "desktop.h" -#include "utils/Logger.h" - - -DesktopCppJob::DesktopCppJob(QObject* parent) : Calamares::CppJob(parent) {} - -DesktopCppJob::~DesktopCppJob() {} - -QString DesktopCppJob::prettyName() const { return tr("Desktop C++ Job") ; } - -QString DesktopCppJob::prettyStatusMessage() const { return m_status ; } - -Calamares::JobResult DesktopCppJob::exec() -{ - m_status = tr("Installing graphical desktop environment") ; emit progress(1) ; - - Calamares::GlobalStorage* globalStorage = Calamares::JobQueue::instance()->globalStorage() ; - bool has_internet = globalStorage->value("hasInternet" ).toBool() ; -has_internet = false ; - QString target_device = globalStorage->value("target-device").toString() ; - QString conf_file = (has_internet) ? "/etc/pacman.conf" : "/etc/pacman-offline.conf" ; - QString mountpoint = "/tmp/pacstrap"; - - if (target_device.isEmpty()) return Calamares::JobResult::error("Target device for root filesystem is unspecified.") ; - -globalStorage->insert("default-desktop", "mate") ; // TODO: per user option via globalStorage -cDebug() << QString("[DESKTOPCPP]: DesktopCppJob::exec() default_desktop=%1").arg(globalStorage->value("default-desktop").toString()) ; - - QString desktop = globalStorage->value("default-desktop").toString() ; - QString packages = QListToString(m_configurationMap.value("applications").toList() + - m_configurationMap.value("multimedia" ).toList() + - m_configurationMap.value("network" ).toList() + - m_configurationMap.value("themes" ).toList() + - m_configurationMap.value("utilities" ).toList() + - m_configurationMap.value("xserver" ).toList() + - m_configurationMap.value(desktop ).toList() ) ; - - QString mount_cmd = QString("/bin/sh -c \"mount %1 %2\"").arg(target_device, mountpoint) ; -// QString pacstrap_cmd = (has_internet) ? QString("/bin/sh -c \"pacstrap-calamares -c %1 %2\"").arg(mountpoint , packages) : -// QString("/bin/sh -c \"pacstrap-calamares -c -o %1 %2\"").arg(mountpoint , packages) ; - QString pacstrap_cmd = QString("/bin/sh -c \"pacstrap -c -C %1 %2 %3\"").arg(conf_file , mountpoint , packages); - QString wallpaper_cmd = QString("/bin/sh -c \"cp /etc/wallpaper.png %1/etc/\"").arg(mountpoint) ; - QString umount_cmd = QString("/bin/sh -c \"umount %1\"").arg(target_device) ; - - // boot-strap install graphical desktop - QProcess::execute(mount_cmd) ; - if (QProcess::execute(pacstrap_cmd)) return Calamares::JobResult::error("PACSTRAP_FAIL") ; - -cDebug() << QString("[DESKTOPCPP]: ls /etc/skel") ; QProcess::execute(QString("/bin/sh -c \"ls -al /etc/skel/\"" ) ) ; -cDebug() << QString("[DESKTOPCPP]: ls chroot/etc/skel/") ; QProcess::execute(QString("/bin/sh -c \"ls -al %1/etc/skel/\"" ).arg(mountpoint)) ; -cDebug() << QString("[DESKTOPCPP]: ls chroot/etc/wallpaper.png") ; QProcess::execute(QString("/bin/sh -c \"ls -al %1/etc/wallpaper.png\"").arg(mountpoint)) ; -cDebug() << QString("[DESKTOPCPP]: ls chroot/etc/sudoers*") ; QProcess::execute(QString("/bin/sh -c \"ls -al %1/etc/sudoers*\"" ).arg(mountpoint)) ; - - QProcess::execute(wallpaper_cmd) ; - -cDebug() << QString("[DESKTOPCPP]: ls chroot/etc/wallpaper.png") ; QProcess::execute(QString("/bin/sh -c \"ls -al %1/etc/wallpaper.png\"").arg(mountpoint)) ; - - QProcess::execute(umount_cmd) ; - emit progress(10) ; - - return Calamares::JobResult::ok() ; -} - - -void DesktopCppJob::setConfigurationMap(const QVariantMap& configurationMap) -{ - m_configurationMap = configurationMap ; -} - - -QString DesktopCppJob::QListToString(const QVariantList& package_list) -{ - QStringList result ; - for (const QVariant& package : package_list) result.append(package.toString()) ; - - return result.join(' ') ; -} - - -CALAMARES_PLUGIN_FACTORY_DEFINITION(DesktopCppJobFactory , registerPlugin<DesktopCppJob>() ;) diff --git a/src/modules/desktop/module.desc b/src/modules/desktop/module.desc deleted file mode 100644 index 3858cc884..000000000 --- a/src/modules/desktop/module.desc +++ /dev/null @@ -1,5 +0,0 @@ ---- -type: "job" -name: "desktop" -interface: "qtplugin" -load: "libcalamares_job_desktop.so" diff --git a/src/modules/pacstrap/CMakeLists.txt b/src/modules/pacstrap-base/CMakeLists.txt index 2f0a5fc66..366fc0d4b 100644 --- a/src/modules/pacstrap/CMakeLists.txt +++ b/src/modules/pacstrap-base/CMakeLists.txt @@ -1,8 +1,8 @@ -calamares_add_plugin( pacstrap +calamares_add_plugin( pacstrap-base TYPE job EXPORT_MACRO PLUGINDLLEXPORT_PRO SOURCES - pacstrap.cpp + pacstrap-base.cpp LINK_PRIVATE_LIBRARIES calamares SHARED_LIB diff --git a/src/modules/pacstrap-base/module.desc b/src/modules/pacstrap-base/module.desc new file mode 100644 index 000000000..231033d99 --- /dev/null +++ b/src/modules/pacstrap-base/module.desc @@ -0,0 +1,5 @@ +--- +type: "job" +name: "pacstrap-base" +interface: "qtplugin" +load: "libcalamares_job_pacstrap-base.so" diff --git a/src/modules/pacstrap/pacstrap.conf b/src/modules/pacstrap-base/pacstrap-base.conf index 444741bab..444741bab 100644 --- a/src/modules/pacstrap/pacstrap.conf +++ b/src/modules/pacstrap-base/pacstrap-base.conf diff --git a/src/modules/pacstrap-base/pacstrap-base.cpp b/src/modules/pacstrap-base/pacstrap-base.cpp new file mode 100644 index 000000000..b998c41f7 --- /dev/null +++ b/src/modules/pacstrap-base/pacstrap-base.cpp @@ -0,0 +1,71 @@ +/* === This file is part of Calamares - <http://github.com/calamares> === + * + * Copyright 2014, Teo Mrnjavac <teo@kde.org> (original dummypython code) + * Copyright 2016, Kevin Kofler <kevin.kofler@chello.at> + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <QProcess> + +#include "pacstrap-base.h" + + +/* PacstrapBaseJob public instance methods */ + +PacstrapBaseJob::PacstrapBaseJob(QObject* parent) : PacstrapCppJob(tr(BASE_JOB_NAME) , + tr(BASE_STATUS_MSG) , + BASE_JOB_WEIGHT , + parent ) {} + + +/* PacstrapBaseJob protected getters/setters */ + +QString PacstrapBaseJob::getPackageList() +{ + return (this->localStorage.value(BASE_PACKAGES_KEY ).toStringList() + + this->localStorage.value(BOOTLODER_PACKAGES_KEY).toStringList() + + this->localStorage.value(KERNEL_PACKAGES_KEY ).toStringList() ).join(' ') ; +} + + +/* PacstrapBaseJob protected instance methods */ + +QString PacstrapBaseJob::chrootExec() +{ + QString pacstrap_cmd = PACSTRAP_FMT .arg(this->confFile , MOUNTPOINT , packages) ; + QString grub_theme_cmd = GRUB_THEME_FMT.arg(MOUNTPOINT) ; + + if (!!execStatus(pacstrap_cmd , CHROOT_TASK_PROPORTION)) return PACSTRAP_ERROR_MSG ; + +QString grub_theme_kludge_cmd = QString("echo GRUB_THEME=/boot/grub/themes/GNUAxiom/theme.txt >> %1/etc/default/grub").arg(MOUNTPOINT) ; +printf("[PACSTRAP-BASE]: grub_theme_cmd=%s\n" , grub_theme_cmd.toStdString().c_str()) ; +printf("[PACSTRAP-BASE]: grub_theme_cmd IN:\n"); QProcess::execute(QString("/bin/sh -c \"cat %1/etc/default/grub\"").arg(MOUNTPOINT)); + + if (!!execStatus(grub_theme_cmd)) return GRUB_THEME_ERROR_MSG ; + +if (!!execStatus(grub_theme_kludge_cmd)) return "grub_theme_kludge_cmd failed" ; +printf("[PACSTRAP-BASE]: grub_theme_cmd OUT:\n"); QProcess::execute(QString("/bin/sh -c \"cat %1/etc/default/grub\"").arg(MOUNTPOINT)); + + return QString("") ; +} + + +/* PacstrapBaseJob private class constants */ + +const QString PacstrapBaseJob::GRUB_THEME_FMT = "sed -i 's|[#]GRUB_THEME=.*|GRUB_THEME=/boot/grub/themes/GNUAxiom/theme.txt|' %1/etc/default/grub" ; +const QString PacstrapBaseJob::GRUB_THEME_ERROR_MSG = "The grub theme installation command has failed." ; + + +CALAMARES_PLUGIN_FACTORY_DEFINITION(PacstrapBaseJobFactory , registerPlugin<PacstrapBaseJob>() ;) diff --git a/src/modules/desktop/desktop.h b/src/modules/pacstrap-base/pacstrap-base.h index 0ba1e6742..48a9b8b1a 100644 --- a/src/modules/desktop/desktop.h +++ b/src/modules/pacstrap-base/pacstrap-base.h @@ -16,43 +16,37 @@ * along with Calamares. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef DESKTOPCPPJOB_H -#define DESKTOPCPPJOB_H +#ifndef PACSTRAP_BASE_H +#define PACSTRAP_BASE_H -#include <QObject> -#include <QVariantMap> - -#include <CppJob.h> -#include <utils/PluginFactory.h> +#include <PacstrapCppJob.h> #include <PluginDllMacro.h> +#include <utils/PluginFactory.h> -class PLUGINDLLEXPORT DesktopCppJob : public Calamares::CppJob +class PLUGINDLLEXPORT PacstrapBaseJob : public PacstrapCppJob { Q_OBJECT -public: - DesktopCppJob(QObject* parent = nullptr) ; - virtual ~DesktopCppJob() ; +public: - QString prettyName() const override ; - QString prettyStatusMessage() const override ; - Calamares::JobResult exec() override ; + explicit PacstrapBaseJob(QObject* parent = nullptr) ; - void setConfigurationMap(const QVariantMap& configurationMap) override ; +protected: -private: + QString getPackageList() override ; + QString chrootExec () override ; - static QString QListToString(const QVariantList& package_list) ; +private: - QVariantMap m_configurationMap ; - QString m_status ; + static const QString GRUB_THEME_FMT ; + static const QString GRUB_THEME_ERROR_MSG ; } ; -CALAMARES_PLUGIN_FACTORY_DECLARATION(DesktopCppJobFactory) +CALAMARES_PLUGIN_FACTORY_DECLARATION(PacstrapBaseJobFactory) -#endif // DESKTOPCPPJOB_H +#endif // PACSTRAP_BASE_H diff --git a/src/modules/desktop/CMakeLists.txt b/src/modules/pacstrap-gui/CMakeLists.txt index 01261451f..9d473c17e 100644 --- a/src/modules/desktop/CMakeLists.txt +++ b/src/modules/pacstrap-gui/CMakeLists.txt @@ -1,8 +1,8 @@ -calamares_add_plugin( desktop +calamares_add_plugin( pacstrap-gui TYPE job EXPORT_MACRO PLUGINDLLEXPORT_PRO SOURCES - desktop.cpp + pacstrap-gui.cpp LINK_PRIVATE_LIBRARIES calamares SHARED_LIB diff --git a/src/modules/pacstrap-gui/module.desc b/src/modules/pacstrap-gui/module.desc new file mode 100644 index 000000000..64280d6a6 --- /dev/null +++ b/src/modules/pacstrap-gui/module.desc @@ -0,0 +1,5 @@ +--- +type: "job" +name: "pacstrap-gui" +interface: "qtplugin" +load: "libcalamares_job_pacstrap-gui.so" diff --git a/src/modules/desktop/desktop.conf b/src/modules/pacstrap-gui/pacstrap-gui.conf index b7e04b9ed..60018a766 100644 --- a/src/modules/desktop/desktop.conf +++ b/src/modules/pacstrap-gui/pacstrap-gui.conf @@ -37,7 +37,7 @@ utilities: - "zenity" - "zip" -xserver: +x-server: - "ttf-dejavu" - "xorg" - "xorg-drivers" diff --git a/src/modules/pacstrap-gui/pacstrap-gui.cpp b/src/modules/pacstrap-gui/pacstrap-gui.cpp new file mode 100644 index 000000000..a21d3a022 --- /dev/null +++ b/src/modules/pacstrap-gui/pacstrap-gui.cpp @@ -0,0 +1,80 @@ +/* === This file is part of Calamares - <http://github.com/calamares> === + * + * Copyright 2014, Teo Mrnjavac <teo@kde.org> (original dummypython code) + * Copyright 2016, Kevin Kofler <kevin.kofler@chello.at> + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <QProcess> + +#include "pacstrap-gui.h" + + +/* PacstrapGuiJob public instance methods */ + +PacstrapGuiJob::PacstrapGuiJob(QObject* parent) : PacstrapCppJob(tr(GUI_JOB_NAME) , + tr(GUI_STATUS_MSG) , + GUI_JOB_WEIGHT , + parent ) {} + + +/* PacstrapGuiJob protected getters/setters */ + +QString PacstrapGuiJob::getPackageList() +{ +globalStorage->insert(GS::DESKTOP_PACKAGES_KEY , MATE_PACKAGES_KEY) ; // TODO: per user option via globalStorage +DEBUG_TRACE_DESKTOPPACKAGES + + QString desktop = this->globalStorage->value(GS::DESKTOP_PACKAGES_KEY).toString() ; + + return (this->localStorage.value(APPLICATIONS_PACKAGES_KEY).toStringList() + + this->localStorage.value(MULTIMEDIA_PACKAGES_KEY ).toStringList() + + this->localStorage.value(NETWORK_PACKAGES_KEY ).toStringList() + + this->localStorage.value(THEMES_PACKAGES_KEY ).toStringList() + + this->localStorage.value(UTILITIES_PACKAGES_KEY ).toStringList() + + this->localStorage.value(XSERVER_PACKAGES_KEY ).toStringList() + + this->localStorage.value(desktop ).toStringList() ).join(' ') ; +} + + +/* PacstrapGuiJob protected instance methods */ + +QString PacstrapGuiJob::chrootExec() +{ + QString pacstrap_cmd = PACSTRAP_FMT .arg(this->confFile , MOUNTPOINT , packages) ; + QString wallpaper_cmd = WALLPAPER_FMT.arg(MOUNTPOINT) ; + + if (!!execStatus(pacstrap_cmd , CHROOT_TASK_PROPORTION)) return PACSTRAP_ERROR_MSG ; + +printf("[PACSTRAP-GUI]: ls /etc/skel\n") ; QProcess::execute(QString("/bin/sh -c \"ls -al /etc/skel/\"" ) ) ; +printf("[PACSTRAP-GUI]: ls chroot/etc/skel/\n") ; QProcess::execute(QString("/bin/sh -c \"ls -al %1/etc/skel/\"" ).arg(MOUNTPOINT)) ; +printf("[PACSTRAP-GUI]: ls chroot/etc/wallpaper.png\n") ; QProcess::execute(QString("/bin/sh -c \"ls -al %1/etc/wallpaper.png\"").arg(MOUNTPOINT)) ; +printf("[PACSTRAP-GUI]: ls chroot/etc/sudoers*\n") ; QProcess::execute(QString("/bin/sh -c \"ls -al %1/etc/sudoers*\"" ).arg(MOUNTPOINT)) ; + + if (!!execStatus(wallpaper_cmd)) return WALLPAPER_ERROR_MSG ; + +printf("[PACSTRAP-GUI]: ls chroot/etc/wallpaper.png\n") ; QProcess::execute(QString("/bin/sh -c \"ls -al %1/etc/wallpaper.png\"").arg(MOUNTPOINT)) ; + + return QString("") ; +} + + +/* PacstrapGuiJob private class constants */ + +const QString PacstrapGuiJob::WALLPAPER_FMT = "cp /etc/wallpaper.png %1/etc/" ; +const QString PacstrapGuiJob::WALLPAPER_ERROR_MSG = "The wallpaper installation command has failed." ; + + +CALAMARES_PLUGIN_FACTORY_DEFINITION(PacstrapGuiJobFactory , registerPlugin<PacstrapGuiJob>() ;) diff --git a/src/modules/pacstrap/pacstrap.h b/src/modules/pacstrap-gui/pacstrap-gui.h index 7ffddb667..6e310f18a 100644 --- a/src/modules/pacstrap/pacstrap.h +++ b/src/modules/pacstrap-gui/pacstrap-gui.h @@ -16,44 +16,37 @@ * along with Calamares. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef PACSTRAPCPPJOB_H -#define PACSTRAPCPPJOB_H +#ifndef PACSTRAP_GUI_H +#define PACSTRAP_GUI_H -#include <QObject> -#include <QVariantMap> - -#include <CppJob.h> -#include <utils/PluginFactory.h> +#include <PacstrapCppJob.h> #include <PluginDllMacro.h> +#include <utils/PluginFactory.h> -class PLUGINDLLEXPORT PacstrapCppJob : public Calamares::CppJob +class PLUGINDLLEXPORT PacstrapGuiJob : public PacstrapCppJob { - Q_OBJECT + Q_OBJECT -public: - explicit PacstrapCppJob(QObject* parent = nullptr) ; - virtual ~PacstrapCppJob() ; +public: - QString prettyName() const override ; - QString prettyStatusMessage() const override ; - Calamares::JobResult exec() override ; + explicit PacstrapGuiJob(QObject* parent = nullptr) ; - void setConfigurationMap(const QVariantMap& configurationMap) override ; +protected: -private: + QString getPackageList() override ; + QString chrootExec () override ; - void setTargetDevice() ; - static QString QListToString(const QVariantList& package_list) ; +private: - QVariantMap m_configurationMap ; - QString m_status ; + static const QString WALLPAPER_FMT ; + static const QString WALLPAPER_ERROR_MSG ; } ; -CALAMARES_PLUGIN_FACTORY_DECLARATION( PacstrapCppJobFactory ) +CALAMARES_PLUGIN_FACTORY_DECLARATION(PacstrapGuiJobFactory) -#endif // PACSTRAPCPPJOB_H +#endif // PACSTRAP_GUI_H diff --git a/src/modules/pacstrap/module.desc b/src/modules/pacstrap/module.desc deleted file mode 100644 index 37cfb122c..000000000 --- a/src/modules/pacstrap/module.desc +++ /dev/null @@ -1,5 +0,0 @@ ---- -type: "job" -name: "pacstrap" -interface: "qtplugin" -load: "libcalamares_job_pacstrap.so" diff --git a/src/modules/pacstrap/pacstrap.cpp b/src/modules/pacstrap/pacstrap.cpp deleted file mode 100644 index 739f7b037..000000000 --- a/src/modules/pacstrap/pacstrap.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* === This file is part of Calamares - <http://github.com/calamares> === - * - * Copyright 2014, Teo Mrnjavac <teo@kde.org> (original dummypython code) - * Copyright 2016, Kevin Kofler <kevin.kofler@chello.at> - * - * Calamares 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. - * - * Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include <QProcess> -#include <QDateTime> -#include <QThread> - -#include "CalamaresVersion.h" -#include "JobQueue.h" -#include "GlobalStorage.h" - -#include "pacstrap.h" -#include "utils/Logger.h" - - -PacstrapCppJob::PacstrapCppJob(QObject* parent) : Calamares::CppJob(parent) {} - -PacstrapCppJob::~PacstrapCppJob() {} - -QString PacstrapCppJob::prettyName() const { return tr("Pacstrap C++ Job") ; } - -QString PacstrapCppJob::prettyStatusMessage() const { return m_status ; } - -Calamares::JobResult PacstrapCppJob::exec() -{ -// Calamares::GlobalStorage *gs = Calamares::JobQueue::instance()->globalStorage(); -// foreach (const QString &key, gs->keys()) -// cDebug() << QString("[PACSTRAPCPP]: globalStorage[%1]=%2\n").arg( key, gs->value( key ).toString() ); - -// QProcess::execute( "echo SKIPPING parabola-prepare.desc" ); - - setTargetDevice() ; - - Calamares::GlobalStorage *globalStorage = Calamares::JobQueue::instance()->globalStorage() ; - bool has_internet = globalStorage->value("hasInternet" ).toBool() ; -has_internet = false ; - QString target_device = globalStorage->value("target-device").toString() ; - QString conf_file = (has_internet) ? "/etc/pacman.conf" : "/etc/pacman-offline.conf" ; - QString mountpoint = "/tmp/pacstrap"; - QString packages = QListToString(m_configurationMap.value("base" ).toList() + - m_configurationMap.value("bootloader").toList() + - m_configurationMap.value("kernel" ).toList() ) ; - - if (target_device.isEmpty()) return Calamares::JobResult::error("Target device for root filesystem is unspecified."); - -// QString keyring_cmd = "/bin/sh -c \"pacman -Sy --noconfirm parabola-keyring && \ -// pacman-key --populate parabola && \ -// pacman-key --refresh-keys \""; -// QString keyring_cmd = "/bin/sh -c \"pacman -Sy --noconfirm parabola-keyring\""; - QString mkdir_cmd = QString("/bin/sh -c \"mkdir %1 2> /dev/null\"").arg(mountpoint) ; - QString mount_cmd = QString("/bin/sh -c \"mount %1 %2\"").arg(target_device , mountpoint) ; -// QString pacstrap_cmd = (has_internet) ? QString("/bin/sh -c \"pacstrap-calamares -c %1 %2\"").arg(mountpoint , packages) : -// QString("/bin/sh -c \"pacstrap-calamares -c -o %1 %2\"").arg(mountpoint , packages) ; - QString pacstrap_cmd = QString("/bin/sh -c \"pacstrap -c -C %1 %2 %3\"").arg(conf_file , mountpoint , packages); - QString grub_theme_cmd = QString("/bin/sh -c \"sed -i 's|[#]GRUB_THEME=.*|GRUB_THEME=/boot/grub/themes/GNUAxiom/theme.txt|' %1/etc/default/grub\"").arg(mountpoint) ; -QString grub_theme_kludge_cmd = QString("/bin/sh -c \"echo GRUB_THEME=/boot/grub/themes/GNUAxiom/theme.txt >> %1/etc/default/grub\"").arg(mountpoint) ; - QString umount_cmd = QString("/bin/sh -c \"umount %1\"").arg(target_device) ; - -cDebug() << QString("[PACSTRAPCPP]: grub_theme_cmd=%1").arg(grub_theme_cmd); -// QProcess::execute( "/bin/sh -c \"ls /tmp/\"" ); - - // boot-strap install root filesystem - m_status = tr("Installing root filesystem") ; emit progress(1) ; -// QProcess::execute(keyring_cmd) ; - QProcess::execute(mkdir_cmd) ; - QProcess::execute(mount_cmd) ; - if (QProcess::execute(pacstrap_cmd)) return Calamares::JobResult::error("PACSTRAP_FAIL") ; -// m_status = tr( "Installing linux-libre kernel" ); emit progress( 5 ); - -cDebug() << QString( "[PACSTRAPCPP]: grub_theme_cmd IN" ); QProcess::execute( QString( "/bin/sh -c \"cat %1/etc/default/grub\"" ).arg( mountpoint ) ); - QProcess::execute(grub_theme_cmd) ; -QProcess::execute(grub_theme_kludge_cmd) ; -cDebug() << QString( "[PACSTRAPCPP]: grub_theme_cmd OUT" ); QProcess::execute( QString( "/bin/sh -c \"cat %1/etc/default/grub\"" ).arg( mountpoint ) ); - - emit progress(5) ; -// QProcess::execute( kernel_cmd ); - QProcess::execute(umount_cmd) ; - - emit progress(1) ; - - return Calamares::JobResult::ok() ; -} - -void PacstrapCppJob::setConfigurationMap(const QVariantMap& configurationMap) -{ - m_configurationMap = configurationMap ; -} - - -void PacstrapCppJob::setTargetDevice() -{ - Calamares::GlobalStorage *globalStorage = Calamares::JobQueue::instance()->globalStorage() ; - QString target_device = "" ; - QVariantList partitions = globalStorage->value("partitions").toList() ; - - // locate target device for root filesystem - foreach (const QVariant& partition , partitions) - { -QStringList result; for ( auto it = partition.toMap().constBegin(); it != partition.toMap().constEnd(); ++it ) result.append( it.key() + '=' + it.value().toString() ); -cDebug() << QString("[PACSTRAPCPP]: partition=%1").arg('[' + result.join(',') + ']'); - - QVariantMap partition_map = partition.toMap() ; - QString device = partition_map.value("device").toString(); - QString fs = partition_map.value("fs").toString(); - QString mountpoint = partition_map.value("mountPoint").toString(); - QString uuid = partition_map.value("uuid").toString() ; - - if (mountpoint == "/") target_device = device ; - -if (mountpoint == "/") cDebug() << QString("[PACSTRAPCPP]: target_device=%1").arg(device); - } - - globalStorage->insert("target-device" , target_device) ; -} - -QString PacstrapCppJob::QListToString(const QVariantList& package_list) -{ - QStringList result ; - for (const QVariant& package : package_list) result.append(package.toString()) ; - - return result.join(' ') ; -} - - -CALAMARES_PLUGIN_FACTORY_DEFINITION(PacstrapCppJobFactory , registerPlugin<PacstrapCppJob>() ;) diff --git a/src/modules/users/CreateUserJob.cpp b/src/modules/users/CreateUserJob.cpp index 63f1fa9b0..9872dbaf9 100644 --- a/src/modules/users/CreateUserJob.cpp +++ b/src/modules/users/CreateUserJob.cpp @@ -82,25 +82,23 @@ CreateUserJob::exec() else sudoersFilename += QStringLiteral( "10-parabola-installer" ); */ - QMap<QString, QVariant> brandingMap = gs->value( "branding" ).toMap(); - QString distroName = brandingMap.value( "shortProductName" ).toString(); - distroName = distroName.toLower().replace( QRegExp( "[^a-z0-9]" ), "-" ); - QString sudoersFilename = QString( "etc/sudoers.d/10-%1-installer" ).arg( distroName ); - QFileInfo sudoersFi( destDir.absoluteFilePath( sudoersFilename ) ); + QMap<QString, QVariant> brandingMap = gs->value( "branding" ).toMap(); + QString distroName = brandingMap.value( "shortProductName" ).toString(); + distroName = distroName.toLower().replace( QRegExp( "[^a-z0-9]" ), "-" ); + QString sudoersFilename = QString( "etc/sudoers.d/10-%1-installer" ).arg( distroName ); + QFileInfo sudoersFi( destDir.absoluteFilePath( sudoersFilename ) ); - cDebug() << QString("[CREATEUSER]: preparing sudoers") ; + cDebug() << QString("[CREATEUSER]: preparing sudoers") ; -cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() distroName=%1").arg(distroName); -cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() sudoersFilename=%1").arg(sudoersFilename); -cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() sudoersFi=%1").arg(sudoersFi.filePath()); -cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() isAbsolute=%2").arg(sudoersFi.isAbsolute()); -cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() isWritable=%3").arg(sudoersFi.isWritable()); QString etcdir = gs->value( "rootMountPoint" ).toString() + "/etc" ; -cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() ls -l %1").arg(etcdir) ; - QProcess::execute( QString( "/bin/sh -c \"ls -l %1\"" ).arg( etcdir ) ); -cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() ls -l %1").arg(sudoersFi.filePath()) ; - QProcess::execute( QString( "/bin/sh -c \"ls -l %1\"" ).arg( sudoersFi.filePath() ) ); - +cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() distroName=%1" ).arg(distroName); +cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() sudoersFilename=%1").arg(sudoersFilename); +cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() sudoersFi=%1" ).arg(sudoersFi.filePath()); +cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() isAbsolute=%1" ).arg(sudoersFi.isAbsolute()); +cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() exists=%1" ).arg(sudoersFi.absoluteDir().exists()); +cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() isWritable=%1" ).arg(sudoersFi.isWritable()); +cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() ls -l %1").arg(etcdir) ; QProcess::execute( QString( "/bin/sh -c \"ls -l %1\"" ).arg( etcdir ) ) ; +cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() ls -l %1").arg(sudoersFi.filePath()) ; QProcess::execute( QString( "/bin/sh -c \"ls -l %1\"" ).arg( sudoersFi.filePath() ) ) ; if ( !sudoersFi.absoluteDir().exists() ) return Calamares::JobResult::error( tr( "Sudoers dir is not writable." ) ); @@ -228,7 +226,7 @@ cDebug() << QString("[CREATEUSER]: CreateUserJob::exec() ls -al /home/%1/ - targ /* parabola-specific configuration */ // Calamares::GlobalStorage* globalStorage = Calamares::JobQueue::instance()->globalStorage(); - QString default_desktop = gs->value("default-desktop").toString(); + QString default_desktop = gs->value(GS::DESKTOP_PACKAGES_KEY).toString(); /* if [ -x /usr/bin/setxkbmap ]; then echo "setxkbmap $(cat /.codecheck | grep XKBMAP= | cut -d '=' -f 2)" >> /home/${user#*=}/.bashrc |