From 4961990ce00892325b08a10d91f5eba9b3711e7c Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Sun, 31 Jul 2022 16:02:10 +0200 Subject: [PATCH] Allow outsourcing custom settings to script --- debian/changelog | 2 ++ src/OptionsPopup.qml | 67 +++++++++++++++++++++++++++++++------------- 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1fc6f90..fa2b9df 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,8 @@ rpi-imager (1.7.3) unstable; urgency=medium * Update Slovan/Korean language files * Allow selecting file names without extension * Add new regulatory-domain parameter to cloud-init files + * Add possibility to outsource handling of custom settings to script at + /usr/lib/raspberrypi-sys-mods/imager_custom -- Floris Bos Sun, 31 Jul 2022 12:15:17 +0200 diff --git a/src/OptionsPopup.qml b/src/OptionsPopup.qml index 4b14e3b..04a89e5 100644 --- a/src/OptionsPopup.qml +++ b/src/OptionsPopup.qml @@ -595,8 +595,12 @@ Popup { if (chkHostname.checked && fieldHostname.length) { addFirstRun("CURRENT_HOSTNAME=`cat /etc/hostname | tr -d \" \\t\\n\\r\"`") - addFirstRun("echo "+fieldHostname.text+" >/etc/hostname") - addFirstRun("sed -i \"s/127.0.1.1.*$CURRENT_HOSTNAME/127.0.1.1\\t"+fieldHostname.text+"/g\" /etc/hosts") + addFirstRun("if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then") + addFirstRun(" /usr/lib/raspberrypi-sys-mods/imager_custom set_hostname "+fieldHostname.text) + addFirstRun("else") + addFirstRun(" echo "+fieldHostname.text+" >/etc/hostname") + addFirstRun(" sed -i \"s/127.0.1.1.*$CURRENT_HOSTNAME/127.0.1.1\\t"+fieldHostname.text+"/g\" /etc/hosts") + addFirstRun("fi") addCloudInit("hostname: "+fieldHostname.text) addCloudInit("manage_etc_hosts: true") @@ -631,12 +635,22 @@ Popup { if (chkSSH.checked && radioPubKeyAuthentication.checked) { var pubkey = fieldPublicKey.text var pubkeyArr = pubkey.split("\n") - - if (pubkey.length) { - addFirstRun("install -o \"$FIRSTUSER\" -m 700 -d \"$FIRSTUSERHOME/.ssh\"") - addFirstRun("install -o \"$FIRSTUSER\" -m 600 <(printf \""+pubkey.replace(/\n/g, "\\n")+"\") \"$FIRSTUSERHOME/.ssh/authorized_keys\"") + var pubkeySpaceSep = '' + for (var j=0; j>/etc/ssh/sshd_config") + + addFirstRun("if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then") + addFirstRun(" /usr/lib/raspberrypi-sys-mods/imager_custom enable_ssh -k"+pubkeySpaceSep) + addFirstRun("else") + addFirstRun(" install -o \"$FIRSTUSER\" -m 700 -d \"$FIRSTUSERHOME/.ssh\"") + addFirstRun(" install -o \"$FIRSTUSER\" -m 600 <(printf \""+pubkey.replace(/\n/g, "\\n")+"\") \"$FIRSTUSERHOME/.ssh/authorized_keys\"") + addFirstRun(" echo 'PasswordAuthentication no' >>/etc/ssh/sshd_config") + addFirstRun(" systemctl enable ssh") + addFirstRun("fi") if (!chkSetUser.checked) { addCloudInit(" lock_passwd: true") @@ -654,6 +668,11 @@ Popup { if (chkSSH.checked && radioPasswordAuthentication.checked) { addCloudInit("ssh_pwauth: true") + addFirstRun("if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then") + addFirstRun(" /usr/lib/raspberrypi-sys-mods/imager_custom enable_ssh") + addFirstRun("else") + addFirstRun(" systemctl enable ssh") + addFirstRun("fi") } if (chkSetUser.checked) { @@ -678,10 +697,6 @@ Popup { addFirstRun(" fi") addFirstRun("fi") } - - if (chkSSH.checked) { - addFirstRun("systemctl enable ssh") - } addCloudInit("") } if (chkWifi.checked) { @@ -698,14 +713,21 @@ Popup { wpaconfig += "\tpsk="+cryptedPsk+"\n" wpaconfig += "}\n" + addFirstRun("if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then") + addFirstRun(" /usr/lib/raspberrypi-sys-mods/imager_custom set_wlan " + +(chkWifiSSIDHidden.checked ? " -h " : "") + +escapeshellarg(fieldWifiSSID.text)+" "+escapeshellarg(cryptedPsk)+" "+escapeshellarg(fieldWifiCountry.editText)) + addFirstRun("else") addFirstRun("cat >/etc/wpa_supplicant/wpa_supplicant.conf <<'WPAEOF'") addFirstRun(wpaconfig) addFirstRun("WPAEOF") - addFirstRun("chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf") - addFirstRun("rfkill unblock wifi") - addFirstRun("for filename in /var/lib/systemd/rfkill/*:wlan ; do") - addFirstRun(" echo 0 > $filename") - addFirstRun("done") + addFirstRun(" chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf") + addFirstRun(" rfkill unblock wifi") + addFirstRun(" for filename in /var/lib/systemd/rfkill/*:wlan ; do") + addFirstRun(" echo 0 > $filename") + addFirstRun(" done") + addFirstRun("fi") + cloudinitnetwork = "version: 2\n" cloudinitnetwork += "wifis:\n" @@ -730,13 +752,18 @@ Popup { kbdconfig += "XKBVARIANT=\"\"\n" kbdconfig += "XKBOPTIONS=\"\"\n" - addFirstRun("rm -f /etc/localtime") - addFirstRun("echo \""+fieldTimezone.editText+"\" >/etc/timezone") - addFirstRun("dpkg-reconfigure -f noninteractive tzdata") + addFirstRun("if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then") + addFirstRun(" /usr/lib/raspberrypi-sys-mods/imager_custom set_keymap "+escapeshellarg(fieldKeyboardLayout.editText)) + addFirstRun(" /usr/lib/raspberrypi-sys-mods/imager_custom set_timezone "+escapeshellarg(fieldTimezone.editText)) + addFirstRun("else") + addFirstRun(" rm -f /etc/localtime") + addFirstRun(" echo \""+fieldTimezone.editText+"\" >/etc/timezone") + addFirstRun(" dpkg-reconfigure -f noninteractive tzdata") addFirstRun("cat >/etc/default/keyboard <<'KBEOF'") addFirstRun(kbdconfig) addFirstRun("KBEOF") - addFirstRun("dpkg-reconfigure -f noninteractive keyboard-configuration") + addFirstRun(" dpkg-reconfigure -f noninteractive keyboard-configuration") + addFirstRun("fi") addCloudInit("timezone: "+fieldTimezone.editText) addCloudInitRun("localectl set-x11-keymap \""+fieldKeyboardLayout.editText+"\" pc105")