Skip to content

Commit 010ab63

Browse files
committed
Raspberry Pi OS cloud-init support
Signed-off-by: paulober <[email protected]>
1 parent 092e59e commit 010ab63

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

src/OptionsPopup.qml

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -712,21 +712,35 @@ Window {
712712
addCloudInit("")
713713
}
714714

715+
var isRpiosCloudInit = imageWriter.checkSWCapability("rpios_cloudinit");
716+
715717
if (chkSSH.checked || chkSetUser.checked) {
716718
// First user may not be called 'pi' on all distributions, so look username up
717719
addFirstRun("FIRSTUSER=`getent passwd 1000 | cut -d: -f1`");
718720
addFirstRun("FIRSTUSERHOME=`getent passwd 1000 | cut -d: -f6`")
719721

720-
addCloudInit("users:")
721-
addCloudInit("- name: "+fieldUserName.text)
722-
addCloudInit(" groups: users,adm,dialout,audio,netdev,video,plugdev,cdrom,games,input,gpio,spi,i2c,render,sudo")
723-
addCloudInit(" shell: /bin/bash")
724-
725722
var cryptedPassword;
726723
if (chkSetUser.checked) {
727724
cryptedPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text)
728-
addCloudInit(" lock_passwd: false")
729-
addCloudInit(" passwd: "+cryptedPassword)
725+
}
726+
727+
if (isRpiosCloudInit && cryptedPassword) {
728+
addCloudInit("rpi_userconf:")
729+
addCloudInit(" password: " + cryptedPassword)
730+
addCloudInit(" user: " + fieldUserName.text)
731+
addCloudInit("")
732+
}
733+
734+
addCloudInit("users:")
735+
addCloudInit("- name: " + fieldUserName.text)
736+
if (!isRpiosCloudInit) {
737+
addCloudInit(" groups: users,adm,dialout,audio,netdev,video,plugdev,cdrom,games,input,gpio,spi,i2c,render,sudo")
738+
addCloudInit(" shell: /bin/bash")
739+
740+
if (chkSetUser.checked) {
741+
addCloudInit(" lock_passwd: false")
742+
addCloudInit(" passwd: "+cryptedPassword)
743+
}
730744
}
731745

732746
if (chkSSH.checked && radioPubKeyAuthentication.checked) {
@@ -759,7 +773,9 @@ Window {
759773
addCloudInit(" - "+pk)
760774
}
761775
}
762-
addCloudInit(" sudo: ALL=(ALL) NOPASSWD:ALL")
776+
if (!isRpiosCloudInit) {
777+
addCloudInit(" sudo: ALL=(ALL) NOPASSWD:ALL")
778+
}
763779
}
764780
addCloudInit("")
765781

@@ -795,6 +811,14 @@ Window {
795811
addFirstRun("fi")
796812
}
797813
addCloudInit("")
814+
815+
/*if (chkSetUser.checked) {
816+
addCloudInit("final_message: \"Setup wizard has been skiped.\"")
817+
addCloudInit("power_state:")
818+
addCloudInit(" mode: reboot")
819+
addCloudInit(" message: Rebooting machine")
820+
addCloudInit("")
821+
}*/
798822
}
799823
if (chkWifi.checked) {
800824
var wpaconfig = "country="+fieldWifiCountry.editText+"\n"
@@ -830,17 +854,18 @@ Window {
830854
addFirstRun("fi")
831855

832856

833-
cloudinitnetwork = "version: 2\n"
834-
cloudinitnetwork += "wifis:\n"
835-
cloudinitnetwork += " renderer: networkd\n"
836-
cloudinitnetwork += " wlan0:\n"
837-
cloudinitnetwork += " dhcp4: true\n"
838-
cloudinitnetwork += " optional: true\n"
839-
cloudinitnetwork += " access-points:\n"
840-
cloudinitnetwork += " \""+fieldWifiSSID.text+"\":\n"
841-
cloudinitnetwork += " password: \""+cryptedPsk+"\"\n"
857+
cloudinitnetwork = "network:\n"
858+
cloudinitnetwork += " version: 2\n"
859+
cloudinitnetwork += " renderer: " + (isRpiosCloudInit ? "NetworkManager" : "networkd") + "\n"
860+
cloudinitnetwork += " wifis:\n"
861+
cloudinitnetwork += " wlan0:\n"
862+
cloudinitnetwork += " dhcp4: true\n"
863+
cloudinitnetwork += " optional: true\n"
864+
cloudinitnetwork += " access-points:\n"
865+
cloudinitnetwork += " \""+fieldWifiSSID.text+"\":\n"
866+
cloudinitnetwork += " password: \""+cryptedPsk+"\"\n"
842867
if (chkWifiSSIDHidden.checked) {
843-
cloudinitnetwork += " hidden: true\n"
868+
cloudinitnetwork += " hidden: true\n"
844869
}
845870

846871
addCmdline("cfg80211.ieee80211_regdom="+fieldWifiCountry.editText)

src/main.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ ApplicationWindow {
12261226
confirmwritepopup.askForConfirmation()
12271227
}
12281228
onNo: {
1229-
imageWriter.setImageCustomization("", "", "", "", "")
1229+
imageWriter.setImageCustomization("", "", "", "", "", false, false)
12301230
confirmwritepopup.askForConfirmation()
12311231
}
12321232
onNoClearSettings: {

0 commit comments

Comments
 (0)