From 1c4bf58fb459c58a2f18c302c724aa44ddf14573 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 22 Dec 2020 21:25:00 +0100 Subject: [PATCH] [libcalamares] automount-manipulation test-program --- src/libcalamares/CMakeLists.txt | 5 +++ src/libcalamares/partition/calautomount.cpp | 48 +++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/libcalamares/partition/calautomount.cpp diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index fd3a678c3..87eb387fa 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -260,3 +260,8 @@ calamares_add_test( add_executable( test_geoip geoip/test_geoip.cpp ${geoip_src} ) target_link_libraries( test_geoip calamares Qt5::Network yamlcpp ) calamares_automoc( test_geoip ) + +if ( Qt5DBus_FOUND ) + add_executable( calautomount partition/calautomount.cpp ) + target_link_libraries( calautomount calamares Qt5::DBus ) +endif() diff --git a/src/libcalamares/partition/calautomount.cpp b/src/libcalamares/partition/calautomount.cpp new file mode 100644 index 000000000..3eb95be08 --- /dev/null +++ b/src/libcalamares/partition/calautomount.cpp @@ -0,0 +1,48 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2020 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + * + */ + +/** @brief Command-line tool to enable or disable automounting + * + * This application uses Calamares methods to enable or disable + * automount settings in the running system. This can be used to + * test the automount-manipulating code without running + * a full Calamares or doing an installation. + * + */ + +static const char usage[] = "Usage: calautomount <-e|-d>\n" +"\n" +"Enables (if `-e` is passed as command-line option) or\n" +"Disables (if `-d` is passed as command-line option)\n" +"\n" +"automounting of disks in the host system as best it can.\n" +"Exits with code 0 on success or 1 if an unknown option is\n" +"passed on the command-line.\n\n"; + +#include "AutoMount.h" +#include "Sync.h" + +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + if ((argc != 2) || (argv[1][0] != '-') || (argv[1][1] !='e' && argv[1][1] !='d')) + { + qWarning() << usage; + return 1; + } + + CalamaresUtils::Partition::automountDisable( argv[1][1] == 'd'); + + return 0; +}