autodetect_email from .ssh/authorized_keys

This commit is contained in:
pvincent
2024-02-29 22:39:26 +04:00
parent 4fbae210ce
commit c41d2af86b
2 changed files with 23 additions and 17 deletions
+22 -16
View File
@@ -226,7 +226,6 @@ function check_credential {
check_yaml_defined_value /etc/miaou/defaults.yaml 'credential.username' && check_yaml_defined_value /etc/miaou/defaults.yaml 'credential.username' &&
check_yaml_defined_value /etc/miaou/defaults.yaml 'credential.shadow' && check_yaml_defined_value /etc/miaou/defaults.yaml 'credential.shadow' &&
check_yaml_defined_value /etc/miaou/defaults.yaml 'credential.email' check_yaml_defined_value /etc/miaou/defaults.yaml 'credential.email'
} }
function check_target() { function check_target() {
@@ -260,7 +259,7 @@ function miaou_configfiles() {
if [[ ! -f /etc/miaou/defaults.yaml ]]; then if [[ ! -f /etc/miaou/defaults.yaml ]]; then
echo -n "building /etc/miaou/defaults.yaml for the first time..." echo -n "building /etc/miaou/defaults.yaml for the first time..."
shadow_passwd=$(sudo grep "$CURRENT_USER" /etc/shadow | cut -d ':' -f2) shadow_passwd=$(sudo grep "$CURRENT_USER" /etc/shadow | cut -d ':' -f2)
env current_user="$CURRENT_USER" shadow_passwd="$shadow_passwd" tera -e --env-key env --env-only -t "$MIAOU_BASEDIR/templates/etc/defaults.yaml.j2" -o /etc/miaou/defaults.yaml >/dev/null env current_user="$CURRENT_USER" shadow_passwd="$shadow_passwd" valid_email="$valid_email" tera -e --env-key env --env-only -t "$MIAOU_BASEDIR/templates/etc/defaults.yaml.j2" -o /etc/miaou/defaults.yaml >/dev/null
yq ".target=\"$TARGET\"" /etc/miaou/defaults.yaml -i yq ".target=\"$TARGET\"" /etc/miaou/defaults.yaml -i
PREFIX="" echoinfo OK PREFIX="" echoinfo OK
fi fi
@@ -339,8 +338,7 @@ EOF
} }
function extra_dev_desktop { function extra_dev_desktop {
# detect if DEV # FIXME: detect if DEV && DESKTOP_USAGE to install spicy-client and other desktop tools
# detect if DESKTOP
: :
} }
@@ -363,15 +361,13 @@ EOF
fi fi
} }
function ask_for_credential { function ask_for_email {
local PREFIX="ask:credential" local PREFIX="install:ask_for_email"
if ! check_credential 2>/dev/null; then valid_email=$(auto_detect_email)
echo "further details required, please replace any <TO BE DEFINED> by a proper value ...press any key to open editor" while ! is_email_valid "$valid_email"; do
read -rn1 echo -n "mandatory email: "
editor /etc/miaou/defaults.yaml read -rei "$valid_email" valid_email
fi done
check_credential
echo "successfully checked!"
} }
function preload_bookworm_image { function preload_bookworm_image {
@@ -393,7 +389,15 @@ function is_email_valid {
} }
function auto_detect_email { function auto_detect_email {
: found_email=""
if [[ -f $HOME/.ssh/authorized_keys ]]; then
while IFS= read -r line; do
found_email="$line"
is_email_valid "$found_email" && break
done < <(cut -d ' ' -f3 <"$HOME/.ssh/authorized_keys")
fi
builtin echo "$found_email"
} }
### MAIN ### MAIN
@@ -423,8 +427,11 @@ else
TARGET=${1:-} TARGET=${1:-}
CURRENT_USER=$(id -un) CURRENT_USER=$(id -un)
sudo_required check_normal_user
check_target check_target
ask_for_email
sudo_required
install_miaou_bash install_miaou_bash
install_mandatory_commands install_mandatory_commands
prepare_toolbox prepare_toolbox
@@ -435,7 +442,6 @@ else
miaou_resolver miaou_resolver
miaou_evalfrombashrc miaou_evalfrombashrc
miaou_configfiles miaou_configfiles
ask_for_credential
opt_link opt_link
extra_dev_desktop extra_dev_desktop
+1 -1
View File
@@ -5,4 +5,4 @@ containers:
credential: credential:
username: {{env.current_user}} username: {{env.current_user}}
shadow: {{env.shadow_passwd}} shadow: {{env.shadow_passwd}}
email: TO BE DEFINED # example user@domain.tld email: {{env.valid_email}}