diff --git a/hacking/GlobalStorage.md b/hacking/GlobalStorage.md index 0e024b16c..000282662 100644 --- a/hacking/GlobalStorage.md +++ b/hacking/GlobalStorage.md @@ -10,6 +10,17 @@ A dictionary with the following keys: - `installPath`: device where the boot loader should be installed ("/dev/sda", "/dev/sdb1"...) +## branding + +A dictionary with the following keys (loaded from branding.desc): + +- `productName`: distribution unversioned product name (long version) +- `shortProductName`: distribution unversioned product name (short version) +- `version`: distribution version number (long version) +- `shortVersion`: distribution version number (short version) +- `versionedName`: distribution product name and version (long version) +- `shortVersionedName`: distribution product name and version (short version) + ## partitions A list of dictionaries, one per partition. The dictionary contains the following keys: diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 93ca927cf..06ffe4747 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -3,6 +3,7 @@ componentName: default strings: productName: Generic GNU/Linux + shortProductName: Generic version: 1.0 LTS shortVersion: 1.0 versionedName: Generic GNU/Linux 1.0 LTS "Rusty Trombone" diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index c7851d6b7..78b16e3bb 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -316,5 +316,6 @@ CalamaresApplication::onPluginsReady() void CalamaresApplication::initJobQueue() { - new Calamares::JobQueue( this ); + Calamares::JobQueue *jobQueue = new Calamares::JobQueue( this ); + Calamares::Branding::instance()->setGlobals( jobQueue->globalStorage() ); } diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index b1672f899..43a7714fc 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -18,6 +18,7 @@ #include "Branding.h" +#include "GlobalStorage.h" #include "utils/CalamaresUtils.h" #include "utils/Logger.h" #include "utils/YamlUtils.h" @@ -26,6 +27,7 @@ #include #include #include +#include #include @@ -48,7 +50,8 @@ QStringList Branding::s_stringEntryStrings = "version", "shortVersion", "versionedName", - "shortVersionedName" + "shortVersionedName", + "shortProductName" }; @@ -200,6 +203,16 @@ Branding::slideshowPaths() const } +void +Branding::setGlobals( GlobalStorage* globalStorage ) const +{ + QVariantMap brandingMap; + foreach ( const QString& key, s_stringEntryStrings ) + brandingMap.insert( key, m_strings.value( key ) ); + globalStorage->insert( "branding", brandingMap ); +} + + void Branding::bail( const QString& message ) { diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index d86c92878..6a4446ecd 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -30,6 +30,8 @@ namespace Calamares { +class GlobalStorage; + class UIDLLEXPORT Branding : public QObject { Q_OBJECT @@ -40,7 +42,8 @@ public: Version, ShortVersion, VersionedName, - ShortVersionedName + ShortVersionedName, + ShortProductName }; enum ImageEntry : short @@ -63,6 +66,13 @@ public: QPixmap image( Branding::ImageEntry imageEntry, const QSize& size ) const; QStringList slideshowPaths() const; + /** + * Creates a map called "branding" in the global storage, and inserts an + * entry for each of the branding strings. This makes the branding + * information accessible to the Python modules. + */ + void setGlobals( GlobalStorage* globalStorage ) const; + private: static Branding* s_instance; diff --git a/src/modules/bootloader/bootloader.conf b/src/modules/bootloader/bootloader.conf index 34ea11ddd..af79d1bb9 100644 --- a/src/modules/bootloader/bootloader.conf +++ b/src/modules/bootloader/bootloader.conf @@ -1,7 +1,6 @@ --- -# Gummiboot configuration files settings, set preferred distribution name and amount of time before -# default selection boots -distribution: KaOS-kf5 +# Gummiboot configuration files settings, set kernel and initramfs file names +# and amount of time before default selection boots kernel: /vmlinuz-linux img: /initramfs-linux.img fallback: /initramfs-linux-fallback.img diff --git a/src/modules/bootloader/main.py b/src/modules/bootloader/main.py index e868fd948..efca4a1b8 100644 --- a/src/modules/bootloader/main.py +++ b/src/modules/bootloader/main.py @@ -53,7 +53,8 @@ def get_uuid(): def create_conf(uuid, conf_path): - distribution = libcalamares.job.configuration["distribution"] + branding = libcalamares.globalstorage.value("branding") + distribution = branding["shortProductName"] kernel = libcalamares.job.configuration["kernel"] img = libcalamares.job.configuration["img"] partitions = libcalamares.globalstorage.value("partitions") @@ -79,7 +80,8 @@ def create_conf(uuid, conf_path): def create_fallback(uuid, fallback_path): - distribution = libcalamares.job.configuration["distribution"] + branding = libcalamares.globalstorage.value("branding") + distribution = branding["shortProductName"] kernel = libcalamares.job.configuration["kernel"] fb_img = libcalamares.job.configuration["fallback"] partitions = libcalamares.globalstorage.value("partitions") @@ -105,11 +107,13 @@ def create_fallback(uuid, fallback_path): def create_loader(loader_path): - distribution = libcalamares.job.configuration["distribution"] + branding = libcalamares.globalstorage.value("branding") + distribution = branding["shortProductName"] timeout = libcalamares.job.configuration["timeout"] + file_name_sanitizer = str.maketrans(" /", "_-") lines = [ 'timeout %s\n' % timeout, - 'default %s\n' % distribution, + 'default %s\n' % distribution.translate(file_name_sanitizer), ] with open(loader_path, 'w') as f: @@ -122,11 +126,13 @@ def install_bootloader(boot_loader, fw_type): if fw_type == 'efi': install_path = libcalamares.globalstorage.value("rootMountPoint") uuid = get_uuid() - distribution = libcalamares.job.configuration["distribution"] + branding = libcalamares.globalstorage.value("branding") + distribution = branding["shortProductName"] + file_name_sanitizer = str.maketrans(" /", "_-") conf_path = os.path.join( - install_path, "boot", "loader", "entries", "%s.conf" % distribution) + install_path, "boot", "loader", "entries", "%s.conf" % distribution.translate(file_name_sanitizer)) fallback_path = os.path.join( - install_path, "boot", "loader", "entries", "%s-fallback.conf" % distribution) + install_path, "boot", "loader", "entries", "%s-fallback.conf" % distribution.translate(file_name_sanitizer)) loader_path = os.path.join( install_path, "boot", "loader", "loader.conf") partitions = libcalamares.globalstorage.value("partitions") diff --git a/src/modules/bootloader/test.yaml b/src/modules/bootloader/test.yaml index 3b9852e63..1cd6c418f 100644 --- a/src/modules/bootloader/test.yaml +++ b/src/modules/bootloader/test.yaml @@ -1,3 +1,5 @@ rootMountPoint: /tmp/mount bootLoader: installPath: /dev/sdb +branding: + shortProductName: "Generic Distro" diff --git a/src/modules/grubcfg/grubcfg.conf b/src/modules/grubcfg/grubcfg.conf deleted file mode 100644 index bdbe2dbcd..000000000 --- a/src/modules/grubcfg/grubcfg.conf +++ /dev/null @@ -1,3 +0,0 @@ ---- -# Replace 'LinuxDistribution' with your distribution name - for example with 'Manjaro' -distributor: LinuxDistribution diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index 26d26a14c..3e3ad81f0 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -56,7 +56,7 @@ def modify_grub_default(partitions, root_mount_point, distributor): elif lines[i].startswith("GRUB_CMDLINE_LINUX_DEFAULT"): lines[i] = kernel_cmd elif lines[i].startswith("#GRUB_DISTRIBUTOR") or lines[i].startswith("GRUB_DISTRIBUTOR"): - lines[i] = "GRUB_DISTRIBUTOR=%s" % distributor + lines[i] = "GRUB_DISTRIBUTOR='%s'" % distributor.replace("'", "'\\''") with open(default_grub, 'w') as grub_file: grub_file.write("\n".join(lines) + "\n") @@ -66,5 +66,6 @@ def modify_grub_default(partitions, root_mount_point, distributor): def run(): partitions = libcalamares.globalstorage.value("partitions") root_mount_point = libcalamares.globalstorage.value("rootMountPoint") - distributor = libcalamares.job.configuration["distributor"] + branding = libcalamares.globalstorage.value("branding") + distributor = branding["shortProductName"] return modify_grub_default(partitions, root_mount_point, distributor)