Skip to content

Commit

Permalink
Raspberry Pi OS cloud-init support
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <44974737+paulober@users.noreply.github.com>
  • Loading branch information
paulober committed Oct 16, 2024
1 parent 092e59e commit 495c803
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
64 changes: 46 additions & 18 deletions src/OptionsPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -712,21 +712,35 @@ Window {
addCloudInit("")
}

var isRpiosCloudInit = imageWriter.checkSWCapability("rpios_cloudinit");

if (chkSSH.checked || chkSetUser.checked) {
// First user may not be called 'pi' on all distributions, so look username up
addFirstRun("FIRSTUSER=`getent passwd 1000 | cut -d: -f1`");
addFirstRun("FIRSTUSERHOME=`getent passwd 1000 | cut -d: -f6`")

addCloudInit("users:")
addCloudInit("- name: "+fieldUserName.text)
addCloudInit(" groups: users,adm,dialout,audio,netdev,video,plugdev,cdrom,games,input,gpio,spi,i2c,render,sudo")
addCloudInit(" shell: /bin/bash")

var cryptedPassword;
if (chkSetUser.checked) {
cryptedPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text)
addCloudInit(" lock_passwd: false")
addCloudInit(" passwd: "+cryptedPassword)
}

if (isRpiosCloudInit && cryptedPassword) {
addCloudInit("rpi_userconf:")
addCloudInit(" password: " + cryptedPassword)
addCloudInit(" user: " + fieldUserName.text)
addCloudInit("")
}

addCloudInit("users:")
addCloudInit("- name: " + fieldUserName.text)
if (!isRpiosCloudInit) {
addCloudInit(" groups: users,adm,dialout,audio,netdev,video,plugdev,cdrom,games,input,gpio,spi,i2c,render,sudo")
addCloudInit(" shell: /bin/bash")

if (chkSetUser.checked) {
addCloudInit(" lock_passwd: false")
addCloudInit(" passwd: "+cryptedPassword)
}
}

if (chkSSH.checked && radioPubKeyAuthentication.checked) {
Expand Down Expand Up @@ -759,7 +773,12 @@ Window {
addCloudInit(" - "+pk)
}
}
addCloudInit(" sudo: ALL=(ALL) NOPASSWD:ALL")
if (!isRpiosCloudInit) {
addCloudInit(" sudo: ALL=(ALL) NOPASSWD:ALL")
} else {
addCloudInit("\nrpi_interfaces:")
addCloudInit(" ssh: true")
}
}
addCloudInit("")

Expand Down Expand Up @@ -795,6 +814,14 @@ Window {
addFirstRun("fi")
}
addCloudInit("")

/*if (chkSetUser.checked) {
addCloudInit("final_message: \"Setup wizard has been skiped.\"")
addCloudInit("power_state:")
addCloudInit(" mode: reboot")
addCloudInit(" message: Rebooting machine")
addCloudInit("")
}*/
}
if (chkWifi.checked) {
var wpaconfig = "country="+fieldWifiCountry.editText+"\n"
Expand Down Expand Up @@ -830,17 +857,18 @@ Window {
addFirstRun("fi")


cloudinitnetwork = "version: 2\n"
cloudinitnetwork += "wifis:\n"
cloudinitnetwork += " renderer: networkd\n"
cloudinitnetwork += " wlan0:\n"
cloudinitnetwork += " dhcp4: true\n"
cloudinitnetwork += " optional: true\n"
cloudinitnetwork += " access-points:\n"
cloudinitnetwork += " \""+fieldWifiSSID.text+"\":\n"
cloudinitnetwork += " password: \""+cryptedPsk+"\"\n"
cloudinitnetwork = "network:\n"
cloudinitnetwork += " version: 2\n"
cloudinitnetwork += " renderer: " + (isRpiosCloudInit ? "NetworkManager" : "networkd") + "\n"
cloudinitnetwork += " wifis:\n"
cloudinitnetwork += " wlan0:\n"
cloudinitnetwork += " dhcp4: true\n"
cloudinitnetwork += " optional: true\n"
cloudinitnetwork += " access-points:\n"
cloudinitnetwork += " \""+fieldWifiSSID.text+"\":\n"
cloudinitnetwork += " password: \""+cryptedPsk+"\"\n"
if (chkWifiSSIDHidden.checked) {
cloudinitnetwork += " hidden: true\n"
cloudinitnetwork += " hidden: true\n"
}

addCmdline("cfg80211.ieee80211_regdom="+fieldWifiCountry.editText)
Expand Down
2 changes: 1 addition & 1 deletion src/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ ApplicationWindow {
confirmwritepopup.askForConfirmation()
}
onNo: {
imageWriter.setImageCustomization("", "", "", "", "")
imageWriter.setImageCustomization("", "", "", "", "", false, false)
confirmwritepopup.askForConfirmation()
}
onNoClearSettings: {
Expand Down

0 comments on commit 495c803

Please sign in to comment.