Advanced settings: rework username/password logic

- Also change group name.
- Outsource changes to /usr/lib/userconf-pi/userconf if present
This commit is contained in:
Floris Bos 2022-01-31 14:26:08 +01:00
parent 2f4fe2f35a
commit 34460f84b8

View file

@ -618,10 +618,9 @@ Popup {
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) {
var cryptedPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text)
addFirstRun("echo \"$FIRSTUSER:\""+escapeshellarg(cryptedPassword)+" | chpasswd -e")
cryptedPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text)
addCloudInit(" lock_passwd: false")
addCloudInit(" passwd: "+cryptedPassword)
}
@ -654,10 +653,16 @@ Popup {
addCloudInit("ssh_pwauth: true")
}
if (chkSetUser.checked) {
/* Rename first ("pi") user if a different desired username was specified */
addFirstRun("if [ -f /usr/lib/userconf-pi/userconf ]; then")
addFirstRun(" /usr/lib/userconf-pi/userconf "+escapeshellarg(fieldUserName.text)+" "+escapeshellarg(cryptedPassword))
addFirstRun("else")
addFirstRun(" echo \"$FIRSTUSER:\""+escapeshellarg(cryptedPassword)+" | chpasswd -e")
addFirstRun(" if [ \"$FIRSTUSER\" != \""+fieldUserName.text+"\" ]; then")
addFirstRun(" usermod -l \""+fieldUserName.text+"\" \"$FIRSTUSER\"")
addFirstRun(" usermod -m -d \"/home/"+fieldUserName.text+"\" \""+fieldUserName.text+"\"")
addFirstRun(" groupmod -n \""+fieldUserName.text+"\" \"$FIRSTUSER\"")
addFirstRun(" if grep -q \"^autologin-user=\" /etc/lightdm/lightdm.conf ; then")
addFirstRun(" sed /etc/lightdm/lightdm.conf -i -e \"s/^autologin-user=.*/autologin-user="+fieldUserName.text+"/\"")
addFirstRun(" fi")
@ -668,6 +673,8 @@ Popup {
addFirstRun(" sed -i \"s/^$FIRSTUSER /"+fieldUserName.text+" /\" /etc/sudoers.d/010_pi-nopasswd")
addFirstRun(" fi")
addFirstRun(" fi")
addFirstRun("fi")
}
if (chkSSH.checked) {
addFirstRun("systemctl enable ssh")
@ -716,7 +723,7 @@ Popup {
addCloudInitRun("sed -i 's/^\s*REGDOMAIN=\S*/REGDOMAIN="+fieldWifiCountry.editText+"/' /etc/default/crda || true")
}
if (chkLocale.checked) {
if (chkSkipFirstUse) {
if (chkSkipFirstUse.checked) {
addFirstRun("rm -f /etc/xdg/autostart/piwiz.desktop")
addCloudInitRun("rm -f /etc/xdg/autostart/piwiz.desktop")
}