diff --git a/CHANGES b/CHANGES index cb807cdc4..377aa2271 100644 --- a/CHANGES +++ b/CHANGES @@ -31,6 +31,14 @@ This release contains contributions from (alphabetically by first name): "fancy" release notes as a QML application, rather than a webview or text widget. Note that this does not replace the slideshow-during- installation module. + - The *users* module now has knobs for setting the hostname and writing + the `/etc/hosts` file. The new configuration options are documented + in `users.conf`. #1140 + - Multiple *netinstall* modules can exist side-by-side, and they each + control the package installation for their part of the package list. + Previously, a netinstall module would overwrite all of the package + configuration done by other netinstall modules. + #1303 # 3.2.18 (2020-01-28) # diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bfe0fbab..479009faf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -549,10 +549,11 @@ install( "${PROJECT_BINARY_DIR}/CalamaresConfig.cmake" "${PROJECT_BINARY_DIR}/CalamaresConfigVersion.cmake" "${PROJECT_BINARY_DIR}/CalamaresUse.cmake" - "CMakeModules/CalamaresAddPlugin.cmake" - "CMakeModules/CalamaresAddModuleSubdirectory.cmake" - "CMakeModules/CalamaresAddLibrary.cmake" "CMakeModules/CalamaresAddBrandingSubdirectory.cmake" + "CMakeModules/CalamaresAddLibrary.cmake" + "CMakeModules/CalamaresAddModuleSubdirectory.cmake" + "CMakeModules/CalamaresAddPlugin.cmake" + "CMakeModules/CalamaresAddTest.cmake" "CMakeModules/CalamaresAddTranslations.cmake" "CMakeModules/CalamaresAutomoc.cmake" "CMakeModules/CMakeColors.cmake" diff --git a/CMakeModules/CalamaresAddTest.cmake b/CMakeModules/CalamaresAddTest.cmake new file mode 100644 index 000000000..f1f6fdf3f --- /dev/null +++ b/CMakeModules/CalamaresAddTest.cmake @@ -0,0 +1,58 @@ +# === This file is part of Calamares - === +# +# 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 . +# +# SPDX-License-Identifier: GPL-3.0+ +# License-Filename: LICENSE +# +### +# +# Support functions for building Calamares tests. +# This extends KDE's ECM tests with some custom patterns. +# +# calamares_add_test( +# +# [GUI] +# SOURCES +# ) + +include( CMakeParseArguments ) +include( CalamaresAutomoc ) + +function( calamares_add_test ) + # parse arguments (name needs to be saved before passing ARGN into the macro) + set( NAME ${ARGV0} ) + set( options GUI ) + set( multiValueArgs SOURCES LIBRARIES ) + cmake_parse_arguments( TEST "${options}" "" "${multiValueArgs}" ${ARGN} ) + set( TEST_NAME ${NAME} ) + + if( ECM_FOUND AND BUILD_TESTING ) + ecm_add_test( + ${TEST_SOURCES} + TEST_NAME + ${TEST_NAME} + LINK_LIBRARIES + calamares + ${TEST_LIBRARIES} + Qt5::Core + Qt5::Test + ) + calamares_automoc( ${TEST_NAME} ) + target_compile_definitions( ${TEST_NAME} PRIVATE -DBUILD_AS_TEST ) + if( TEST_GUI ) + target_link_libraries( ${TEST_NAME} calamaresui Qt5::Gui ) + endif() + endif() +endfunction() diff --git a/CMakeModules/FindYAMLCPP.cmake b/CMakeModules/FindYAMLCPP.cmake index 1ec9798d5..395c794bb 100644 --- a/CMakeModules/FindYAMLCPP.cmake +++ b/CMakeModules/FindYAMLCPP.cmake @@ -1,9 +1,11 @@ # Locate yaml-cpp # # This module defines -# YAMLCPP_FOUND, if false, do not try to link to yaml-cpp -# YAMLCPP_LIBRARY, where to find yaml-cpp -# YAMLCPP_INCLUDE_DIR, where to find yaml.h +# YAMLCPP_FOUND, if false, do not try to link to yaml-cpp +# YAMLCPP_LIBRARY, where to find yaml-cpp +# YAMLCPP_INCLUDE_DIR, where to find yaml.h +# There is also one IMPORTED library target, +# yamlcpp # # By default, the dynamic libraries of yaml-cpp will be found. To find the static ones instead, # you must set the YAMLCPP_STATIC_LIBRARY variable to TRUE before calling find_package(YamlCpp ...). @@ -48,3 +50,12 @@ find_library(YAMLCPP_LIBRARY include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(YAMLCPP DEFAULT_MSG YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY) mark_as_advanced(YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY) + +# Add an imported target +if( YAMLCPP_LIBRARY ) + add_library( yamlcpp UNKNOWN IMPORTED ) + set_property( TARGET yamlcpp PROPERTY IMPORTED_LOCATION ${YAMLCPP_LIBRARY} ) + if ( YAMLCPP_INCLUDE_DIR ) + set_property( TARGET yamlcpp PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${YAMLCPP_INCLUDE_DIR} ) + endif() +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b73fecda0..1445b18f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,7 @@ include( CalamaresAddPlugin ) include( CalamaresAddModuleSubdirectory ) include( CalamaresAddLibrary ) include( CalamaresAddBrandingSubdirectory ) +include( CalamaresAddTest ) # library add_subdirectory( libcalamares ) diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index a55e26b6d..9327af8e3 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -1,5 +1,3 @@ -add_definitions( -DUIDLLEXPORT_PRO ) - set( calamaresSources main.cpp CalamaresApplication.cpp diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index cad7e7a6e..803c46870 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -74,7 +74,6 @@ mark_thirdparty_code( ${kdsagSources} ) include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} - ${YAMLCPP_INCLUDE_DIR} ) ### OPTIONAL Python support @@ -126,7 +125,7 @@ target_link_libraries( calamares LINK_PRIVATE ${OPTIONAL_PRIVATE_LIBRARIES} LINK_PUBLIC - ${YAMLCPP_LIBRARY} + yamlcpp Qt5::Core KF5::CoreAddons ${OPTIONAL_PUBLIC_LIBRARIES} @@ -159,85 +158,51 @@ install( FILES ${utilsHeaders} DESTINATION include/libcalam ### TESTING # # -if ( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( - utils/Tests.cpp - TEST_NAME - libcalamarestest - LINK_LIBRARIES - calamares - Qt5::Core - Qt5::Test - ) - calamares_automoc( libcalamarestest ) +calamares_add_test( + libcalamarestest + SOURCES + utils/Tests.cpp +) - ecm_add_test( - utils/TestPaths.cpp - TEST_NAME - libcalamarestestpaths - LINK_LIBRARIES - calamares - Qt5::Core - Qt5::Test - ) - calamares_automoc( libcalamarestestpaths ) +calamares_add_test( + libcalamarestestpaths + SOURCES + utils/TestPaths.cpp +) +calamares_add_test( + geoiptest + SOURCES + geoip/GeoIPTests.cpp + ${geoip_src} +) - ecm_add_test( - geoip/GeoIPTests.cpp - ${geoip_src} - TEST_NAME - geoiptest - LINK_LIBRARIES - calamares - Qt5::Test - ${YAMLCPP_LIBRARY} - ) - calamares_automoc( geoiptest ) +calamares_add_test( + libcalamarespartitiontest + SOURCES + partition/Tests.cpp +) - ecm_add_test( - partition/Tests.cpp - TEST_NAME - libcalamarespartitiontest - LINK_LIBRARIES - calamares - Qt5::Test - ) - calamares_automoc( libcalamarespartitiontest ) +calamares_add_test( + libcalamareslocaletest + SOURCES + locale/Tests.cpp +) - ecm_add_test( - locale/Tests.cpp - TEST_NAME - libcalamareslocaletest - LINK_LIBRARIES - calamares - Qt5::Test - ) - calamares_automoc( libcalamareslocaletest ) +calamares_add_test( + libcalamaresnetworktest + SOURCES + network/Tests.cpp +) - ecm_add_test( - network/Tests.cpp - TEST_NAME - libcalamaresnetworktest - LINK_LIBRARIES - calamares - Qt5::Test - ) - calamares_automoc( libcalamaresnetworktest ) - - ecm_add_test( - modulesystem/Tests.cpp - TEST_NAME - libcalamaresmodulesystemtest - LINK_LIBRARIES - calamares - Qt5::Test - ) - calamares_automoc( libcalamaresmodulesystemtest ) -endif() +calamares_add_test( + libcalamaresmodulesystemtest + SOURCES + modulesystem/Tests.cpp +) if( BUILD_TESTING ) add_executable( test_geoip geoip/test_geoip.cpp ${geoip_src} ) - target_link_libraries( test_geoip calamares Qt5::Network ${YAMLCPP_LIBRARY} ) + target_link_libraries( test_geoip calamares Qt5::Network yamlcpp ) calamares_automoc( test_geoip ) endif() diff --git a/src/libcalamares/DllMacro.h b/src/libcalamares/DllMacro.h index d3e1c8098..712bf5732 100644 --- a/src/libcalamares/DllMacro.h +++ b/src/libcalamares/DllMacro.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Teo Mrnjavac + * 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 @@ -21,6 +22,10 @@ #include +/* + * Mark symbols exported from Calamares non-GUI library with DLLEXPORT. + * These are the public API of libcalamares. + */ #ifndef DLLEXPORT #if defined( DLLEXPORT_PRO ) #define DLLEXPORT Q_DECL_EXPORT @@ -29,4 +34,42 @@ #endif #endif +/* + * Mark symbols exported from Calamares GUI library with DLLEXPORT. + * These are the public API of libcalamaresui. + */ +#ifndef UIDLLEXPORT +#if defined( UIDLLEXPORT_PRO ) +#define UIDLLEXPORT Q_DECL_EXPORT +#else +#define UIDLLEXPORT Q_DECL_IMPORT +#endif +#endif + +/* + * Mark symbols exported from Calamares C++ plugins with PLUGINDLLEXPORT. + * These are the public API of the libraries (generally, the plugin + * entry point) + */ +#ifndef PLUGINDLLEXPORT +#if defined( PLUGINDLLEXPORT_PRO ) +#define PLUGINDLLEXPORT Q_DECL_EXPORT +#else +#define PLUGINDLLEXPORT Q_DECL_IMPORT +#endif +#endif + +/* + * For functions that should be static in production but also need to + * be tested, use STATICTEST as linkage specifier. When built as part + * of a test, the function will be given normal linkage. + */ +#ifndef STATICTEST +#if defined( BUILD_AS_TEST ) +#define STATICTEST +#else +#define STATICTEST static +#endif +#endif + #endif diff --git a/src/libcalamares/PluginDllMacro.h b/src/libcalamares/PluginDllMacro.h deleted file mode 100644 index d790230b9..000000000 --- a/src/libcalamares/PluginDllMacro.h +++ /dev/null @@ -1,32 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2014, Teo Mrnjavac - * - * 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 PLUGINDLLMACRO_H -#define PLUGINDLLMACRO_H - -#include - -#ifndef PLUGINDLLEXPORT -#if defined( PLUGINDLLEXPORT_PRO ) -#define PLUGINDLLEXPORT Q_DECL_EXPORT -#else -#define PLUGINDLLEXPORT Q_DECL_IMPORT -#endif -#endif - -#endif diff --git a/src/libcalamares/network/Tests.cpp b/src/libcalamares/network/Tests.cpp index 3a15b3c59..830545b96 100644 --- a/src/libcalamares/network/Tests.cpp +++ b/src/libcalamares/network/Tests.cpp @@ -47,6 +47,6 @@ NetworkTests::testPing() using namespace CalamaresUtils::Network; Logger::setupLogLevel( Logger::LOGVERBOSE ); auto& nam = Manager::instance(); - auto r = nam.synchronousPing( QUrl( "https://www.kde.org" ), RequestOptions( RequestOptions::FollowRedirect ) ); - QVERIFY( r ); + auto canPing_www_kde_org = nam.synchronousPing( QUrl( "https://www.kde.org" ), RequestOptions( RequestOptions::FollowRedirect ) ); + QVERIFY( canPing_www_kde_org ); } diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index 61e05976a..8bd696bf0 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -293,19 +293,19 @@ System::targetPath( const QString& path ) const } } -QString +CreationResult System::createTargetFile( const QString& path, const QByteArray& contents ) const { QString completePath = targetPath( path ); if ( completePath.isEmpty() ) { - return QString(); + return CreationResult( CreationResult::Code::Invalid ); } QFile f( completePath ); if ( f.exists() ) { - return QString(); + return CreationResult( CreationResult::Code::AlreadyExists ); } QIODevice::OpenMode m = @@ -317,18 +317,18 @@ System::createTargetFile( const QString& path, const QByteArray& contents ) cons if ( !f.open( m ) ) { - return QString(); + return CreationResult( CreationResult::Code::Failed ); } if ( f.write( contents ) != contents.size() ) { f.close(); f.remove(); - return QString(); + return CreationResult( CreationResult::Code::Failed ); } f.close(); - return QFileInfo( f ).canonicalFilePath(); + return CreationResult( QFileInfo( f ).canonicalFilePath() ); } void diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index ca8e0d797..900634a74 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -84,6 +84,41 @@ public: } }; +/** @brief The result of a create*() action, for status + * + * A CreationResult has a status field, can be converted to bool + * (true only on success) and can report the full pathname of + * the thing created if it was successful. + */ +class CreationResult : public QPair< int, QString > +{ +public: + enum class Code : int + { + // These are "not failed", but only OK is a success + OK = 0, + AlreadyExists = 1, + // These are "failed" + Invalid = -1, + Failed = -2 + }; + + CreationResult( Code r ) + : QPair< int, QString >( static_cast< int >( r ), QString() ) + { + } + explicit CreationResult( const QString& path ) + : QPair< int, QString >( 0, path ) + { + } + + Code code() const { return static_cast< Code >( first ); } + QString path() const { return second; } + + bool failed() const { return first < 0; } + operator bool() const { return first == 0; } +}; + /** * @brief The System class is a singleton with utility functions that perform * system-specific operations. @@ -244,7 +279,7 @@ public: * root of the host system, or empty on failure. (Here, it is * possible to be canonical because the file exists). */ - DLLEXPORT QString createTargetFile( const QString& path, const QByteArray& contents ) const; + DLLEXPORT CreationResult createTargetFile( const QString& path, const QByteArray& contents ) const; /** @brief Remove a file from the target system. * diff --git a/src/libcalamares/utils/TestPaths.cpp b/src/libcalamares/utils/TestPaths.cpp index da67f9dd2..612c8f97d 100644 --- a/src/libcalamares/utils/TestPaths.cpp +++ b/src/libcalamares/utils/TestPaths.cpp @@ -46,6 +46,7 @@ private Q_SLOTS: void init(); void cleanupTestCase(); + void testCreationResult(); void testTargetPath(); void testCreateTarget(); void testCreateTargetBasedirs(); @@ -95,6 +96,42 @@ TestPaths::init() m_gs->insert( "rootMountPoint", "/tmp" ); } +void TestPaths::testCreationResult() +{ + using Code = CalamaresUtils::CreationResult::Code; + + for( auto c : { Code::OK, Code::AlreadyExists, Code::Failed, Code::Invalid } ) + { + auto r = CalamaresUtils::CreationResult( c ); + QVERIFY( r.path().isEmpty() ); + QCOMPARE( r.path(), QString() ); + // Get a warning from Clang if we're not covering everything + switch( r.code() ) + { + case Code::OK: + QVERIFY( !r.failed() ); + QVERIFY( r ); + break; + case Code::AlreadyExists: + QVERIFY( !r.failed() ); + QVERIFY( !r ); + break; + case Code::Failed: + case Code::Invalid: + QVERIFY( r.failed() ); + QVERIFY( !r ); + break; + } + } + + QString path( "/etc/os-release" ); + auto r = CalamaresUtils::CreationResult( path ); + QVERIFY( !r.failed() ); + QVERIFY( r ); + QCOMPARE( r.code(), Code::OK ); + QCOMPARE( r.path(), path ); +} + void TestPaths::testTargetPath() @@ -117,7 +154,10 @@ TestPaths::testTargetPath() void TestPaths::testCreateTarget() { - QCOMPARE( m_system->createTargetFile( testFile, "Hello" ), QString( absFile ) ); // Success + auto r = m_system->createTargetFile( testFile, "Hello" ); + QVERIFY( !r.failed() ); + QVERIFY( r ); + QCOMPARE( r.path(), QString( absFile ) ); // Success QFileInfo fi( absFile ); QVERIFY( fi.exists() ); diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index e3952881e..f1b26fbb5 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -22,7 +22,7 @@ #ifndef BRANDING_H #define BRANDING_H -#include "UiDllMacro.h" +#include "DllMacro.h" #include "utils/NamedSuffix.h" diff --git a/src/libcalamaresui/UiDllMacro.h b/src/libcalamaresui/UiDllMacro.h deleted file mode 100644 index 3064ca68c..000000000 --- a/src/libcalamaresui/UiDllMacro.h +++ /dev/null @@ -1,32 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2014, Teo Mrnjavac - * - * 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 UIDLLMACRO_H -#define UIDLLMACRO_H - -#include - -#ifndef UIDLLEXPORT -#if defined( UIDLLEXPORT_PRO ) -#define UIDLLEXPORT Q_DECL_EXPORT -#else -#define UIDLLEXPORT Q_DECL_IMPORT -#endif -#endif - -#endif diff --git a/src/libcalamaresui/ViewManager.h b/src/libcalamaresui/ViewManager.h index fca74a367..42fb9ad8f 100644 --- a/src/libcalamaresui/ViewManager.h +++ b/src/libcalamaresui/ViewManager.h @@ -20,7 +20,7 @@ #ifndef VIEWMANAGER_H #define VIEWMANAGER_H -#include "UiDllMacro.h" +#include "DllMacro.h" #include "viewpages/ViewStep.h" #include diff --git a/src/libcalamaresui/modulesystem/CppJobModule.h b/src/libcalamaresui/modulesystem/CppJobModule.h index feb0f22bb..d97443a8a 100644 --- a/src/libcalamaresui/modulesystem/CppJobModule.h +++ b/src/libcalamaresui/modulesystem/CppJobModule.h @@ -22,7 +22,7 @@ #define CALAMARES_CPPJOBMODULE_H #include "Module.h" -#include "UiDllMacro.h" +#include "DllMacro.h" class QPluginLoader; diff --git a/src/libcalamaresui/modulesystem/Module.h b/src/libcalamaresui/modulesystem/Module.h index bf2f1cb5d..0891f8a25 100644 --- a/src/libcalamaresui/modulesystem/Module.h +++ b/src/libcalamaresui/modulesystem/Module.h @@ -22,7 +22,7 @@ #include "Job.h" #include "Requirement.h" -#include "UiDllMacro.h" +#include "DllMacro.h" #include "modulesystem/Descriptor.h" #include "modulesystem/InstanceKey.h" diff --git a/src/libcalamaresui/modulesystem/ProcessJobModule.h b/src/libcalamaresui/modulesystem/ProcessJobModule.h index 96fb2ed47..da2badbd0 100644 --- a/src/libcalamaresui/modulesystem/ProcessJobModule.h +++ b/src/libcalamaresui/modulesystem/ProcessJobModule.h @@ -22,7 +22,7 @@ #include "Module.h" -#include "UiDllMacro.h" +#include "DllMacro.h" #include diff --git a/src/libcalamaresui/modulesystem/PythonJobModule.h b/src/libcalamaresui/modulesystem/PythonJobModule.h index 8fa137f71..295ab5942 100644 --- a/src/libcalamaresui/modulesystem/PythonJobModule.h +++ b/src/libcalamaresui/modulesystem/PythonJobModule.h @@ -21,7 +21,7 @@ #include "Module.h" -#include "UiDllMacro.h" +#include "DllMacro.h" namespace Calamares { diff --git a/src/libcalamaresui/modulesystem/PythonQtViewModule.h b/src/libcalamaresui/modulesystem/PythonQtViewModule.h index 6ebb5c433..33b8d041b 100644 --- a/src/libcalamaresui/modulesystem/PythonQtViewModule.h +++ b/src/libcalamaresui/modulesystem/PythonQtViewModule.h @@ -20,7 +20,7 @@ #define CALAMARES_PYTHONQTVIEWMODULE_H #include "Module.h" -#include "UiDllMacro.h" +#include "DllMacro.h" namespace Calamares { diff --git a/src/libcalamaresui/modulesystem/ViewModule.h b/src/libcalamaresui/modulesystem/ViewModule.h index e9db1347b..c1ee8ff69 100644 --- a/src/libcalamaresui/modulesystem/ViewModule.h +++ b/src/libcalamaresui/modulesystem/ViewModule.h @@ -21,7 +21,7 @@ #define CALAMARES_VIEWMODULE_H #include "Module.h" -#include "UiDllMacro.h" +#include "DllMacro.h" class QPluginLoader; diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.h b/src/libcalamaresui/utils/CalamaresUtilsGui.h index 0c10dcc30..961ed5bc7 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -20,7 +20,7 @@ #ifndef CALAMARESUTILSGUI_H #define CALAMARESUTILSGUI_H -#include "UiDllMacro.h" +#include "DllMacro.h" #include #include diff --git a/src/libcalamaresui/utils/ImageRegistry.h b/src/libcalamaresui/utils/ImageRegistry.h index 454cb500d..f73ee36e6 100644 --- a/src/libcalamaresui/utils/ImageRegistry.h +++ b/src/libcalamaresui/utils/ImageRegistry.h @@ -28,7 +28,7 @@ #include -#include "UiDllMacro.h" +#include "DllMacro.h" #include "utils/CalamaresUtilsGui.h" class UIDLLEXPORT ImageRegistry diff --git a/src/libcalamaresui/utils/Qml.h b/src/libcalamaresui/utils/Qml.h index 70f59e7ec..7371bbc3a 100644 --- a/src/libcalamaresui/utils/Qml.h +++ b/src/libcalamaresui/utils/Qml.h @@ -34,7 +34,7 @@ namespace CalamaresUtils * * If there is a return value from the QML method, it is logged (but not otherwise used). */ -DLLEXPORT void +UIDLLEXPORT void callQMLFunction( QQuickItem* qmlObject, const char* method ); } // namespace CalamaresUtils diff --git a/src/libcalamaresui/viewpages/ViewStep.h b/src/libcalamaresui/viewpages/ViewStep.h index c5903d6f5..bdc235476 100644 --- a/src/libcalamaresui/viewpages/ViewStep.h +++ b/src/libcalamaresui/viewpages/ViewStep.h @@ -21,7 +21,7 @@ #define VIEWSTEP_H #include "Job.h" -#include "UiDllMacro.h" +#include "DllMacro.h" #include "modulesystem/InstanceKey.h" #include "modulesystem/Requirement.h" diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 9e9621106..b72b755d3 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -12,7 +12,7 @@ include_directories( if( BUILD_TESTING ) add_executable( test_conf test_conf.cpp ) - target_link_libraries( test_conf ${YAMLCPP_LIBRARY} Qt5::Core ) + target_link_libraries( test_conf yamlcpp Qt5::Core ) target_include_directories( test_conf PUBLIC ${YAMLCPP_INCLUDE_DIR} ) endif() diff --git a/src/modules/contextualprocess/CMakeLists.txt b/src/modules/contextualprocess/CMakeLists.txt index a7e9ed05b..2df4cfe37 100644 --- a/src/modules/contextualprocess/CMakeLists.txt +++ b/src/modules/contextualprocess/CMakeLists.txt @@ -8,18 +8,11 @@ calamares_add_plugin( contextualprocess SHARED_LIB ) -if( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( - Tests.cpp - ContextualProcessJob.cpp # Builds it a second time - TEST_NAME - contextualprocesstest - LINK_LIBRARIES - ${CALAMARES_LIBRARIES} - calamaresui - ${YAMLCPP_LIBRARY} - Qt5::Core - Qt5::Test - ) - calamares_automoc( contextualprocesstest ) -endif() +calamares_add_test( + contextualprocesstest + SOURCES + Tests.cpp + ContextualProcessJob.cpp # Builds it a second time + LIBRARIES + yamlcpp +) diff --git a/src/modules/contextualprocess/ContextualProcessJob.h b/src/modules/contextualprocess/ContextualProcessJob.h index 2efbc5082..3a252d2d3 100644 --- a/src/modules/contextualprocess/ContextualProcessJob.h +++ b/src/modules/contextualprocess/ContextualProcessJob.h @@ -23,7 +23,7 @@ #include #include "CppJob.h" -#include "PluginDllMacro.h" +#include "DllMacro.h" #include "utils/PluginFactory.h" diff --git a/src/modules/dracutlukscfg/DracutLuksCfgJob.h b/src/modules/dracutlukscfg/DracutLuksCfgJob.h index e9e5a54a2..ccf0adb70 100644 --- a/src/modules/dracutlukscfg/DracutLuksCfgJob.h +++ b/src/modules/dracutlukscfg/DracutLuksCfgJob.h @@ -27,7 +27,7 @@ #include -#include +#include class PLUGINDLLEXPORT DracutLuksCfgJob : public Calamares::CppJob { diff --git a/src/modules/dummycpp/DummyCppJob.h b/src/modules/dummycpp/DummyCppJob.h index 4a79d0378..c60b01d57 100644 --- a/src/modules/dummycpp/DummyCppJob.h +++ b/src/modules/dummycpp/DummyCppJob.h @@ -27,7 +27,7 @@ #include -#include +#include class PLUGINDLLEXPORT DummyCppJob : public Calamares::CppJob { diff --git a/src/modules/finished/FinishedViewStep.h b/src/modules/finished/FinishedViewStep.h index 7b3881099..2df37e9b6 100644 --- a/src/modules/finished/FinishedViewStep.h +++ b/src/modules/finished/FinishedViewStep.h @@ -25,7 +25,7 @@ #include "utils/PluginFactory.h" #include "viewpages/ViewStep.h" -#include "PluginDllMacro.h" +#include "DllMacro.h" class FinishedPage; diff --git a/src/modules/fsresizer/CMakeLists.txt b/src/modules/fsresizer/CMakeLists.txt index 3d82489b7..01f673eb8 100644 --- a/src/modules/fsresizer/CMakeLists.txt +++ b/src/modules/fsresizer/CMakeLists.txt @@ -30,21 +30,15 @@ if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND SHARED_LIB ) - if( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( - Tests.cpp - TEST_NAME - fsresizertest - LINK_LIBRARIES - ${CALAMARES_LIBRARIES} - calamares - calamares_job_fsresizer # From above - ${YAMLCPP_LIBRARY} - Qt5::Core - Qt5::Test - ) - set_target_properties( fsresizertest PROPERTIES AUTOMOC TRUE ) - target_include_directories( fsresizertest PRIVATE /usr/local/include ) + calamares_add_test( + fsresizertest + SOURCES + Tests.cpp + LIBRARIES + calamares_job_fsresizer # From above + yamlcpp + ) + if( TARGET fsresizertest ) target_compile_definitions( fsresizertest PRIVATE ${_partition_defs} ) endif() else() diff --git a/src/modules/fsresizer/ResizeFSJob.h b/src/modules/fsresizer/ResizeFSJob.h index 76ca6c219..985942b99 100644 --- a/src/modules/fsresizer/ResizeFSJob.h +++ b/src/modules/fsresizer/ResizeFSJob.h @@ -27,7 +27,7 @@ #include "partition/PartitionSize.h" #include "utils/PluginFactory.h" -#include +#include class CoreBackend; // From KPMCore class Device; // From KPMCore diff --git a/src/modules/hostinfo/CMakeLists.txt b/src/modules/hostinfo/CMakeLists.txt index caf888625..3d6e0973f 100644 --- a/src/modules/hostinfo/CMakeLists.txt +++ b/src/modules/hostinfo/CMakeLists.txt @@ -32,18 +32,11 @@ if ( KF5CoreAddons_FOUND AND KF5CoreAddons_VERSION VERSION_GREATER_EQUAL 5.58 ) target_compile_definitions( calamares_job_hostinfo PRIVATE WITH_KOSRelease ) endif() -if( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( - Tests.cpp - HostInfoJob.cpp # Builds it a second time - TEST_NAME - hostinfotest - LINK_LIBRARIES - ${CALAMARES_LIBRARIES} - calamaresui - ${YAMLCPP_LIBRARY} - Qt5::Core - Qt5::Test - ) - calamares_automoc( hostinfotest ) -endif() +calamares_add_test( + hostinfotest + SOURCES + Tests.cpp + HostInfoJob.cpp + LIBRARIES + yamlcpp +) diff --git a/src/modules/hostinfo/HostInfoJob.h b/src/modules/hostinfo/HostInfoJob.h index fa3342192..5db169b0e 100644 --- a/src/modules/hostinfo/HostInfoJob.h +++ b/src/modules/hostinfo/HostInfoJob.h @@ -20,7 +20,7 @@ #define HOSTINFOJOB_H #include "CppJob.h" -#include "PluginDllMacro.h" +#include "DllMacro.h" #include "utils/PluginFactory.h" #include diff --git a/src/modules/initcpio/CMakeLists.txt b/src/modules/initcpio/CMakeLists.txt index af217fb1a..5140c97e0 100644 --- a/src/modules/initcpio/CMakeLists.txt +++ b/src/modules/initcpio/CMakeLists.txt @@ -8,18 +8,11 @@ calamares_add_plugin( initcpio SHARED_LIB ) -if( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( - Tests.cpp - TEST_NAME - initcpiotest - LINK_LIBRARIES - ${CALAMARES_LIBRARIES} - calamares - calamares_job_initcpio # From above - ${YAMLCPP_LIBRARY} - Qt5::Core - Qt5::Test - ) - calamares_automoc( initcpiotest ) -endif() +calamares_add_test( + initcpiotest + SOURCES + Tests.cpp + LIBRARIES + calamares_job_initcpio # From above + yamlcpp +) diff --git a/src/modules/initcpio/InitcpioJob.h b/src/modules/initcpio/InitcpioJob.h index 11358d749..cdc48f6ce 100644 --- a/src/modules/initcpio/InitcpioJob.h +++ b/src/modules/initcpio/InitcpioJob.h @@ -20,7 +20,7 @@ #define INITCPIOJOB_H #include "CppJob.h" -#include "PluginDllMacro.h" +#include "DllMacro.h" #include "utils/PluginFactory.h" #include diff --git a/src/modules/initramfs/CMakeLists.txt b/src/modules/initramfs/CMakeLists.txt index d7da12d55..b3287c896 100644 --- a/src/modules/initramfs/CMakeLists.txt +++ b/src/modules/initramfs/CMakeLists.txt @@ -8,18 +8,11 @@ calamares_add_plugin( initramfs SHARED_LIB ) -if( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( - Tests.cpp - TEST_NAME - initramfstest - LINK_LIBRARIES - ${CALAMARES_LIBRARIES} - calamares - calamares_job_initramfs # From above - ${YAMLCPP_LIBRARY} - Qt5::Core - Qt5::Test - ) - calamares_automoc( initramfstest ) -endif() +calamares_add_test( + initramfstest + SOURCES + Tests.cpp + LIBRARIES + calamares_job_initramfs # From above + yamlcpp +) diff --git a/src/modules/initramfs/InitramfsJob.cpp b/src/modules/initramfs/InitramfsJob.cpp index af8e07ca7..468047c45 100644 --- a/src/modules/initramfs/InitramfsJob.cpp +++ b/src/modules/initramfs/InitramfsJob.cpp @@ -54,7 +54,7 @@ InitramfsJob::exec() // First make sure we generate a safe initramfs with suitable permissions. static const char confFile[] = "/etc/initramfs-tools/conf.d/calamares-safe-initramfs.conf"; static const char contents[] = "UMASK=0077\n"; - if ( CalamaresUtils::System::instance()->createTargetFile( confFile, QByteArray( contents ) ).isEmpty() ) + if ( CalamaresUtils::System::instance()->createTargetFile( confFile, QByteArray( contents ) ).failed() ) { cWarning() << Logger::SubEntry << "Could not configure safe UMASK for initramfs."; // But continue anyway. diff --git a/src/modules/initramfs/InitramfsJob.h b/src/modules/initramfs/InitramfsJob.h index 9eeb81fea..3239c6929 100644 --- a/src/modules/initramfs/InitramfsJob.h +++ b/src/modules/initramfs/InitramfsJob.h @@ -20,7 +20,7 @@ #define INITRAMFSJOB_H #include "CppJob.h" -#include "PluginDllMacro.h" +#include "DllMacro.h" #include "utils/PluginFactory.h" #include diff --git a/src/modules/initramfs/Tests.cpp b/src/modules/initramfs/Tests.cpp index 936c94097..39d2abeaa 100644 --- a/src/modules/initramfs/Tests.cpp +++ b/src/modules/initramfs/Tests.cpp @@ -57,9 +57,12 @@ void InitramfsTests::cleanup() void InitramfsTests::testCreateHostFile() { - + CalamaresUtils::System s( false ); // don't chroot - QString path = s.createTargetFile( confFile, QByteArray( contents ) ); + auto r = s.createTargetFile( confFile, QByteArray( contents ) ); + QVERIFY( !r.failed() ); + QVERIFY( r ); + QString path = r.path(); QVERIFY( !path.isEmpty() ); QCOMPARE( path, confFile ); // don't chroot, so path create relative to / QVERIFY( QFile::exists( confFile ) ); @@ -67,30 +70,33 @@ void InitramfsTests::testCreateHostFile() QFileInfo fi( confFile ); QVERIFY( fi.exists() ); QCOMPARE( fi.size(), sizeof( contents )-1 ); // don't count trailing NUL - + QFile::remove( confFile ); } void InitramfsTests::testCreateTargetFile() { static const char short_confFile[] = "/calamares-safe-umask"; - + CalamaresUtils::System s( true ); - QString path = s.createTargetFile( short_confFile, QByteArray( contents ) ); + auto r = s.createTargetFile( short_confFile, QByteArray( contents ) ); + QVERIFY( r.failed() ); + QVERIFY( !r ); + QString path = r.path(); QVERIFY( path.isEmpty() ); // because no rootmountpoint is set - + Calamares::JobQueue j; j.globalStorage()->insert( "rootMountPoint", "/tmp" ); - + path = s.createTargetFile( short_confFile, QByteArray( contents ) ); - QVERIFY( path.endsWith( short_confFile ) ); // chroot, so path create relative to + QVERIFY( path.endsWith( short_confFile ) ); // chroot, so path create relative to QVERIFY( path.startsWith( "/tmp/" ) ); QVERIFY( QFile::exists( path ) ); QFileInfo fi( path ); QVERIFY( fi.exists() ); QCOMPARE( fi.size(), sizeof( contents )-1 ); // don't count trailing NUL - + QFile::remove( path ); } diff --git a/src/modules/interactiveterminal/InteractiveTerminalViewStep.h b/src/modules/interactiveterminal/InteractiveTerminalViewStep.h index 55486691d..f0af35d3c 100644 --- a/src/modules/interactiveterminal/InteractiveTerminalViewStep.h +++ b/src/modules/interactiveterminal/InteractiveTerminalViewStep.h @@ -25,7 +25,7 @@ #include #include -#include +#include class InteractiveTerminalPage; diff --git a/src/modules/keyboard/KeyboardViewStep.h b/src/modules/keyboard/KeyboardViewStep.h index a5bdd579e..9f362e116 100644 --- a/src/modules/keyboard/KeyboardViewStep.h +++ b/src/modules/keyboard/KeyboardViewStep.h @@ -25,7 +25,7 @@ #include #include -#include +#include class KeyboardPage; diff --git a/src/modules/license/LicenseViewStep.h b/src/modules/license/LicenseViewStep.h index 957110f3d..cc1a92896 100644 --- a/src/modules/license/LicenseViewStep.h +++ b/src/modules/license/LicenseViewStep.h @@ -20,7 +20,7 @@ #ifndef LICENSEPAGEPLUGIN_H #define LICENSEPAGEPLUGIN_H -#include +#include #include #include diff --git a/src/modules/locale/CMakeLists.txt b/src/modules/locale/CMakeLists.txt index 768a67543..cae2ea41c 100644 --- a/src/modules/locale/CMakeLists.txt +++ b/src/modules/locale/CMakeLists.txt @@ -27,19 +27,13 @@ calamares_add_plugin( locale calamaresui Qt5::Network ${geoip_libs} - ${YAMLCPP_LIBRARY} + yamlcpp SHARED_LIB ) -if( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( - Tests.cpp - LocaleConfiguration.cpp - TEST_NAME - localetest - LINK_LIBRARIES - calamares - Qt5::Test - ) - calamares_automoc( localetest ) -endif() +calamares_add_test( + localetest + SOURCES + Tests.cpp + LocaleConfiguration.cpp +) diff --git a/src/modules/locale/LocaleViewStep.h b/src/modules/locale/LocaleViewStep.h index eb8d64177..841aba97f 100644 --- a/src/modules/locale/LocaleViewStep.h +++ b/src/modules/locale/LocaleViewStep.h @@ -25,7 +25,7 @@ #include "utils/PluginFactory.h" #include "viewpages/ViewStep.h" -#include "PluginDllMacro.h" +#include "DllMacro.h" #include #include diff --git a/src/modules/luksbootkeyfile/LuksBootKeyFileJob.cpp b/src/modules/luksbootkeyfile/LuksBootKeyFileJob.cpp index 9997cc185..90d64d5a6 100644 --- a/src/modules/luksbootkeyfile/LuksBootKeyFileJob.cpp +++ b/src/modules/luksbootkeyfile/LuksBootKeyFileJob.cpp @@ -205,7 +205,7 @@ LuksBootKeyFileJob::exec() if ( !setupLuks( d ) ) return Calamares::JobResult::error( tr( "Encrypted rootfs setup error" ), - tr( "Could configure LUKS key file on partition %1." ).arg( d.device ) ); + tr( "Could not configure LUKS key file on partition %1." ).arg( d.device ) ); } return Calamares::JobResult::ok(); diff --git a/src/modules/luksbootkeyfile/LuksBootKeyFileJob.h b/src/modules/luksbootkeyfile/LuksBootKeyFileJob.h index 2d4d6d319..de9b9c677 100644 --- a/src/modules/luksbootkeyfile/LuksBootKeyFileJob.h +++ b/src/modules/luksbootkeyfile/LuksBootKeyFileJob.h @@ -20,7 +20,7 @@ #define LUKSBOOTKEYFILEJOB_H #include "CppJob.h" -#include "PluginDllMacro.h" +#include "DllMacro.h" #include "utils/PluginFactory.h" #include diff --git a/src/modules/machineid/CMakeLists.txt b/src/modules/machineid/CMakeLists.txt index a57d5163d..4a916334c 100644 --- a/src/modules/machineid/CMakeLists.txt +++ b/src/modules/machineid/CMakeLists.txt @@ -9,17 +9,10 @@ calamares_add_plugin( machineid SHARED_LIB ) -if ( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( - Tests.cpp - MachineIdJob.cpp - Workers.cpp - TEST_NAME - machineidtest - LINK_LIBRARIES - calamares - Qt5::Core - Qt5::Test - ) - calamares_automoc( machineidtest ) -endif() +calamares_add_test( + machineidtest + SOURCES + Tests.cpp + MachineIdJob.cpp + Workers.cpp +) diff --git a/src/modules/machineid/MachineIdJob.h b/src/modules/machineid/MachineIdJob.h index 5d44b2017..3e450accb 100644 --- a/src/modules/machineid/MachineIdJob.h +++ b/src/modules/machineid/MachineIdJob.h @@ -26,7 +26,7 @@ #include -#include +#include class PLUGINDLLEXPORT MachineIdJob : public Calamares::CppJob { diff --git a/src/modules/machineid/Tests.cpp b/src/modules/machineid/Tests.cpp index 53abd0482..4600633b0 100644 --- a/src/modules/machineid/Tests.cpp +++ b/src/modules/machineid/Tests.cpp @@ -28,6 +28,9 @@ #include #include +// Internals of Workers.cpp +extern int getUrandomPoolSize(); + class MachineIdTests : public QObject { Q_OBJECT @@ -93,10 +96,10 @@ MachineIdTests::testPoolSize() { #ifdef Q_OS_FREEBSD // It hardly makes sense, but also the /proc entry is missing - QCOMPARE( MachineId::getUrandomPoolSize(), 512 ); + QCOMPARE( getUrandomPoolSize(), 512 ); #else // Based on a sample size of 1, Netrunner - QCOMPARE( MachineId::getUrandomPoolSize(), 4096 ); + QCOMPARE( getUrandomPoolSize(), 4096 ); #endif } @@ -122,8 +125,13 @@ MachineIdTests::testJob() gs->insert( "rootMountPoint", "/tmp" ); // Prepare part of the target filesystem - QVERIFY( system->createTargetDirs("/etc") ); - QVERIFY( !(system->createTargetFile( "/etc/machine-id", "Hello" ).isEmpty() ) ); + { + QVERIFY( system->createTargetDirs("/etc") ); + auto r = system->createTargetFile( "/etc/machine-id", "Hello" ); + QVERIFY( !r.failed() ); + QVERIFY( r ); + QVERIFY( !r.path().isEmpty() ); + } MachineIdJob job( nullptr ); QVERIFY( !job.prettyName().isEmpty() ); diff --git a/src/modules/machineid/Workers.cpp b/src/modules/machineid/Workers.cpp index 39acdfbf2..76e466435 100644 --- a/src/modules/machineid/Workers.cpp +++ b/src/modules/machineid/Workers.cpp @@ -27,6 +27,34 @@ #include +/// @brief Returns a recommended size for the entropy pool (in bytes) +STATICTEST int +getUrandomPoolSize() +{ + QFile f( "/proc/sys/kernel/random/poolsize" ); + constexpr const int minimumPoolSize = 512; + int poolSize = minimumPoolSize; + + if ( f.exists() && f.open( QIODevice::ReadOnly | QIODevice::Text ) ) + { + QByteArray v = f.read( 16 ); + if ( v.length() > 2 ) + { + if ( v.endsWith( '\n' ) ) + { + v.chop( 1 ); + } + bool ok = false; + poolSize = v.toInt( &ok ); + if ( !ok ) + { + poolSize = minimumPoolSize; + } + } + } + return ( poolSize >= minimumPoolSize ) ? poolSize : minimumPoolSize; +} + namespace MachineId { @@ -59,33 +87,6 @@ copyFile( const QString& rootMountPoint, const QString& fileName ) return Calamares::JobResult::ok(); } -int -getUrandomPoolSize() -{ - QFile f( "/proc/sys/kernel/random/poolsize" ); - constexpr const int minimumPoolSize = 512; - int poolSize = minimumPoolSize; - - if ( f.exists() && f.open( QIODevice::ReadOnly | QIODevice::Text ) ) - { - QByteArray v = f.read( 16 ); - if ( v.length() > 2 ) - { - if ( v.endsWith( '\n' ) ) - { - v.chop( 1 ); - } - bool ok = false; - poolSize = v.toInt( &ok ); - if ( !ok ) - { - poolSize = minimumPoolSize; - } - } - } - return ( poolSize >= minimumPoolSize ) ? poolSize : minimumPoolSize; -} - Calamares::JobResult createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fileName ) { diff --git a/src/modules/machineid/Workers.h b/src/modules/machineid/Workers.h index 31561af1b..8cb8d74ff 100644 --- a/src/modules/machineid/Workers.h +++ b/src/modules/machineid/Workers.h @@ -48,9 +48,6 @@ enum class EntropyGeneration CopyFromHost }; -/// @brief Returns a recommended size for the entropy pool (in bytes) -int getUrandomPoolSize(); - /// @brief Creates a new entropy file @p fileName in the target system at @p rootMountPoint Calamares::JobResult createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fileName ); diff --git a/src/modules/netinstall/CMakeLists.txt b/src/modules/netinstall/CMakeLists.txt index 67f805734..c5eddd32b 100644 --- a/src/modules/netinstall/CMakeLists.txt +++ b/src/modules/netinstall/CMakeLists.txt @@ -1,5 +1,3 @@ -include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ) - calamares_add_plugin( netinstall TYPE viewmodule EXPORT_MACRO PLUGINDLLEXPORT_PRO @@ -15,6 +13,6 @@ calamares_add_plugin( netinstall LINK_PRIVATE_LIBRARIES calamaresui Qt5::Network - ${YAMLCPP_LIBRARY} + yamlcpp SHARED_LIB ) diff --git a/src/modules/netinstall/NetInstallViewStep.cpp b/src/modules/netinstall/NetInstallViewStep.cpp index fcb76be5a..b0fe53083 100644 --- a/src/modules/netinstall/NetInstallViewStep.cpp +++ b/src/modules/netinstall/NetInstallViewStep.cpp @@ -20,15 +20,15 @@ #include "NetInstallViewStep.h" -#include "JobQueue.h" #include "GlobalStorage.h" +#include "JobQueue.h" #include "utils/Logger.h" #include "utils/Variant.h" #include "NetInstallPage.h" -CALAMARES_PLUGIN_FACTORY_DEFINITION( NetInstallViewStepFactory, registerPlugin(); ) +CALAMARES_PLUGIN_FACTORY_DEFINITION( NetInstallViewStepFactory, registerPlugin< NetInstallViewStep >(); ) NetInstallViewStep::NetInstallViewStep( QObject* parent ) : Calamares::ViewStep( parent ) @@ -36,15 +36,16 @@ NetInstallViewStep::NetInstallViewStep( QObject* parent ) , m_nextEnabled( false ) { emit nextStatusChanged( true ); - connect( m_widget, &NetInstallPage::checkReady, - this, &NetInstallViewStep::nextIsReady ); + connect( m_widget, &NetInstallPage::checkReady, this, &NetInstallViewStep::nextIsReady ); } NetInstallViewStep::~NetInstallViewStep() { if ( m_widget && m_widget->parent() == nullptr ) + { m_widget->deleteLater(); + } } @@ -110,58 +111,70 @@ NetInstallViewStep::onActivate() m_widget->onActivate(); } - void NetInstallViewStep::onLeave() { - cDebug() << "Leaving netinstall, adding packages to be installed" - << "to global storage"; - PackageModel::PackageItemDataList packages = m_widget->selectedPackages(); + cDebug() << "Netinstall: Processing" << packages.length() << "packages."; + + static const char PACKAGEOP[] = "packageOperations"; + + // Check if there's already a PACAKGEOP entry in GS, and if so we'll + // extend that one (overwriting the value in GS at the end of this method) + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + QVariantList packageOperations = gs->contains( PACKAGEOP ) ? gs->value( PACKAGEOP ).toList() : QVariantList(); + cDebug() << Logger::SubEntry << "Existing package operations length" << packageOperations.length(); + + // Clear out existing operations for this module, going backwards: + // Sometimes we remove an item, and we don't want the index to + // fall off the end of the list. + for ( int index = packageOperations.length() - 1; 0 <= index ; index-- ) + { + const QVariantMap op = packageOperations.at(index).toMap(); + if ( op.contains( "source" ) && op.value( "source" ).toString() == moduleInstanceKey().toString() ) + { + cDebug() << Logger::SubEntry << "Removing existing operations for" << moduleInstanceKey(); + packageOperations.removeAt( index ); + } + } + + // This netinstall module may add two sub-steps to the packageOperations, + // one for installing and one for try-installing. QVariantList installPackages; QVariantList tryInstallPackages; - QVariantList packageOperations; - cDebug() << "Processing" << packages.length() << "packages from netinstall."; - - for ( auto package : packages ) + for ( const auto& package : packages ) { - QVariant details( package.packageName ); - // If it's a package with a pre- or post-script, replace - // with the more complicated datastructure. - if ( !package.preScript.isEmpty() || !package.postScript.isEmpty() ) - { - QMap sdetails; - sdetails.insert( "pre-script", package.preScript ); - sdetails.insert( "package", package.packageName ); - sdetails.insert( "post-script", package.postScript ); - details = sdetails; - } if ( package.isCritical ) - installPackages.append( details ); + { + installPackages.append( package.toOperation() ); + } else - tryInstallPackages.append( details ); + { + tryInstallPackages.append( package.toOperation() ); + } } if ( !installPackages.empty() ) { - QMap op; + QVariantMap op; op.insert( "install", QVariant( installPackages ) ); + op.insert( "source", moduleInstanceKey().toString() ); packageOperations.append( op ); cDebug() << Logger::SubEntry << installPackages.length() << "critical packages."; } if ( !tryInstallPackages.empty() ) { - QMap op; + QVariantMap op; op.insert( "try_install", QVariant( tryInstallPackages ) ); + op.insert( "source", moduleInstanceKey().toString() ); packageOperations.append( op ); cDebug() << Logger::SubEntry << tryInstallPackages.length() << "non-critical packages."; } if ( !packageOperations.isEmpty() ) { - Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - gs->insert( "packageOperations", QVariant( packageOperations ) ); + gs->insert( PACKAGEOP, packageOperations ); } } diff --git a/src/modules/netinstall/NetInstallViewStep.h b/src/modules/netinstall/NetInstallViewStep.h index b07d3f96d..be92f5cc3 100644 --- a/src/modules/netinstall/NetInstallViewStep.h +++ b/src/modules/netinstall/NetInstallViewStep.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include @@ -70,4 +70,4 @@ private: CALAMARES_PLUGIN_FACTORY_DECLARATION( NetInstallViewStepFactory ) -#endif // NETINSTALLVIEWSTEP_H +#endif // NETINSTALLVIEWSTEP_H diff --git a/src/modules/netinstall/PackageModel.cpp b/src/modules/netinstall/PackageModel.cpp index 2fde7695e..b5b256ae0 100644 --- a/src/modules/netinstall/PackageModel.cpp +++ b/src/modules/netinstall/PackageModel.cpp @@ -21,9 +21,9 @@ #include "utils/Yaml.h" -PackageModel::PackageModel( const YAML::Node& data, QObject* parent ) : - QAbstractItemModel( parent ), - m_columnHeadings() +PackageModel::PackageModel( const YAML::Node& data, QObject* parent ) + : QAbstractItemModel( parent ) + , m_columnHeadings() { m_rootItem = new PackageTreeItem(); setupModelData( data, m_rootItem ); @@ -38,33 +38,47 @@ QModelIndex PackageModel::index( int row, int column, const QModelIndex& parent ) const { if ( !hasIndex( row, column, parent ) ) + { return QModelIndex(); + } PackageTreeItem* parentItem; if ( !parent.isValid() ) + { parentItem = m_rootItem; + } else - parentItem = static_cast( parent.internalPointer() ); + { + parentItem = static_cast< PackageTreeItem* >( parent.internalPointer() ); + } PackageTreeItem* childItem = parentItem->child( row ); if ( childItem ) + { return createIndex( row, column, childItem ); + } else + { return QModelIndex(); + } } QModelIndex PackageModel::parent( const QModelIndex& index ) const { if ( !index.isValid() ) + { return QModelIndex(); + } - PackageTreeItem* child = static_cast( index.internalPointer() ); + PackageTreeItem* child = static_cast< PackageTreeItem* >( index.internalPointer() ); PackageTreeItem* parent = child->parentItem(); if ( parent == m_rootItem ) + { return QModelIndex(); + } return createIndex( parent->row(), 0, parent ); } @@ -72,13 +86,19 @@ int PackageModel::rowCount( const QModelIndex& parent ) const { if ( parent.column() > 0 ) + { return 0; + } PackageTreeItem* parentItem; if ( !parent.isValid() ) + { parentItem = m_rootItem; + } else - parentItem = static_cast( parent.internalPointer() ); + { + parentItem = static_cast< PackageTreeItem* >( parent.internalPointer() ); + } return parentItem->childCount(); } @@ -87,7 +107,9 @@ int PackageModel::columnCount( const QModelIndex& parent ) const { if ( parent.isValid() ) - return static_cast( parent.internalPointer() )->columnCount(); + { + return static_cast< PackageTreeItem* >( parent.internalPointer() )->columnCount(); + } return m_rootItem->columnCount(); } @@ -95,17 +117,25 @@ QVariant PackageModel::data( const QModelIndex& index, int role ) const { if ( !index.isValid() ) + { return QVariant(); + } - PackageTreeItem* item = static_cast( index.internalPointer() ); + PackageTreeItem* item = static_cast< PackageTreeItem* >( index.internalPointer() ); if ( index.column() == 0 && role == Qt::CheckStateRole ) + { return item->isSelected(); + } - if ( item->isHidden() && role == Qt::DisplayRole ) // Hidden group + if ( item->isHidden() && role == Qt::DisplayRole ) // Hidden group + { return QVariant(); + } if ( role == Qt::DisplayRole ) + { return item->data( index.column() ); + } return QVariant(); } @@ -114,27 +144,31 @@ PackageModel::setData( const QModelIndex& index, const QVariant& value, int role { if ( role == Qt::CheckStateRole && index.isValid() ) { - PackageTreeItem* item = static_cast( index.internalPointer() ); - item->setSelected( static_cast( value.toInt() ) ); + PackageTreeItem* item = static_cast< PackageTreeItem* >( index.internalPointer() ); + item->setSelected( static_cast< Qt::CheckState >( value.toInt() ) ); - emit dataChanged( this->index( 0, 0 ), index.sibling( index.column(), index.row() + 1 ), - QVector( Qt::CheckStateRole ) ); + emit dataChanged( this->index( 0, 0 ), + index.sibling( index.column(), index.row() + 1 ), + QVector< int >( Qt::CheckStateRole ) ); } return true; } bool -PackageModel::setHeaderData( int section, Qt::Orientation orientation, - const QVariant& value, int role ) +PackageModel::setHeaderData( int section, Qt::Orientation orientation, const QVariant& value, int role ) { Q_UNUSED( role ) if ( orientation == Qt::Horizontal ) { if ( m_columnHeadings.value( section ) != QVariant() ) + { m_columnHeadings.replace( section, value ); + } else + { m_columnHeadings.insert( section, value ); + } emit headerDataChanged( orientation, section, section ); } return true; @@ -144,9 +178,13 @@ Qt::ItemFlags PackageModel::flags( const QModelIndex& index ) const { if ( !index.isValid() ) + { return Qt::ItemFlags(); + } if ( index.column() == 0 ) + { return Qt::ItemIsUserCheckable | QAbstractItemModel::flags( index ); + } return QAbstractItemModel::flags( index ); } @@ -154,46 +192,55 @@ QVariant PackageModel::headerData( int section, Qt::Orientation orientation, int role ) const { if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) + { return m_columnHeadings.value( section ); + } return QVariant(); } -QList +QList< PackageTreeItem::ItemData > PackageModel::getPackages() const { - QList items = getItemPackages( m_rootItem ); + QList< PackageTreeItem* > items = getItemPackages( m_rootItem ); for ( auto package : m_hiddenItems ) if ( package->hiddenSelected() ) + { items.append( getItemPackages( package ) ); - QList packages; + } + QList< PackageTreeItem::ItemData > packages; for ( auto item : items ) { PackageTreeItem::ItemData itemData; - itemData.preScript = item->parentItem()->preScript(); // Only groups have hooks - itemData.packageName = item->packageName(); // this seg faults - itemData.postScript = item->parentItem()->postScript(); // Only groups have hooks - itemData.isCritical = item->parentItem()->isCritical(); // Only groups are critical + itemData.preScript = item->parentItem()->preScript(); // Only groups have hooks + itemData.packageName = item->packageName(); // this seg faults + itemData.postScript = item->parentItem()->postScript(); // Only groups have hooks + itemData.isCritical = item->parentItem()->isCritical(); // Only groups are critical packages.append( itemData ); } return packages; } -QList +QList< PackageTreeItem* > PackageModel::getItemPackages( PackageTreeItem* item ) const { - QList selectedPackages; + QList< PackageTreeItem* > selectedPackages; for ( int i = 0; i < item->childCount(); i++ ) { if ( item->child( i )->isSelected() == Qt::Unchecked ) + { continue; + } - if ( !item->child( i )->childCount() ) // package + if ( !item->child( i )->childCount() ) // package + { selectedPackages.append( item->child( i ) ); + } else + { selectedPackages.append( getItemPackages( item->child( i ) ) ); + } } return selectedPackages; - } void @@ -203,49 +250,57 @@ PackageModel::setupModelData( const YAML::Node& data, PackageTreeItem* parent ) { const YAML::Node itemDefinition = *it; - QString name( - tr( CalamaresUtils::yamlToVariant( itemDefinition["name"] ).toByteArray() ) ); - QString description( - tr( CalamaresUtils::yamlToVariant( itemDefinition["description"] ).toByteArray() ) ); + QString name( tr( CalamaresUtils::yamlToVariant( itemDefinition[ "name" ] ).toByteArray() ) ); + QString description( tr( CalamaresUtils::yamlToVariant( itemDefinition[ "description" ] ).toByteArray() ) ); PackageTreeItem::ItemData itemData; itemData.name = name; itemData.description = description; - if ( itemDefinition["pre-install"] ) - itemData.preScript = - CalamaresUtils::yamlToVariant( itemDefinition["pre-install"] ).toString(); - if ( itemDefinition["post-install"] ) - itemData.postScript = - CalamaresUtils::yamlToVariant( itemDefinition["post-install"] ).toString(); + if ( itemDefinition[ "pre-install" ] ) + { + itemData.preScript = CalamaresUtils::yamlToVariant( itemDefinition[ "pre-install" ] ).toString(); + } + if ( itemDefinition[ "post-install" ] ) + { + itemData.postScript = CalamaresUtils::yamlToVariant( itemDefinition[ "post-install" ] ).toString(); + } PackageTreeItem* item = new PackageTreeItem( itemData, parent ); - if ( itemDefinition["selected"] ) - item->setSelected( - CalamaresUtils::yamlToVariant( itemDefinition["selected"] ).toBool() ? - Qt::Checked : Qt::Unchecked ); + if ( itemDefinition[ "selected" ] ) + item->setSelected( CalamaresUtils::yamlToVariant( itemDefinition[ "selected" ] ).toBool() ? Qt::Checked + : Qt::Unchecked ); else - item->setSelected( parent->isSelected() ); // Inherit from it's parent + { + item->setSelected( parent->isSelected() ); // Inherit from it's parent + } - if ( itemDefinition["hidden"] ) - item->setHidden( - CalamaresUtils::yamlToVariant( itemDefinition["hidden"] ).toBool() ); + if ( itemDefinition[ "hidden" ] ) + { + item->setHidden( CalamaresUtils::yamlToVariant( itemDefinition[ "hidden" ] ).toBool() ); + } - if ( itemDefinition["critical"] ) - item->setCritical( - CalamaresUtils::yamlToVariant( itemDefinition["critical"] ).toBool() ); + if ( itemDefinition[ "critical" ] ) + { + item->setCritical( CalamaresUtils::yamlToVariant( itemDefinition[ "critical" ] ).toBool() ); + } - if ( itemDefinition["packages"] ) - for ( YAML::const_iterator packageIt = itemDefinition["packages"].begin(); - packageIt != itemDefinition["packages"].end(); ++packageIt ) + if ( itemDefinition[ "packages" ] ) + for ( YAML::const_iterator packageIt = itemDefinition[ "packages" ].begin(); + packageIt != itemDefinition[ "packages" ].end(); + ++packageIt ) item->appendChild( new PackageTreeItem( CalamaresUtils::yamlToVariant( *packageIt ).toString(), item ) ); - if ( itemDefinition["subgroups"] ) - setupModelData( itemDefinition["subgroups"], item ); + if ( itemDefinition[ "subgroups" ] ) + { + setupModelData( itemDefinition[ "subgroups" ], item ); + } if ( item->isHidden() ) + { m_hiddenItems.append( item ); + } else { item->setCheckable( true ); diff --git a/src/modules/netinstall/PackageModel.h b/src/modules/netinstall/PackageModel.h index f84b2779d..cd8f676c8 100644 --- a/src/modules/netinstall/PackageModel.h +++ b/src/modules/netinstall/PackageModel.h @@ -29,7 +29,7 @@ namespace YAML { - class Node; +class Node; } class PackageModel : public QAbstractItemModel @@ -43,27 +43,24 @@ public: ~PackageModel() override; QVariant data( const QModelIndex& index, int role ) const override; - bool setData( const QModelIndex& index, const QVariant& value, - int role = Qt::EditRole ) override; - bool setHeaderData( int section, Qt::Orientation orientation, - const QVariant& value, int role = Qt::EditRole ) override; + bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole ) override; + bool + setHeaderData( int section, Qt::Orientation orientation, const QVariant& value, int role = Qt::EditRole ) override; Qt::ItemFlags flags( const QModelIndex& index ) const override; - QVariant headerData( int section, Qt::Orientation orientation, - int role = Qt::DisplayRole ) const override; - QModelIndex index( int row, int column, - const QModelIndex& parent = QModelIndex() ) const override; + QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override; + QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override; QModelIndex parent( const QModelIndex& index ) const override; int rowCount( const QModelIndex& parent = QModelIndex() ) const override; int columnCount( const QModelIndex& parent = QModelIndex() ) const override; PackageItemDataList getPackages() const; - QList getItemPackages( PackageTreeItem* item ) const; + QList< PackageTreeItem* > getItemPackages( PackageTreeItem* item ) const; private: void setupModelData( const YAML::Node& data, PackageTreeItem* parent ); PackageTreeItem* m_rootItem; - QList m_hiddenItems; + QList< PackageTreeItem* > m_hiddenItems; QVariantList m_columnHeadings; }; -#endif // PACKAGEMODEL_H +#endif // PACKAGEMODEL_H diff --git a/src/modules/netinstall/PackageTreeItem.cpp b/src/modules/netinstall/PackageTreeItem.cpp index b3dc6fae7..bbd85975e 100644 --- a/src/modules/netinstall/PackageTreeItem.cpp +++ b/src/modules/netinstall/PackageTreeItem.cpp @@ -21,28 +21,52 @@ #include "utils/Logger.h" +QVariant +PackageTreeItem::ItemData::toOperation() const +{ + // If it's a package with a pre- or post-script, replace + // with the more complicated datastructure. + if ( !preScript.isEmpty() || !postScript.isEmpty() ) + { + QMap< QString, QVariant > sdetails; + sdetails.insert( "pre-script", preScript ); + sdetails.insert( "package", packageName ); + sdetails.insert( "post-script", postScript ); + return sdetails; + } + else + { + return packageName; + } +} + PackageTreeItem::PackageTreeItem( const ItemData& data, PackageTreeItem* parent ) : m_parentItem( parent ) , m_data( data ) -{ } +{ +} -PackageTreeItem::PackageTreeItem( const QString packageName, PackageTreeItem* parent ) : - m_parentItem( parent ) +PackageTreeItem::PackageTreeItem( const QString packageName, PackageTreeItem* parent ) + : m_parentItem( parent ) { m_data.packageName = packageName; if ( parent != nullptr ) + { m_data.selected = parent->isSelected(); + } else + { m_data.selected = Qt::Unchecked; + } } -PackageTreeItem::PackageTreeItem( PackageTreeItem* parent ) : - m_parentItem( parent ) +PackageTreeItem::PackageTreeItem( PackageTreeItem* parent ) + : m_parentItem( parent ) { } -PackageTreeItem::PackageTreeItem::PackageTreeItem() : - PackageTreeItem( QString(), nullptr ) +PackageTreeItem::PackageTreeItem::PackageTreeItem() + : PackageTreeItem( QString(), nullptr ) { m_data.selected = Qt::Checked; m_data.name = QLatin1String( "" ); @@ -75,7 +99,9 @@ int PackageTreeItem::row() const { if ( m_parentItem ) - return m_parentItem->m_childItems.indexOf( const_cast( this ) ); + { + return m_parentItem->m_childItems.indexOf( const_cast< PackageTreeItem* >( this ) ); + } return 0; } @@ -88,13 +114,15 @@ PackageTreeItem::columnCount() const QVariant PackageTreeItem::data( int column ) const { - if ( packageName() != nullptr ) // package + if ( packageName() != nullptr ) // package { if ( !column ) + { return QVariant( packageName() ); + } return QVariant(); } - switch ( column ) // group + switch ( column ) // group { case 0: return QVariant( prettyName() ); @@ -164,14 +192,18 @@ bool PackageTreeItem::hiddenSelected() const { Q_ASSERT( m_data.isHidden ); - if (! m_data.selected ) + if ( !m_data.selected ) + { return false; + } const PackageTreeItem* currentItem = parentItem(); while ( currentItem != nullptr ) { if ( !currentItem->isHidden() ) + { return currentItem->isSelected() != Qt::Unchecked; + } currentItem = currentItem->parentItem(); } @@ -202,8 +234,10 @@ void PackageTreeItem::setSelected( Qt::CheckState isSelected ) { if ( parentItem() == nullptr ) - // This is the root, it is always checked so don't change state + // This is the root, it is always checked so don't change state + { return; + } m_data.selected = isSelected; setChildrenSelected( isSelected ); @@ -216,8 +250,10 @@ PackageTreeItem::setSelected( Qt::CheckState isSelected ) currentItem = currentItem->parentItem(); } if ( currentItem == nullptr ) - // Reached the root .. don't bother + // Reached the root .. don't bother + { return; + } // Figure out checked-state based on the children int childrenSelected = 0; @@ -225,16 +261,26 @@ PackageTreeItem::setSelected( Qt::CheckState isSelected ) for ( int i = 0; i < currentItem->childCount(); i++ ) { if ( currentItem->child( i )->isSelected() == Qt::Checked ) + { childrenSelected++; + } if ( currentItem->child( i )->isSelected() == Qt::PartiallyChecked ) + { childrenPartiallySelected++; + } } - if ( !childrenSelected && !childrenPartiallySelected) + if ( !childrenSelected && !childrenPartiallySelected ) + { currentItem->setSelected( Qt::Unchecked ); + } else if ( childrenSelected == currentItem->childCount() ) + { currentItem->setSelected( Qt::Checked ); + } else + { currentItem->setSelected( Qt::PartiallyChecked ); + } } void diff --git a/src/modules/netinstall/PackageTreeItem.h b/src/modules/netinstall/PackageTreeItem.h index 9c1c8c5a5..c2672b4d4 100644 --- a/src/modules/netinstall/PackageTreeItem.h +++ b/src/modules/netinstall/PackageTreeItem.h @@ -21,8 +21,8 @@ #define PACKAGETREEITEM_H #include -#include #include +#include class PackageTreeItem : public QStandardItem { @@ -37,6 +37,13 @@ public: bool isCritical = false; bool isHidden = false; Qt::CheckState selected = Qt::Unchecked; + + /** @brief Turns this item into a variant for PackageOperations use + * + * For "plain" items, this is just the package name; items with + * scripts return a map. See the package module for how it's interpreted. + */ + QVariant toOperation() const; }; explicit PackageTreeItem( const ItemData& data, PackageTreeItem* parent = nullptr ); explicit PackageTreeItem( const QString packageName, PackageTreeItem* parent = nullptr ); @@ -78,11 +85,12 @@ public: void setSelected( Qt::CheckState isSelected ); void setChildrenSelected( Qt::CheckState isSelected ); int type() const override; + private: PackageTreeItem* m_parentItem; - QList m_childItems; + QList< PackageTreeItem* > m_childItems; ItemData m_data; - const int m_columns = 2; // Name, description + const int m_columns = 2; // Name, description }; -#endif // PACKAGETREEITEM_H +#endif // PACKAGETREEITEM_H diff --git a/src/modules/notesqml/NotesQmlViewStep.h b/src/modules/notesqml/NotesQmlViewStep.h index 445b34c81..5ffd4598e 100644 --- a/src/modules/notesqml/NotesQmlViewStep.h +++ b/src/modules/notesqml/NotesQmlViewStep.h @@ -20,7 +20,7 @@ #ifndef NOTESQMLVIEWSTEP_H #define NOTESQMLVIEWSTEP_H -#include "PluginDllMacro.h" +#include "DllMacro.h" #include "locale/TranslatableConfiguration.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/Variant.h" diff --git a/src/modules/oemid/OEMViewStep.h b/src/modules/oemid/OEMViewStep.h index d8722594a..57e2bba66 100644 --- a/src/modules/oemid/OEMViewStep.h +++ b/src/modules/oemid/OEMViewStep.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include diff --git a/src/modules/packagechooser/CMakeLists.txt b/src/modules/packagechooser/CMakeLists.txt index eeae655c9..d85eda8e2 100644 --- a/src/modules/packagechooser/CMakeLists.txt +++ b/src/modules/packagechooser/CMakeLists.txt @@ -53,18 +53,12 @@ calamares_add_plugin( packagechooser SHARED_LIB ) -if( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( - Tests.cpp - TEST_NAME - packagechoosertest - LINK_LIBRARIES - ${CALAMARES_LIBRARIES} - calamares_viewmodule_packagechooser - Qt5::Core - Qt5::Test - Qt5::Gui - ${_extra_libraries} - ) - calamares_automoc( packagechoosertest) -endif() +calamares_add_test( + packagechoosertest + GUI + SOURCES + Tests.cpp + LIBRARIES + calamares_viewmodule_packagechooser + ${_extra_libraries} +) diff --git a/src/modules/packagechooser/PackageChooserViewStep.h b/src/modules/packagechooser/PackageChooserViewStep.h index 29e65ef82..9e9087971 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.h +++ b/src/modules/packagechooser/PackageChooserViewStep.h @@ -19,7 +19,7 @@ #ifndef PACKAGECHOOSERVIEWSTEP_H #define PACKAGECHOOSERVIEWSTEP_H -#include "PluginDllMacro.h" +#include "DllMacro.h" #include "locale/TranslatableConfiguration.h" #include "utils/PluginFactory.h" #include "viewpages/ViewStep.h" diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index aa4bb8b12..685cea0e5 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -478,7 +478,10 @@ def run_operations(pkgman, entry): else: for package in package_list: pkgman.install_package(package, from_local=True) - + elif key == "source": + libcalamares.utils.debug("Package-list from {!s}".format(entry[key])) + else: + libcalamares.utils.warning("Unknown package-operation key {!s}".format(key)) completed_packages += len(package_list) libcalamares.job.setprogress(completed_packages * 1.0 / total_packages) libcalamares.utils.debug(pretty_name()) diff --git a/src/modules/packages/packages.conf b/src/modules/packages/packages.conf index e42e8e9b8..7b631d79e 100644 --- a/src/modules/packages/packages.conf +++ b/src/modules/packages/packages.conf @@ -55,22 +55,25 @@ update_system: false # that is in this configuration file). # # Allowed package operations are: -# - install, try_install: will call the package manager to +# - *install*, *try_install*: will call the package manager to # install one or more packages. The install target will # abort the whole installation if package-installation # fails, while try_install carries on. Packages may be # listed as (localized) names, or as (localized) package-data. # See below for the description of the format. -# - localInstall: this is used to call the package manager +# - *localInstall*: this is used to call the package manager # to install a package from a path-to-a-package. This is # useful if you have a static package archive on the install media. # The *pacman* package manager is the only one to specially support # this operation (all others treat this the same as *install*). -# - remove, try_remove: will call the package manager to +# - *remove*, *try_remove*: will call the package manager to # remove one or more packages. The remove target will # abort the whole installation if package-removal fails, # while try_remove carries on. Packages may be listed as # (localized) names. +# One additional key is recognized, to help netinstall out: +# - *source*: ignored, does get logged +# Any other key is ignored, and logged as a warning. # # There are two formats for naming packages: as a name or as package-data, # which is an object notation providing package-name, as well as pre- and diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 1bb7f64fd..4b16d807a 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -648,7 +648,7 @@ PartitionViewStep::checkRequirements() { QLatin1String( "partitions" ), []{ return tr( "has at least one disk device available." ); }, - []{ return tr( "There are no partitons to install on." ); }, + []{ return tr( "There are no partitions to install on." ); }, m_core->deviceModel()->rowCount() > 0, // satisfied #ifdef DEBUG_PARTITION_UNSAFE false // optional diff --git a/src/modules/partition/gui/PartitionViewStep.h b/src/modules/partition/gui/PartitionViewStep.h index 0a62b3aa3..f60dff1df 100644 --- a/src/modules/partition/gui/PartitionViewStep.h +++ b/src/modules/partition/gui/PartitionViewStep.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include "core/PartitionActions.h" diff --git a/src/modules/partition/tests/CMakeLists.txt b/src/modules/partition/tests/CMakeLists.txt index ac3968df9..fdba7e688 100644 --- a/src/modules/partition/tests/CMakeLists.txt +++ b/src/modules/partition/tests/CMakeLists.txt @@ -21,16 +21,12 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) -if( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( ${partitionjobtests_SRCS} - TEST_NAME partitionjobtests - LINK_LIBRARIES - ${CALAMARES_LIBRARIES} - kpmcore - Qt5::Core - Qt5::Test - ) - - set_target_properties( partitionjobtests PROPERTIES AUTOMOC TRUE ) +calamares_add_test( + partitionjobtests + SOURCES ${partitionjobtests_SRCS} + LIBRARIES + kpmcore +) +if( TARGET partitionjobtests ) target_compile_definitions( partitionjobtests PRIVATE ${_partition_defs} ) endif() diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.h b/src/modules/plasmalnf/PlasmaLnfViewStep.h index 01db17821..e99418549 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.h +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include diff --git a/src/modules/preservefiles/PreserveFiles.h b/src/modules/preservefiles/PreserveFiles.h index ed2fe889c..587ac9bab 100644 --- a/src/modules/preservefiles/PreserveFiles.h +++ b/src/modules/preservefiles/PreserveFiles.h @@ -24,7 +24,7 @@ #include #include "CppJob.h" -#include "PluginDllMacro.h" +#include "DllMacro.h" #include "utils/PluginFactory.h" diff --git a/src/modules/shellprocess/CMakeLists.txt b/src/modules/shellprocess/CMakeLists.txt index 166dff17d..ec1cf0bcf 100644 --- a/src/modules/shellprocess/CMakeLists.txt +++ b/src/modules/shellprocess/CMakeLists.txt @@ -8,17 +8,10 @@ calamares_add_plugin( shellprocess SHARED_LIB ) -if( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( - Tests.cpp - TEST_NAME - shellprocesstest - LINK_LIBRARIES - ${CALAMARES_LIBRARIES} - calamaresui - ${YAMLCPP_LIBRARY} - Qt5::Core - Qt5::Test - ) - calamares_automoc( shellprocesstest ) -endif() +calamares_add_test( + shellprocesstest + SOURCES + Tests.cpp + LIBRARIES + yamlcpp +) diff --git a/src/modules/shellprocess/ShellProcessJob.h b/src/modules/shellprocess/ShellProcessJob.h index d532aac99..708a43087 100644 --- a/src/modules/shellprocess/ShellProcessJob.h +++ b/src/modules/shellprocess/ShellProcessJob.h @@ -20,7 +20,7 @@ #define SHELLPROCESSJOB_H #include "CppJob.h" -#include "PluginDllMacro.h" +#include "DllMacro.h" #include "utils/CommandList.h" #include "utils/PluginFactory.h" diff --git a/src/modules/summary/SummaryViewStep.h b/src/modules/summary/SummaryViewStep.h index 88f177a4d..2c873e168 100644 --- a/src/modules/summary/SummaryViewStep.h +++ b/src/modules/summary/SummaryViewStep.h @@ -24,7 +24,7 @@ #include #include -#include +#include class SummaryPage; diff --git a/src/modules/tracking/TrackingViewStep.h b/src/modules/tracking/TrackingViewStep.h index dc952253a..df6497d68 100644 --- a/src/modules/tracking/TrackingViewStep.h +++ b/src/modules/tracking/TrackingViewStep.h @@ -21,7 +21,7 @@ #include "TrackingType.h" -#include +#include #include #include diff --git a/src/modules/users/CMakeLists.txt b/src/modules/users/CMakeLists.txt index d0e7b6d9d..1d969a93b 100644 --- a/src/modules/users/CMakeLists.txt +++ b/src/modules/users/CMakeLists.txt @@ -1,4 +1,4 @@ -find_package( Qt5 COMPONENTS Core REQUIRED ) +find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Core DBus Network ) find_package( Crypt REQUIRED ) # Add optional libraries here @@ -36,20 +36,24 @@ calamares_add_plugin( users calamaresui ${CRYPT_LIBRARIES} ${USER_EXTRA_LIB} + Qt5::DBus SHARED_LIB ) -if( ECM_FOUND AND BUILD_TESTING ) - ecm_add_test( - PasswordTests.cpp - SetPasswordJob.cpp - TEST_NAME - passwordtest - LINK_LIBRARIES - ${CALAMARES_LIBRARIES} - Qt5::Core - Qt5::Test - ${CRYPT_LIBRARIES} - ) - calamares_automoc( passwordtest ) -endif() +calamares_add_test( + userspasswordtest + SOURCES + PasswordTests.cpp + SetPasswordJob.cpp + LIBRARIES + ${CRYPT_LIBRARIES} +) + +calamares_add_test( + userstest + SOURCES + Tests.cpp + SetHostNameJob.cpp + LIBRARIES + Qt5::DBus +) diff --git a/src/modules/users/SetHostNameJob.cpp b/src/modules/users/SetHostNameJob.cpp index b03d7a200..db220d042 100644 --- a/src/modules/users/SetHostNameJob.cpp +++ b/src/modules/users/SetHostNameJob.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Rohan Garg * Copyright 2015, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018, 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 @@ -22,14 +22,19 @@ #include "GlobalStorage.h" #include "JobQueue.h" +#include "utils/CalamaresUtilsSystem.h" #include "utils/Logger.h" #include #include +#include +#include +#include -SetHostNameJob::SetHostNameJob( const QString& hostname ) +SetHostNameJob::SetHostNameJob( const QString& hostname, Actions a ) : Calamares::Job() , m_hostname( hostname ) + , m_actions( a ) { } @@ -53,6 +58,68 @@ SetHostNameJob::prettyStatusMessage() const return tr( "Setting hostname %1." ).arg( m_hostname ); } +STATICTEST bool +setFileHostname( const QString& hostname ) +{ + return !( CalamaresUtils::System::instance() + ->createTargetFile( QStringLiteral( "/etc/hostname" ), ( hostname + '\n' ).toUtf8() ) + .failed() ); +} + +STATICTEST bool +writeFileEtcHosts( const QString& hostname ) +{ + // The actual hostname gets substituted in at %1 + static const char etc_hosts[] = R"(# Host addresses +127.0.0.1 localhost +127.0.1.1 %1 +::1 localhost ip6-localhost ip6-loopback +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters +)"; + + return !( CalamaresUtils::System::instance() + ->createTargetFile( QStringLiteral( "/etc/hosts" ), QString( etc_hosts ).arg( hostname ).toUtf8() ) + .failed() ); +} + +STATICTEST bool +setSystemdHostname( const QString& hostname ) +{ + QDBusInterface hostnamed( "org.freedesktop.hostname1", + "/org/freedesktop/hostname1", + "org.freedesktop.hostname1", + QDBusConnection::systemBus() ); + if ( !hostnamed.isValid() ) + { + cWarning() << "Interface" << hostnamed.interface() << "is not valid."; + return false; + } + + bool success = true; + // Static, writes /etc/hostname + { + QDBusReply< void > r = hostnamed.call( "SetStaticHostname", hostname, false ); + if ( !r.isValid() ) + { + cWarning() << "Could not set hostname through org.freedesktop.hostname1.SetStaticHostname." << r.error(); + success = false; + } + } + // Dynamic, updates kernel + { + QDBusReply< void > r = hostnamed.call( "SetHostname", hostname, false ); + if ( !r.isValid() ) + { + cWarning() << "Could not set hostname through org.freedesktop.hostname1.SetHostname." << r.error(); + success = false; + } + } + + return success; +} + + Calamares::JobResult SetHostNameJob::exec() { @@ -71,43 +138,29 @@ SetHostNameJob::exec() return Calamares::JobResult::error( tr( "Internal Error" ) ); } - QFile hostfile( destDir + "/etc/hostname" ); - if ( !hostfile.open( QFile::WriteOnly ) ) + if ( m_actions & Action::EtcHostname ) { - cError() << "Can't write to hostname file"; - return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) ); + if ( !setFileHostname( m_hostname ) ) + { + cError() << "Can't write to hostname file"; + return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) ); + } } - QTextStream hostfileout( &hostfile ); - hostfileout << m_hostname << "\n"; - hostfile.close(); - - QFile hostsfile( destDir + "/etc/hosts" ); - if ( !hostsfile.open( QFile::WriteOnly ) ) + if ( m_actions & Action::WriteEtcHosts ) { - cError() << "Can't write to hosts file"; - return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) ); + if ( !writeFileEtcHosts( m_hostname ) ) + { + cError() << "Can't write to hosts file"; + return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) ); + } } - // We also need to write the appropriate entries for /etc/hosts - QTextStream hostsfileout( &hostsfile ); - // ipv4 support - hostsfileout << "127.0.0.1" - << "\t" - << "localhost" - << "\n"; - hostsfileout << "127.0.1.1" - << "\t" << m_hostname << "\n"; - // ipv6 support - hostsfileout << "::1" - << "\t" - << "localhost ip6-localhost ip6-loopback" - << "\n"; - hostsfileout << "ff02::1 ip6-allnodes" - << "\n" - << "ff02::2 ip6-allrouters" - << "\n"; - hostsfile.close(); + if ( m_actions & Action::SystemdHostname ) + { + // Does its own logging + setSystemdHostname( m_hostname ); + } return Calamares::JobResult::ok(); } diff --git a/src/modules/users/SetHostNameJob.h b/src/modules/users/SetHostNameJob.h index ca2481dd4..619e2ba59 100644 --- a/src/modules/users/SetHostNameJob.h +++ b/src/modules/users/SetHostNameJob.h @@ -2,6 +2,7 @@ * * Copyright 2014, Rohan Garg * Copyright 2015, Teo Mrnjavac + * 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 @@ -26,7 +27,17 @@ class SetHostNameJob : public Calamares::Job { Q_OBJECT public: - SetHostNameJob( const QString& hostname ); + enum Action + { + None = 0x0, + EtcHostname = 0x1, // Write to /etc/hostname directly + SystemdHostname = 0x2, // Set via hostnamed(1) + WriteEtcHosts = 0x4 // Write /etc/hosts (127.0.1.1 is this host) + }; + Q_DECLARE_FLAGS( Actions, Action ) + + + SetHostNameJob( const QString& hostname, Actions a ); QString prettyName() const override; QString prettyDescription() const override; QString prettyStatusMessage() const override; @@ -34,7 +45,9 @@ public: private: const QString m_hostname; + const Actions m_actions; }; +Q_DECLARE_OPERATORS_FOR_FLAGS( SetHostNameJob::Actions ) #endif // SETHOSTNAMEJOB_CPP_H diff --git a/src/modules/users/Tests.cpp b/src/modules/users/Tests.cpp new file mode 100644 index 000000000..196fd9d68 --- /dev/null +++ b/src/modules/users/Tests.cpp @@ -0,0 +1,145 @@ +/* === 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 . + */ + +#include "SetHostNameJob.h" + +// Implementation details +extern bool setFileHostname( const QString& ); +extern bool writeFileEtcHosts( const QString& ); +extern bool setSystemdHostname( const QString& ); + +#include "GlobalStorage.h" +#include "JobQueue.h" +#include "utils/CalamaresUtilsSystem.h" +#include "utils/Logger.h" +#include "utils/Yaml.h" + +#include +#include + +class UsersTests : public QObject +{ + Q_OBJECT +public: + UsersTests(); + virtual ~UsersTests() {} + +private Q_SLOTS: + void initTestCase(); + + void testEtcHostname(); + void testEtcHosts(); + void testHostnamed(); + + void cleanup(); + +private: + QTemporaryDir m_dir; +}; + +UsersTests::UsersTests() + : m_dir( QStringLiteral( "/tmp/calamares-usertest" ) ) +{ +} + +void +UsersTests::initTestCase() +{ + Logger::setupLogLevel( Logger::LOGDEBUG ); + cDebug() << "Users test started."; + cDebug() << "Test dir" << m_dir.path(); + + // Ensure we have a system object, expect it to be a "bogus" one + CalamaresUtils::System* system = CalamaresUtils::System::instance(); + QVERIFY( system ); + QVERIFY( system->doChroot() ); + + // Ensure we have a system-wide GlobalStorage with /tmp as root + if ( !Calamares::JobQueue::instance() ) + { + cDebug() << "Creating new JobQueue"; + (void)new Calamares::JobQueue(); + } + Calamares::GlobalStorage* gs + = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; + QVERIFY( gs ); + gs->insert( "rootMountPoint", m_dir.path() ); +} + +void +UsersTests::testEtcHostname() +{ + cDebug() << "Test dir" << m_dir.path(); + + QVERIFY( QFile::exists( m_dir.path() ) ); + QVERIFY( !QFile::exists( m_dir.filePath( "etc" ) ) ); + + // Doesn't create intermediate directories + QVERIFY( !setFileHostname( QStringLiteral( "tubophone.calamares.io" ) ) ); + + QVERIFY( CalamaresUtils::System::instance()->createTargetDirs( "/etc" ) ); + QVERIFY( QFile::exists( m_dir.filePath( "etc" ) ) ); + + // Does write the file + QVERIFY( setFileHostname( QStringLiteral( "tubophone.calamares.io" ) ) ); + QVERIFY( QFile::exists( m_dir.filePath( "etc/hostname" ) ) ); + + // 22 for the test string, above, and 1 for the newline + QCOMPARE( QFileInfo( m_dir.filePath( "etc/hostname" ) ).size(), 22 + 1 ); +} + +void +UsersTests::testEtcHosts() +{ + // Assume previous tests did their work + QVERIFY( QFile::exists( m_dir.path() ) ); + QVERIFY( QFile::exists( m_dir.filePath( "etc" ) ) ); + + QVERIFY( writeFileEtcHosts( QStringLiteral( "tubophone.calamares.io" ) ) ); + QVERIFY( QFile::exists( m_dir.filePath( "etc/hosts" ) ) ); + // The skeleton contains %1 which has the hostname substituted in, so we lose two, + // and the rest of the blabla is 150 (according to Python) + QCOMPARE( QFileInfo( m_dir.filePath( "etc/hosts" ) ).size(), 150 + 22 - 2 ); +} + +void +UsersTests::testHostnamed() +{ + // Since the service might not be running (e.g. non-systemd systems, + // FreeBSD, docker, ..) we're not going to fail a test here. + // There's also the permissions problem to think of. + QEXPECT_FAIL( "", "Hostname changes are access-controlled", Continue ); + QVERIFY( setSystemdHostname( "tubophone.calamares.io" ) ); +} + + +void +UsersTests::cleanup() +{ + if ( QTest::currentTestFailed() ) + { + m_dir.setAutoRemove( false ); + } +} + + +QTEST_GUILESS_MAIN( UsersTests ) + +#include "utils/moc-warnings.h" + +#include "Tests.moc" diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index a7c72ce69..21f472a40 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -3,6 +3,7 @@ * Copyright 2014-2017, Teo Mrnjavac * Copyright 2017-2018, Adriaan de Groot * Copyright 2019, Collabora Ltd + * Copyright 2020, Gabriel Craciunescu * * Portions from the Manjaro Installation Framework * by Roland Singer @@ -40,6 +41,7 @@ #include "utils/String.h" #include +#include #include #include #include @@ -97,14 +99,12 @@ UsersPage::UsersPage( QWidget* parent ) connect( ui->textBoxUserVerifiedPassword, &QLineEdit::textChanged, this, &UsersPage::onPasswordTextChanged ); connect( ui->textBoxRootPassword, &QLineEdit::textChanged, this, &UsersPage::onRootPasswordTextChanged ); connect( ui->textBoxVerifiedRootPassword, &QLineEdit::textChanged, this, &UsersPage::onRootPasswordTextChanged ); - connect( ui->checkBoxValidatePassword, &QCheckBox::stateChanged, this, [this]( int ) - { + connect( ui->checkBoxValidatePassword, &QCheckBox::stateChanged, this, [this]( int ) { onPasswordTextChanged( ui->textBoxUserPassword->text() ); onRootPasswordTextChanged( ui->textBoxRootPassword->text() ); checkReady( isReady() ); } ); - connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, [this]( int checked ) - { + connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, [this]( int checked ) { ui->labelChooseRootPassword->setVisible( !checked ); ui->labelRootPassword->setVisible( !checked ); ui->labelRootPasswordError->setVisible( !checked ); @@ -166,6 +166,37 @@ UsersPage::isReady() return readyFields && m_readyRootPassword; } +QString +UsersPage::getHostname() const +{ + return ui->textBoxHostname->text(); +} + +QString +UsersPage::getRootPassword() const +{ + if ( m_writeRootPassword ) + { + if ( ui->checkBoxReusePassword->isChecked() ) + { + return ui->textBoxUserPassword->text(); + } + else + { + return ui->textBoxRootPassword->text(); + } + } + else + { + return QString(); + } +} + +QPair< QString, QString > +UsersPage::getUserPassword() const +{ + return QPair< QString, QString >( ui->textBoxUsername->text(), ui->textBoxUserPassword->text() ); +} QList< Calamares::job_ptr > UsersPage::createJobs( const QStringList& defaultGroupsList ) @@ -186,32 +217,10 @@ UsersPage::createJobs( const QStringList& defaultGroupsList ) defaultGroupsList ); list.append( Calamares::job_ptr( j ) ); - j = new SetPasswordJob( ui->textBoxUsername->text(), ui->textBoxUserPassword->text() ); - list.append( Calamares::job_ptr( j ) ); - if ( m_writeRootPassword ) { gs->insert( "reuseRootPassword", ui->checkBoxReusePassword->isChecked() ); - if ( ui->checkBoxReusePassword->isChecked() ) - { - j = new SetPasswordJob( "root", ui->textBoxUserPassword->text() ); - } - else - { - j = new SetPasswordJob( "root", ui->textBoxRootPassword->text() ); - } - list.append( Calamares::job_ptr( j ) ); } - else - { - j = new SetPasswordJob( "root", - "" ); //explicitly disable root password - list.append( Calamares::job_ptr( j ) ); - } - - j = new SetHostNameJob( ui->textBoxHostname->text() ); - list.append( Calamares::job_ptr( j ) ); - gs->insert( "hostname", ui->textBoxHostname->text() ); if ( ui->checkBoxAutoLogin->isChecked() ) { @@ -269,6 +278,38 @@ UsersPage::onFullNameTextEdited( const QString& textRef ) checkReady( isReady() ); } +/** @brief Guess the machine's name + * + * If there is DMI data, use that; otherwise, just call the machine "-pc". + * Reads the DMI data just once. + */ +static QString +guessProductName() +{ + static bool tried = false; + static QString dmiProduct; + + if ( !tried ) + { + // yes validateHostnameText() but these files can be a mess + QRegExp dmirx( "[^a-zA-Z0-9]", Qt::CaseInsensitive ); + QFile dmiFile( QStringLiteral( "/sys/devices/virtual/dmi/id/product_name" ) ); + + if ( dmiFile.exists() && dmiFile.open( QIODevice::ReadOnly ) ) + { + dmiProduct = QString::fromLocal8Bit( dmiFile.readAll().simplified().data() ) + .toLower() + .replace( dmirx, " " ) + .remove( ' ' ); + } + if ( dmiProduct.isEmpty() ) + { + dmiProduct = QStringLiteral( "-pc" ); + } + tried = true; + } + return dmiProduct; +} void UsersPage::fillSuggestions() @@ -303,7 +344,9 @@ UsersPage::fillSuggestions() { if ( !cleanParts.isEmpty() && !cleanParts.first().isEmpty() ) { - QString hostnameSuggestion = QString( "%1-pc" ).arg( cleanParts.first() ); + QString hostnameSuggestion; + QString productName = guessProductName(); + hostnameSuggestion = QString( "%1-%2" ).arg( cleanParts.first() ).arg( productName ); if ( HOSTNAME_RX.indexIn( hostnameSuggestion ) != -1 ) { ui->textBoxHostname->setText( hostnameSuggestion ); @@ -524,10 +567,10 @@ UsersPage::addPasswordCheck( const QString& key, const QVariant& value ) { if ( value.toBool() ) { - m_passwordChecks.push_back( PasswordCheck( - []() { return QCoreApplication::translate( "PWQ", "Password is empty" ); }, - []( const QString& s ) { return !s.isEmpty(); }, - PasswordCheck::Weight( 1 ) ) ); + m_passwordChecks.push_back( + PasswordCheck( []() { return QCoreApplication::translate( "PWQ", "Password is empty" ); }, + []( const QString& s ) { return !s.isEmpty(); }, + PasswordCheck::Weight( 1 ) ) ); } } #ifdef CHECK_PWQUALITY diff --git a/src/modules/users/UsersPage.h b/src/modules/users/UsersPage.h index c6bf87ecf..3382e9335 100644 --- a/src/modules/users/UsersPage.h +++ b/src/modules/users/UsersPage.h @@ -63,6 +63,13 @@ public: */ void addPasswordCheck( const QString& key, const QVariant& value ); + ///@brief Hostname as entered / auto-filled + QString getHostname() const; + ///@brief Root password, depends on settings, may be empty + QString getRootPassword() const; + ///@brief User name and password + QPair< QString, QString > getUserPassword() const; + protected slots: void onFullNameTextEdited( const QString& ); void fillSuggestions(); diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp index b898f00c8..fe633b1c2 100644 --- a/src/modules/users/UsersViewStep.cpp +++ b/src/modules/users/UsersViewStep.cpp @@ -20,10 +20,12 @@ #include "UsersViewStep.h" +#include "SetHostNameJob.h" +#include "SetPasswordJob.h" #include "UsersPage.h" -// #include "utils/CalamaresUtils.h" #include "utils/Logger.h" +#include "utils/NamedEnum.h" #include "utils/Variant.h" #include "GlobalStorage.h" @@ -31,9 +33,28 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( UsersViewStepFactory, registerPlugin< UsersViewStep >(); ) +static const NamedEnumTable< SetHostNameJob::Action >& +hostnameActions() +{ + using Action = SetHostNameJob::Action; + + // *INDENT-OFF* + // clang-format off + static const NamedEnumTable< Action > names { + { QStringLiteral( "none" ), Action::None }, + { QStringLiteral( "etcfile" ), Action::EtcHostname }, + { QStringLiteral( "hostnamed" ), Action::SystemdHostname } + }; + // clang-format on + // *INDENT-ON* + + return names; +} + UsersViewStep::UsersViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_widget( new UsersPage() ) + , m_actions( SetHostNameJob::Action::None ) { emit nextStatusChanged( true ); connect( m_widget, &UsersPage::checkReady, this, &UsersViewStep::nextStatusChanged ); @@ -109,14 +130,27 @@ void UsersViewStep::onLeave() { m_jobs.clear(); - m_jobs.append( m_widget->createJobs( m_defaultGroups ) ); + + Calamares::Job* j; + + auto userPW = m_widget->getUserPassword(); + j = new SetPasswordJob( userPW.first, userPW.second ); + m_jobs.append( Calamares::job_ptr( j ) ); + + j = new SetPasswordJob( "root", m_widget->getRootPassword() ); + m_jobs.append( Calamares::job_ptr( j ) ); + + j = new SetHostNameJob( m_widget->getHostname(), m_actions ); + m_jobs.append( Calamares::job_ptr( j ) ); } void UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { + using CalamaresUtils::getBool; + if ( configurationMap.contains( "defaultGroups" ) && configurationMap.value( "defaultGroups" ).type() == QVariant::List ) { @@ -142,25 +176,12 @@ UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap ) configurationMap.value( "sudoersGroup" ).toString() ); } - if ( configurationMap.contains( "setRootPassword" ) - && configurationMap.value( "setRootPassword" ).type() == QVariant::Bool ) - { - Calamares::JobQueue::instance()->globalStorage()->insert( - "setRootPassword", configurationMap.value( "setRootPassword" ).toBool() ); - m_widget->setWriteRootPassword( configurationMap.value( "setRootPassword" ).toBool() ); - } + bool setRootPassword = getBool( configurationMap, "setRootPassword", true ); + Calamares::JobQueue::instance()->globalStorage()->insert( "setRootPassword", setRootPassword ); - if ( configurationMap.contains( "doAutologin" ) - && configurationMap.value( "doAutologin" ).type() == QVariant::Bool ) - { - m_widget->setAutologinDefault( configurationMap.value( "doAutologin" ).toBool() ); - } - - if ( configurationMap.contains( "doReusePassword" ) - && configurationMap.value( "doReusePassword" ).type() == QVariant::Bool ) - { - m_widget->setReusePasswordDefault( configurationMap.value( "doReusePassword" ).toBool() ); - } + m_widget->setWriteRootPassword( setRootPassword ); + m_widget->setAutologinDefault( getBool( configurationMap, "doAutologin", false ) ); + m_widget->setReusePasswordDefault( getBool( configurationMap, "doReusePassword", false ) ); if ( configurationMap.contains( "passwordRequirements" ) && configurationMap.value( "passwordRequirements" ).type() == QVariant::Map ) @@ -173,8 +194,8 @@ UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap ) } } - m_widget->setPasswordCheckboxVisible( CalamaresUtils::getBool( configurationMap, "allowWeakPasswords", false ) ); - m_widget->setValidatePasswordDefault( !CalamaresUtils::getBool( configurationMap, "allowWeakPasswordsDefault", false) ); + m_widget->setPasswordCheckboxVisible( getBool( configurationMap, "allowWeakPasswords", false ) ); + m_widget->setValidatePasswordDefault( !getBool( configurationMap, "allowWeakPasswordsDefault", false ) ); QString shell( QLatin1String( "/bin/bash" ) ); // as if it's not set at all if ( configurationMap.contains( "userShell" ) ) @@ -184,4 +205,21 @@ UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap ) // Now it might be explicitly set to empty, which is ok Calamares::JobQueue::instance()->globalStorage()->insert( "userShell", shell ); + + using Action = SetHostNameJob::Action; + + QString hostnameActionString = CalamaresUtils::getString( configurationMap, "setHostname" ); + if ( hostnameActionString.isEmpty() ) + { + hostnameActionString = QStringLiteral( "EtcFile" ); + } + bool ok = false; + auto hostnameAction = hostnameActions().find( hostnameActionString, ok ); + if ( !ok ) + { + hostnameAction = Action::EtcHostname; + } + + Action hostsfileAction = getBool( configurationMap, "writeHostsFile", true ) ? Action::WriteEtcHosts : Action::None; + m_actions = hostsfileAction | hostnameAction; } diff --git a/src/modules/users/UsersViewStep.h b/src/modules/users/UsersViewStep.h index 6fced76b9..03cc83819 100644 --- a/src/modules/users/UsersViewStep.h +++ b/src/modules/users/UsersViewStep.h @@ -20,13 +20,13 @@ #ifndef USERSPAGEPLUGIN_H #define USERSPAGEPLUGIN_H +#include "SetHostNameJob.h" + +#include "DllMacro.h" +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" + #include - -#include -#include - -#include - #include class UsersPage; @@ -61,6 +61,7 @@ private: QList< Calamares::job_ptr > m_jobs; QStringList m_defaultGroups; + SetHostNameJob::Actions m_actions; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( UsersViewStepFactory ) diff --git a/src/modules/users/users.conf b/src/modules/users/users.conf index 00747195c..1c928fd3a 100644 --- a/src/modules/users/users.conf +++ b/src/modules/users/users.conf @@ -28,13 +28,13 @@ defaultGroups: # Disable when your Distribution does not require such a group. autologinGroup: autologin # You can control the initial state for the 'autologin checkbox' here. -# Possible values are: -# - true to check or +# Possible values are: +# - true to check or # - false to uncheck # These set the **initial** state of the checkbox. doAutologin: true -# When *sudoersGroup* is set to a non-empty string, Calamares creates a +# When *sudoersGroup* is set to a non-empty string, Calamares creates a # sudoers file for the user. This file is located at: # `/etc/sudoers.d/10-installer` # Remember to add the (value of) *sudoersGroup* to *defaultGroups*. @@ -48,8 +48,8 @@ sudoersGroup: wheel # Setting this to false , causes the root account to be disabled. setRootPassword: true # You can control the initial state for the 'reuse password for root' -# checkbox here. Possible values are: -# - true to check or +# checkbox here. Possible values are: +# - true to check or # - false to uncheck # # When checked, the user password is used for the root account too. @@ -96,18 +96,18 @@ passwordRequirements: libpwquality: - minlen=0 - minclass=0 - + # You can control the visibility of the 'strong passwords' checkbox here. -# Possible values are: -# - true to show or +# Possible values are: +# - true to show or # - false to hide (default) # the checkbox. This checkbox allows the user to choose to disable # password-strength-checks. By default the box is **hidden**, so # that you have to pick a password that satisfies the checks. allowWeakPasswords: false # You can control the initial state for the 'strong passwords' checkbox here. -# Possible values are: -# - true to uncheck or +# Possible values are: +# - true to uncheck or # - false to check (default) # the checkbox by default. Since the box is labeled to enforce strong # passwords, in order to **allow** weak ones by default, the box needs @@ -122,3 +122,17 @@ allowWeakPasswordsDefault: false # - set, non-empty, use that path as shell. No validation is done # that the shell actually exists or is executable. # userShell: /bin/bash + +# Hostname setting +# +# The user can enter a hostname; this is configured into the system +# in some way; pick one of: +# - *None*, to not set the hostname at all +# - *EtcFile*, to write to `/etc/hostname` directly +# - *Hostnamed*, to use systemd hostnamed(1) over DBus +# The default is *EtcFile*. +setHostname: EtcFile + +# Should /etc/hosts be written with a hostname for this machine +# (also adds localhost and some ipv6 standard entries). +writeHostsFile: true diff --git a/src/modules/webview/WebViewStep.h b/src/modules/webview/WebViewStep.h index c588318fa..9ee2dfac9 100644 --- a/src/modules/webview/WebViewStep.h +++ b/src/modules/webview/WebViewStep.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include diff --git a/src/modules/welcome/WelcomeViewStep.h b/src/modules/welcome/WelcomeViewStep.h index 4d8fa160f..217f827e9 100644 --- a/src/modules/welcome/WelcomeViewStep.h +++ b/src/modules/welcome/WelcomeViewStep.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.h b/src/modules/welcomeq/WelcomeQmlViewStep.h index 5486d8d31..468dd7621 100644 --- a/src/modules/welcomeq/WelcomeQmlViewStep.h +++ b/src/modules/welcomeq/WelcomeQmlViewStep.h @@ -25,7 +25,7 @@ #include "utils/PluginFactory.h" #include "viewpages/ViewStep.h" -#include +#include #include #include