commit: 74d7acd9ae1cf38725c1f31172e761eeadf857c9 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> AuthorDate: Sun Jul 14 18:11:34 2019 +0000 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> CommitDate: Sun Jul 14 18:11:34 2019 +0000 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=74d7acd9
Dropbear: Move --ssh-authorized-keys validation to determine_real_args() function It's a common error especially for new setups that '/etc/dropbear/authorized_keys' file will be missing. Moving the check to determine_real_args() will allow us to bail out very early for better user experience. Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> gen_determineargs.sh | 16 ++++++++++++++++ gen_initramfs.sh | 15 ++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/gen_determineargs.sh b/gen_determineargs.sh index a42cd44..1b3abf8 100755 --- a/gen_determineargs.sh +++ b/gen_determineargs.sh @@ -424,6 +424,22 @@ determine_real_args() { gen_die "--multipath requires --lvm but --no-lvm is set!" fi + if isTrue "${SSH}" + then + local ssh_authorized_keys_file=$(expand_file "${SSH_AUTHORIZED_KEYS_FILE}") + if [ -z "${ssh_authorized_keys_file}" ] + then + # expand_file() will return also return an empty string when file + # doesn't exist! + gen_die "--ssh-authorized-keys value '${SSH_AUTHORIZED_KEYS_FILE}' is invalid! Does the file exists?" + elif [ ! -s "${ssh_authorized_keys_file}" ] + then + gen_die "authorized_keys file '${ssh_authorized_keys_file}' is empty!" + else + declare -gr DROPBEAR_AUTHORIZED_KEYS_FILE="${ssh_authorized_keys_file}" + fi + fi + if isTrue "${ZFS}" && isTrue "$(tc-is-cross-compiler)" then local error_msg="Using binpkg for ZFS is not supported." diff --git a/gen_initramfs.sh b/gen_initramfs.sh index 41f0269..973ed9e 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -899,16 +899,9 @@ append_dropbear() { dropbear_command=dropbearconvert fi - local ssh_authorized_keys_file=$(expand_file "${SSH_AUTHORIZED_KEYS_FILE}") - if [ -z "${ssh_authorized_keys_file}" ] + if [ -z "${DROPBEAR_AUTHORIZED_KEYS_FILE}" ] then - gen_die "--ssh-authorized-keys value '${SSH_AUTHORIZED_KEYS_FILE}' is invalid!" - elif [ ! -f "${ssh_authorized_keys_file}" ] - then - gen_die "authorized_keys file '${ssh_authorized_keys_file}' does NOT exist!" - elif [ ! -s "${ssh_authorized_keys_file}" ] - then - gen_die "authorized_keys file '${ssh_authorized_keys_file}' is empty!" + gen_die "Something went wrong: DROPBEAR_AUTHORIZED_KEYS_FILE should already been set but is missing!" fi populate_binpkg ${PN} @@ -1122,8 +1115,8 @@ append_dropbear() { cp -a "${GK_SHARE}"/defaults/unlock-luks.sh "${TDIR}"/usr/sbin/unlock-luks \ || gen_die "Failed to copy '${GK_SHARE}/defaults/unlock-luks.sh' to '${TDIR}/usr/sbin/unlock-luks'" - cp -aL "${ssh_authorized_keys_file}" "${TDIR}"/root/.ssh/ \ - || gen_die "Failed to copy '${ssh_authorized_keys_file}'!" + cp -aL "${DROPBEAR_AUTHORIZED_KEYS_FILE}" "${TDIR}"/root/.ssh/ \ + || gen_die "Failed to copy '${DROPBEAR_AUTHORIZED_KEYS_FILE}'!" cp -aL /etc/localtime "${TDIR}"/etc/ \ || gen_die "Failed to copy '/etc/localtime'. Please set system's timezone!"