mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-18 16:05:21 +01:00
Advanced options: allow username and password to be set without ssh
- Allow username and password to be set separate to SSH. Does enforce password to be changed if SSH is enabled without public key authentication. - cloud-init: apt: disable date/time checks
This commit is contained in:
parent
ba5a27d154
commit
83513733ef
1 changed files with 81 additions and 59 deletions
140
OptionsPopup.qml
140
OptionsPopup.qml
|
@ -153,71 +153,18 @@ Popup {
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
enabled: chkSSH.checked
|
enabled: chkSSH.checked
|
||||||
Layout.leftMargin: 40
|
Layout.leftMargin: 40
|
||||||
spacing: -5
|
spacing: -10
|
||||||
|
|
||||||
GridLayout {
|
|
||||||
columns: 2
|
|
||||||
columnSpacing: 10
|
|
||||||
rowSpacing: -5
|
|
||||||
|
|
||||||
Text {
|
|
||||||
text: qsTr("Set username:")
|
|
||||||
color: parent.enabled ? (fieldUserName.indicateError ? "red" : "black") : "grey"
|
|
||||||
}
|
|
||||||
TextField {
|
|
||||||
id: fieldUserName
|
|
||||||
text: "pi"
|
|
||||||
Layout.minimumWidth: 200
|
|
||||||
property bool indicateError: false
|
|
||||||
|
|
||||||
onTextEdited: {
|
|
||||||
indicateError = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RadioButton {
|
RadioButton {
|
||||||
id: radioPasswordAuthentication
|
id: radioPasswordAuthentication
|
||||||
text: qsTr("Use password authentication")
|
text: qsTr("Use password authentication")
|
||||||
onCheckedChanged: {
|
onCheckedChanged: {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
|
chkSetUser.checked = true
|
||||||
fieldUserPassword.forceActiveFocus()
|
fieldUserPassword.forceActiveFocus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GridLayout {
|
|
||||||
Layout.leftMargin: 40
|
|
||||||
columns: 2
|
|
||||||
columnSpacing: 10
|
|
||||||
rowSpacing: -5
|
|
||||||
enabled: radioPasswordAuthentication.checked
|
|
||||||
|
|
||||||
Text {
|
|
||||||
text: qsTr("Set password for '%1' user:").arg(fieldUserName.text)
|
|
||||||
color: parent.enabled ? (fieldUserPassword.indicateError ? "red" : "black") : "grey"
|
|
||||||
}
|
|
||||||
TextField {
|
|
||||||
id: fieldUserPassword
|
|
||||||
echoMode: TextInput.Password
|
|
||||||
Layout.minimumWidth: 200
|
|
||||||
property bool alreadyCrypted: false
|
|
||||||
property bool indicateError: false
|
|
||||||
|
|
||||||
onTextEdited: {
|
|
||||||
if (alreadyCrypted) {
|
|
||||||
/* User is trying to edit saved
|
|
||||||
(crypted) password, clear field */
|
|
||||||
alreadyCrypted = false
|
|
||||||
clear()
|
|
||||||
}
|
|
||||||
if (indicateError) {
|
|
||||||
indicateError = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RadioButton {
|
RadioButton {
|
||||||
id: radioPubKeyAuthentication
|
id: radioPubKeyAuthentication
|
||||||
text: qsTr("Allow public-key authentication only")
|
text: qsTr("Allow public-key authentication only")
|
||||||
|
@ -245,6 +192,67 @@ Popup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckBox {
|
||||||
|
id: chkSetUser
|
||||||
|
text: qsTr("Set username and password")
|
||||||
|
onCheckedChanged: {
|
||||||
|
if (!checked && chkSSH.checked && radioPasswordAuthentication.checked) {
|
||||||
|
checked = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
enabled: chkSetUser.checked
|
||||||
|
Layout.leftMargin: 40
|
||||||
|
spacing: -5
|
||||||
|
|
||||||
|
GridLayout {
|
||||||
|
columns: 2
|
||||||
|
columnSpacing: 10
|
||||||
|
rowSpacing: -5
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: qsTr("Username:")
|
||||||
|
color: parent.enabled ? (fieldUserName.indicateError ? "red" : "black") : "grey"
|
||||||
|
}
|
||||||
|
TextField {
|
||||||
|
id: fieldUserName
|
||||||
|
text: "pi"
|
||||||
|
Layout.minimumWidth: 200
|
||||||
|
property bool indicateError: false
|
||||||
|
|
||||||
|
onTextEdited: {
|
||||||
|
indicateError = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: qsTr("Password:")
|
||||||
|
color: parent.enabled ? (fieldUserPassword.indicateError ? "red" : "black") : "grey"
|
||||||
|
}
|
||||||
|
TextField {
|
||||||
|
id: fieldUserPassword
|
||||||
|
echoMode: TextInput.Password
|
||||||
|
Layout.minimumWidth: 200
|
||||||
|
property bool alreadyCrypted: false
|
||||||
|
property bool indicateError: false
|
||||||
|
|
||||||
|
onTextEdited: {
|
||||||
|
if (alreadyCrypted) {
|
||||||
|
/* User is trying to edit saved
|
||||||
|
(crypted) password, clear field */
|
||||||
|
alreadyCrypted = false
|
||||||
|
clear()
|
||||||
|
}
|
||||||
|
if (indicateError) {
|
||||||
|
indicateError = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CheckBox {
|
CheckBox {
|
||||||
id: chkWifi
|
id: chkWifi
|
||||||
text: qsTr("Configure wifi")
|
text: qsTr("Configure wifi")
|
||||||
|
@ -457,9 +465,11 @@ Popup {
|
||||||
fieldUserPassword.alreadyCrypted = true
|
fieldUserPassword.alreadyCrypted = true
|
||||||
chkSSH.checked = true
|
chkSSH.checked = true
|
||||||
radioPasswordAuthentication.checked = true
|
radioPasswordAuthentication.checked = true
|
||||||
|
chkSetUser.checked = true
|
||||||
}
|
}
|
||||||
if ('sshUserName' in settings) {
|
if ('sshUserName' in settings) {
|
||||||
fieldUserName.text = settings.sshUserName
|
fieldUserName.text = settings.sshUserName
|
||||||
|
chkSetUser.checked = true
|
||||||
}
|
}
|
||||||
if ('sshAuthorizedKeys' in settings) {
|
if ('sshAuthorizedKeys' in settings) {
|
||||||
fieldPublicKey.text = settings.sshAuthorizedKeys
|
fieldPublicKey.text = settings.sshAuthorizedKeys
|
||||||
|
@ -589,9 +599,16 @@ Popup {
|
||||||
addCloudInit("manage_etc_hosts: true")
|
addCloudInit("manage_etc_hosts: true")
|
||||||
addCloudInit("packages:")
|
addCloudInit("packages:")
|
||||||
addCloudInit("- avahi-daemon")
|
addCloudInit("- avahi-daemon")
|
||||||
|
/* Disable date/time checks in apt as NTP may not have synchronized yet when installing packages */
|
||||||
|
addCloudInit("apt:")
|
||||||
|
addCloudInit(" conf: |")
|
||||||
|
addCloudInit(" Acquire {")
|
||||||
|
addCloudInit(" Check-Date \"false\";")
|
||||||
|
addCloudInit(" };")
|
||||||
addCloudInit("")
|
addCloudInit("")
|
||||||
}
|
}
|
||||||
if (chkSSH.checked) {
|
|
||||||
|
if (chkSSH.checked || chkSetUser.checked) {
|
||||||
// First user may not be called 'pi' on all distributions, so look username up
|
// First user may not be called 'pi' on all distributions, so look username up
|
||||||
addFirstRun("FIRSTUSER=`getent passwd 1000 | cut -d: -f1`");
|
addFirstRun("FIRSTUSER=`getent passwd 1000 | cut -d: -f1`");
|
||||||
addFirstRun("FIRSTUSERHOME=`getent passwd 1000 | cut -d: -f6`")
|
addFirstRun("FIRSTUSERHOME=`getent passwd 1000 | cut -d: -f6`")
|
||||||
|
@ -601,16 +618,19 @@ 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")
|
||||||
|
|
||||||
if (radioPasswordAuthentication.checked) {
|
if (chkSetUser.checked) {
|
||||||
var cryptedPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text)
|
var cryptedPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text)
|
||||||
addFirstRun("echo \"$FIRSTUSER:\""+escapeshellarg(cryptedPassword)+" | chpasswd -e")
|
addFirstRun("echo \"$FIRSTUSER:\""+escapeshellarg(cryptedPassword)+" | chpasswd -e")
|
||||||
|
|
||||||
addCloudInit(" lock_passwd: false")
|
addCloudInit(" lock_passwd: false")
|
||||||
addCloudInit(" passwd: "+cryptedPassword)
|
addCloudInit(" passwd: "+cryptedPassword)
|
||||||
addCloudInit("")
|
addCloudInit("")
|
||||||
|
}
|
||||||
|
if (chkSSH.checked && radioPasswordAuthentication.checked) {
|
||||||
addCloudInit("ssh_pwauth: true")
|
addCloudInit("ssh_pwauth: true")
|
||||||
}
|
}
|
||||||
if (radioPubKeyAuthentication.checked) {
|
|
||||||
|
if (chkSSH.checked && radioPubKeyAuthentication.checked) {
|
||||||
var pubkey = fieldPublicKey.text
|
var pubkey = fieldPublicKey.text
|
||||||
var pubkeyArr = pubkey.split("\n")
|
var pubkeyArr = pubkey.split("\n")
|
||||||
|
|
||||||
|
@ -646,7 +666,9 @@ Popup {
|
||||||
addFirstRun(" fi")
|
addFirstRun(" fi")
|
||||||
addFirstRun("fi")
|
addFirstRun("fi")
|
||||||
|
|
||||||
addFirstRun("systemctl enable ssh")
|
if (chkSSH.checked) {
|
||||||
|
addFirstRun("systemctl enable ssh")
|
||||||
|
}
|
||||||
addCloudInit("")
|
addCloudInit("")
|
||||||
}
|
}
|
||||||
if (chkWifi.checked) {
|
if (chkWifi.checked) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue