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(" groups: users,adm,dialout,audio,netdev,video,plugdev,cdrom,games,input,gpio,spi,i2c,render,sudo")
addCloudInit(" shell: /bin/bash") addCloudInit(" shell: /bin/bash")
var cryptedPassword;
if (chkSetUser.checked) { if (chkSetUser.checked) {
var cryptedPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text) cryptedPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text)
addFirstRun("echo \"$FIRSTUSER:\""+escapeshellarg(cryptedPassword)+" | chpasswd -e")
addCloudInit(" lock_passwd: false") addCloudInit(" lock_passwd: false")
addCloudInit(" passwd: "+cryptedPassword) addCloudInit(" passwd: "+cryptedPassword)
} }
@ -654,20 +653,28 @@ Popup {
addCloudInit("ssh_pwauth: true") addCloudInit("ssh_pwauth: true")
} }
/* Rename first ("pi") user if a different desired username was specified */ if (chkSetUser.checked) {
addFirstRun("if [ \"$FIRSTUSER\" != \""+fieldUserName.text+"\" ]; then") /* Rename first ("pi") user if a different desired username was specified */
addFirstRun(" usermod -l \""+fieldUserName.text+"\" \"$FIRSTUSER\"") addFirstRun("if [ -f /usr/lib/userconf-pi/userconf ]; then")
addFirstRun(" usermod -m -d \"/home/"+fieldUserName.text+"\" \""+fieldUserName.text+"\"") addFirstRun(" /usr/lib/userconf-pi/userconf "+escapeshellarg(fieldUserName.text)+" "+escapeshellarg(cryptedPassword))
addFirstRun(" if grep -q \"^autologin-user=\" /etc/lightdm/lightdm.conf ; then") addFirstRun("else")
addFirstRun(" sed /etc/lightdm/lightdm.conf -i -e \"s/^autologin-user=.*/autologin-user="+fieldUserName.text+"/\"") addFirstRun(" echo \"$FIRSTUSER:\""+escapeshellarg(cryptedPassword)+" | chpasswd -e")
addFirstRun(" fi") addFirstRun(" if [ \"$FIRSTUSER\" != \""+fieldUserName.text+"\" ]; then")
addFirstRun(" if [ -f /etc/systemd/system/getty@tty1.service.d/autologin.conf ]; then") addFirstRun(" usermod -l \""+fieldUserName.text+"\" \"$FIRSTUSER\"")
addFirstRun(" sed /etc/systemd/system/getty@tty1.service.d/autologin.conf -i -e \"s/$FIRSTUSER/"+fieldUserName.text+"/\"") addFirstRun(" usermod -m -d \"/home/"+fieldUserName.text+"\" \""+fieldUserName.text+"\"")
addFirstRun(" fi") addFirstRun(" groupmod -n \""+fieldUserName.text+"\" \"$FIRSTUSER\"")
addFirstRun(" if [ -f /etc/sudoers.d/010_pi-nopasswd ]; then") addFirstRun(" if grep -q \"^autologin-user=\" /etc/lightdm/lightdm.conf ; then")
addFirstRun(" sed -i \"s/^$FIRSTUSER /"+fieldUserName.text+" /\" /etc/sudoers.d/010_pi-nopasswd") addFirstRun(" sed /etc/lightdm/lightdm.conf -i -e \"s/^autologin-user=.*/autologin-user="+fieldUserName.text+"/\"")
addFirstRun(" fi") addFirstRun(" fi")
addFirstRun("fi") addFirstRun(" if [ -f /etc/systemd/system/getty@tty1.service.d/autologin.conf ]; then")
addFirstRun(" sed /etc/systemd/system/getty@tty1.service.d/autologin.conf -i -e \"s/$FIRSTUSER/"+fieldUserName.text+"/\"")
addFirstRun(" fi")
addFirstRun(" if [ -f /etc/sudoers.d/010_pi-nopasswd ]; then")
addFirstRun(" sed -i \"s/^$FIRSTUSER /"+fieldUserName.text+" /\" /etc/sudoers.d/010_pi-nopasswd")
addFirstRun(" fi")
addFirstRun(" fi")
addFirstRun("fi")
}
if (chkSSH.checked) { if (chkSSH.checked) {
addFirstRun("systemctl enable ssh") addFirstRun("systemctl enable ssh")
@ -716,7 +723,7 @@ Popup {
addCloudInitRun("sed -i 's/^\s*REGDOMAIN=\S*/REGDOMAIN="+fieldWifiCountry.editText+"/' /etc/default/crda || true") addCloudInitRun("sed -i 's/^\s*REGDOMAIN=\S*/REGDOMAIN="+fieldWifiCountry.editText+"/' /etc/default/crda || true")
} }
if (chkLocale.checked) { if (chkLocale.checked) {
if (chkSkipFirstUse) { if (chkSkipFirstUse.checked) {
addFirstRun("rm -f /etc/xdg/autostart/piwiz.desktop") addFirstRun("rm -f /etc/xdg/autostart/piwiz.desktop")
addCloudInitRun("rm -f /etc/xdg/autostart/piwiz.desktop") addCloudInitRun("rm -f /etc/xdg/autostart/piwiz.desktop")
} }