diff --git a/CHANGES b/CHANGES index 67edca8f0..1c364e7f8 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,18 @@ contributors are listed. Note that Calamares does not have a historical changelog -- this log starts with version 3.2.0. The release notes on the website will have to do for older versions. +# 3.2.21 (unreleased) # + +This release contains contributions from (alphabetically by first name): + - No external contributors yet + +## Core ## + - No core changes yet + +## Modules ## + - No module changes yet + + # 3.2.20 (2020-02-27) # This release contains contributions from (alphabetically by first name): diff --git a/CMakeLists.txt b/CMakeLists.txt index eee6c01b2..b7f332c87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,10 +40,10 @@ cmake_minimum_required( VERSION 3.3 FATAL_ERROR ) project( CALAMARES - VERSION 3.2.20 + VERSION 3.2.21 LANGUAGES C CXX ) -set( CALAMARES_VERSION_RC 0 ) # Set to 0 during release cycle, 1 during development +set( CALAMARES_VERSION_RC 1 ) # Set to 0 during release cycle, 1 during development ### OPTIONS # diff --git a/ci/calamaresstyle b/ci/calamaresstyle index 65dc83de7..ecbd798c5 100755 --- a/ci/calamaresstyle +++ b/ci/calamaresstyle @@ -6,6 +6,11 @@ # You can pass in directory names, in which case the files # in that directory (NOT below it) are processed. # +LANG=C +LC_ALL=C +LC_NUMERIC=C +export LANG LC_ALL LC_NUMERIC + AS=$( which astyle ) for _cf in clang-format-7 clang-format-8 clang-format70 clang-format80 clang-format diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index 0e207fa02..ceca20b7a 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -44,6 +44,10 @@ static unsigned int s_threshold = #endif static QMutex s_mutex; +static const char s_Continuation[] = "\n "; +static const char s_SubEntry[] = " .. "; + + namespace Logger { @@ -172,22 +176,39 @@ setupLogfile() qInstallMessageHandler( CalamaresLogHandler ); } -CLog::CLog( unsigned int debugLevel ) +CDebug::CDebug( unsigned int debugLevel, const char* func ) : QDebug( &m_msg ) , m_debugLevel( debugLevel ) + , m_funcinfo( func ) { + if ( debugLevel <= LOGERROR ) + { + m_msg = QStringLiteral( "ERROR:" ); + } + else if ( debugLevel <= LOGWARNING ) + { + m_msg = QStringLiteral( "WARNING:" ); + } } -CLog::~CLog() +CDebug::~CDebug() { + if ( m_funcinfo ) + { + m_msg.prepend( s_Continuation ); // Prepending, so back-to-front + m_msg.prepend( m_funcinfo ); + } log( m_msg.toUtf8().data(), m_debugLevel ); } -CDebug::~CDebug() {} +constexpr FuncSuppressor::FuncSuppressor( const char s[] ) + : m_s( s ) +{ +} -const char Continuation[] = "\n "; -const char SubEntry[] = " .. "; +const constexpr FuncSuppressor Continuation( s_Continuation ); +const constexpr FuncSuppressor SubEntry( s_SubEntry ); QString toString( const QVariant& v ) diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 33954bd37..fe4b98fd4 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -27,8 +27,14 @@ namespace Logger { -DLLEXPORT extern const char Continuation[]; -DLLEXPORT extern const char SubEntry[]; +struct FuncSuppressor +{ + explicit constexpr FuncSuppressor( const char[] ); + const char* m_s; +}; + +DLLEXPORT extern const FuncSuppressor Continuation; +DLLEXPORT extern const FuncSuppressor SubEntry; enum { @@ -41,34 +47,32 @@ enum LOGVERBOSE = 8 }; -class DLLEXPORT CLog : public QDebug +class DLLEXPORT CDebug : public QDebug { public: - explicit CLog( unsigned int debugLevel ); - virtual ~CLog(); + explicit CDebug( unsigned int debugLevel = LOGDEBUG, const char* func = nullptr ); + virtual ~CDebug(); + + friend QDebug& operator<<( CDebug&&, const FuncSuppressor& ); private: QString m_msg; unsigned int m_debugLevel; + const char* m_funcinfo = nullptr; }; -class DLLEXPORT CDebug : public CLog +inline QDebug& +operator<<( CDebug&& s, const FuncSuppressor& f ) { -public: - CDebug( unsigned int debugLevel = LOGDEBUG ) - : CLog( debugLevel ) - { - if ( debugLevel <= LOGERROR ) - { - *this << "ERROR:"; - } - else if ( debugLevel <= LOGWARNING ) - { - *this << "WARNING:"; - } - } - virtual ~CDebug(); -}; + s.m_funcinfo = nullptr; + return s << f.m_s; +} + +inline QDebug& +operator<<( QDebug& s, const FuncSuppressor& f ) +{ + return s << f.m_s; +} /** * @brief The full path of the log file. @@ -219,8 +223,8 @@ operator<<( QDebug& s, const DebugMap& t ) } } // namespace Logger -#define cDebug() (Logger::CDebug( Logger::LOGDEBUG ) << Q_FUNC_INFO << Logger::Continuation) -#define cWarning() Logger::CDebug( Logger::LOGWARNING ) -#define cError() Logger::CDebug( Logger::LOGERROR ) +#define cDebug() Logger::CDebug( Logger::LOGDEBUG, Q_FUNC_INFO ) +#define cWarning() Logger::CDebug( Logger::LOGWARNING, Q_FUNC_INFO ) +#define cError() Logger::CDebug( Logger::LOGERROR, Q_FUNC_INFO ) #endif diff --git a/src/modules/partition/jobs/CreatePartitionTableJob.cpp b/src/modules/partition/jobs/CreatePartitionTableJob.cpp index 20a3c7e6a..b18f56a04 100644 --- a/src/modules/partition/jobs/CreatePartitionTableJob.cpp +++ b/src/modules/partition/jobs/CreatePartitionTableJob.cpp @@ -69,7 +69,7 @@ CreatePartitionTableJob::prettyStatusMessage() const static inline QDebug& -operator <<( QDebug& s, PartitionIterator& it ) +operator <<( QDebug&& s, PartitionIterator& it ) { s << ( ( *it ) ? ( *it )->deviceNode() : QString( "" ) ); return s; diff --git a/src/modules/removeuser/CMakeLists.txt b/src/modules/removeuser/CMakeLists.txt new file mode 100644 index 000000000..55798feac --- /dev/null +++ b/src/modules/removeuser/CMakeLists.txt @@ -0,0 +1,9 @@ +calamares_add_plugin( removeuser + TYPE job + EXPORT_MACRO PLUGINDLLEXPORT_PRO + SOURCES + RemoveUserJob.cpp + LINK_PRIVATE_LIBRARIES + calamares + SHARED_LIB +) diff --git a/src/modules/removeuser/RemoveUserJob.cpp b/src/modules/removeuser/RemoveUserJob.cpp new file mode 100644 index 000000000..0488d19a4 --- /dev/null +++ b/src/modules/removeuser/RemoveUserJob.cpp @@ -0,0 +1,74 @@ +/* === This file is part of Calamares - === + * + * Copyright 2015, Teo Mrnjavac + * Copyright 2017. Alf Gaida + * Copyright 2019-2020, Adriaan de Groot + * + * 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 . + */ + +#include "RemoveUserJob.h" + +#include "GlobalStorage.h" +#include "JobQueue.h" +#include "utils/CalamaresUtilsSystem.h" +#include "utils/Logger.h" +#include "utils/Variant.h" + +#include + +RemoveUserJob::RemoveUserJob( QObject* parent ) + : Calamares::CppJob( parent ) +{ +} + + +RemoveUserJob::~RemoveUserJob() {} + + +QString +RemoveUserJob::prettyName() const +{ + return tr( "Remove live user from target system" ); +} + +Calamares::JobResult +RemoveUserJob::exec() +{ + if ( m_username.isEmpty() ) + { + cWarning() << "Ignoring an empty username."; + return Calamares::JobResult::ok(); + } + + auto* s = CalamaresUtils::System::instance(); + auto r = s->targetEnvCommand( { QStringLiteral( "userdel" ), + QStringLiteral( "-f" ), // force + QStringLiteral( "-r" ), // remove home-dir and mail + m_username } ); + if ( r.getExitCode() != 0 ) + { + cWarning() << "Cannot remove user" << m_username << "userdel terminated with exit code" << r.getExitCode(); + } + return Calamares::JobResult::ok(); +} + + +void +RemoveUserJob::setConfigurationMap( const QVariantMap& map ) +{ + m_username = CalamaresUtils::getString( map, "username" ); +} + +CALAMARES_PLUGIN_FACTORY_DEFINITION( RemoveUserJobFactory, registerPlugin< RemoveUserJob >(); ) diff --git a/src/modules/removeuser/RemoveUserJob.h b/src/modules/removeuser/RemoveUserJob.h new file mode 100644 index 000000000..d13e834f0 --- /dev/null +++ b/src/modules/removeuser/RemoveUserJob.h @@ -0,0 +1,49 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, Adriaan de Groot + * + * 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 . + */ + +#ifndef REMOVEUSERJOB_H +#define REMOVEUSERJOB_H + +#include "CppJob.h" +#include "DllMacro.h" +#include "utils/PluginFactory.h" + +#include +#include + +class PLUGINDLLEXPORT RemoveUserJob : public Calamares::CppJob +{ + Q_OBJECT + +public: + explicit RemoveUserJob( QObject* parent = nullptr ); + virtual ~RemoveUserJob() override; + + QString prettyName() const override; + + Calamares::JobResult exec() override; + + void setConfigurationMap( const QVariantMap& configurationMap ) override; + +private: + QString m_username; +}; + +CALAMARES_PLUGIN_FACTORY_DECLARATION( RemoveUserJobFactory ) + +#endif // REMOVEUSERJOB_H diff --git a/src/modules/removeuser/main.py b/src/modules/removeuser/main.py deleted file mode 100644 index bd876edcd..000000000 --- a/src/modules/removeuser/main.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# === This file is part of Calamares - === -# -# Copyright 2015, Teo Mrnjavac -# Copyright 2017. Alf Gaida -# Copyright 2019, Adriaan de Groot -# -# 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 . - -import subprocess -import libcalamares - -import gettext -_ = gettext.translation("calamares-python", - localedir=libcalamares.utils.gettext_path(), - languages=libcalamares.utils.gettext_languages(), - fallback=True).gettext - - -def pretty_name(): - return _("Remove live user from target system") - - -def run(): - """ - Remove live user from target system - """ - username = libcalamares.job.configuration["username"] - - try: - libcalamares.utils.check_target_env_call(["userdel", "-f", - "-r", username]) - except subprocess.CalledProcessError as e: - libcalamares.utils.debug("Cannot remove user. " - "'userdel' terminated with exit code " - "{}.".format(e.returncode)) - return None diff --git a/src/modules/removeuser/module.desc b/src/modules/removeuser/module.desc deleted file mode 100644 index 5c6fc6fb7..000000000 --- a/src/modules/removeuser/module.desc +++ /dev/null @@ -1,6 +0,0 @@ ---- -type: "job" -name: "removeuser" -interface: "python" -requires: [] -script: "main.py" diff --git a/src/modules/removeuser/removeuser.conf b/src/modules/removeuser/removeuser.conf index dab4b2526..d266e6952 100644 --- a/src/modules/removeuser/removeuser.conf +++ b/src/modules/removeuser/removeuser.conf @@ -1,6 +1,10 @@ # Removes a single user (with userdel) from the system. # This is typically used in OEM setups or if the live user # spills into the target system. +# +# The module never fails; if userdel fails, this is logged +# but the module still reports success and installation / setup +# continues as normal. --- # Username in the target system to be removed. username: live