From b0bd95a9776ea72a236c2ee5c4039a804299a714 Mon Sep 17 00:00:00 2001 From: "Gerd v. Egidy" Date: Wed, 24 Aug 2022 13:18:08 +0200 Subject: [PATCH] Add rclone option to the "sysconfig" scope of YAML config file rclone needs a rclone.conf file before it can be used, it contains the urls, login data and similar. Use the sysconfig.rclone.config hierarchy instead of just sysconfig.rclone to allow adding features later. These could be support for encrypted rclone config files (these would then go into sysconfig.rclone.crypted_config) or things like automounting. --- ChangeLog | 5 ++++ .../systemd/scripts/sysrescue-initialize.py | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/ChangeLog b/ChangeLog index 115898a..2d397de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ IMPORTANT: The 32bit (i686) release of SystemRescue will be deprecated soon unless volunteers are found to help maintaining it. See https://gitlab.com/systemrescue/systemrescue-sources/-/issues/278 +------------------------------------------------------------------------------ +9.05 (YYYY-MM-DD): +------------------------------------------------------------------------------- +* Add rclone option to the "sysconfig" scope of YAML config file, it writes a rclone.conf file + ------------------------------------------------------------------------------ 9.04 (2022-08-07): ------------------------------------------------------------------------------- diff --git a/airootfs/etc/systemd/scripts/sysrescue-initialize.py b/airootfs/etc/systemd/scripts/sysrescue-initialize.py index 0cc6cbe..a41bc45 100755 --- a/airootfs/etc/systemd/scripts/sysrescue-initialize.py +++ b/airootfs/etc/systemd/scripts/sysrescue-initialize.py @@ -10,6 +10,7 @@ import sys import re import tempfile import functools +import configparser # flush stdout buffer after each print call: immediately show the user what is going on print = functools.partial(print, flush=True) @@ -249,6 +250,33 @@ if 'sysconfig' in config and 'bookmarks' in config['sysconfig'] and config['sysc with open(firefox_policy_path, "w", encoding='utf-8') as polfile: json.dump(ff_policy, polfile, ensure_ascii=False, indent=2) +# ============================================================================== +# configure rclone +# ============================================================================== + +if 'sysconfig' in config and 'rclone' in config['sysconfig'] and \ + config['sysconfig']['rclone'] and isinstance(config['sysconfig']['rclone'], dict) and \ + 'config' in config['sysconfig']['rclone'] and \ + config['sysconfig']['rclone']['config'] and \ + isinstance(config['sysconfig']['rclone']['config'], dict): + print(f"====> Adding rclone config ...") + + try: + if not os.path.isdir("/root/.config"): + os.mkdir("/root/.config") + if not os.path.isdir("/root/.config/rclone"): + os.mkdir("/root/.config/rclone") + os.chmod("/root/.config/rclone", 0o700) + + iniparser = configparser.ConfigParser() + iniparser.read_dict(config['sysconfig']['rclone']['config']) + with open('/root/.config/rclone/rclone.conf', 'w') as configfile: + os.chmod("/root/.config/rclone/rclone.conf", 0o600) + iniparser.write(configfile) + except Exception as e: + print(e) + errcnt+=1 + # ============================================================================== # Configure custom CA certificates # ==============================================================================