Merge branch 'master' of https://github.com/calamares/calamares into development

This commit is contained in:
Philip Müller 2020-03-05 05:34:19 +01:00
commit c52aeb3856
12 changed files with 210 additions and 88 deletions

12
CHANGES
View File

@ -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):

View File

@ -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
#

View File

@ -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

View File

@ -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 )

View File

@ -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

View File

@ -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( "<null device>" ) );
return s;

View File

@ -0,0 +1,9 @@
calamares_add_plugin( removeuser
TYPE job
EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES
RemoveUserJob.cpp
LINK_PRIVATE_LIBRARIES
calamares
SHARED_LIB
)

View File

@ -0,0 +1,74 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017. Alf Gaida <agaida@siduction.org>
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
*
* 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 "RemoveUserJob.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "utils/CalamaresUtilsSystem.h"
#include "utils/Logger.h"
#include "utils/Variant.h"
#include <QFile>
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 >(); )

View File

@ -0,0 +1,49 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2020, Adriaan de Groot <groot@kde.org>
*
* 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/>.
*/
#ifndef REMOVEUSERJOB_H
#define REMOVEUSERJOB_H
#include "CppJob.h"
#include "DllMacro.h"
#include "utils/PluginFactory.h"
#include <QObject>
#include <QVariantMap>
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

View File

@ -1,50 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# === This file is part of Calamares - <https://github.com/calamares> ===
#
# Copyright 2015, Teo Mrnjavac <teo@kde.org>
# Copyright 2017. Alf Gaida <agaida@siduction.org>
# Copyright 2019, Adriaan de Groot <groot@kde.org>
#
# 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/>.
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

View File

@ -1,6 +0,0 @@
---
type: "job"
name: "removeuser"
interface: "python"
requires: []
script: "main.py"

View File

@ -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