mkinitcpio-dropbear/dropbear_install

97 lines
2.4 KiB
Text
Raw Normal View History

2024-05-09 11:02:17 +03:00
#!/bin/sh
2015-07-13 23:43:43 +03:00
get_fingerprint() {
2024-05-09 11:02:40 +03:00
keyfile="$1"
dropbearkey -y -f "${keyfile}" | sed -n '/^Fingerprint:/ {s/Fingerprint: *//; p}'
2015-07-13 23:43:43 +03:00
}
display_fingerprints() {
2024-05-09 11:02:40 +03:00
for keyfile in "/etc/dropbear/dropbear_rsa_host_key" "/etc/dropbear/dropbear_ecdsa_host_key"; do
if [ -s "${keyfile}" ]; then
echo "$(basename "${keyfile}") : $(get_fingerprint "${keyfile}")"
fi
done
2015-07-13 23:43:43 +03:00
}
copy_openssh_keys() {
2024-05-09 11:02:40 +03:00
osshrsa="/etc/ssh/ssh_host_rsa_key"
osshecdsa="/etc/ssh/ssh_host_ecdsa_key"
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
dbpre="/etc/dropbear/dropbear_"
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
return_code=1
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
if [ -s "$osshrsa" ]; then
dropbearconvert openssh dropbear $osshrsa ${dbpre}rsa_host_key
return_code=0
fi
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
if [ -s "$osshecdsa" ]; then
dropbearconvert openssh dropbear $osshecdsa ${dbpre}ecdsa_host_key
return_code=0
fi
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
return $return_code
2015-07-13 23:43:43 +03:00
}
generate_keys() {
2024-05-09 11:02:40 +03:00
for keytype in rsa ecdsa; do
keyfile="/etc/dropbear/dropbear_${keytype}_host_key"
if [ ! -s "$keyfile" ]; then
echo "Generating ${keytype} host key for dropbear ..."
dropbearkey -t "${keytype}" -f "${keyfile}"
fi
done
2015-07-13 23:43:43 +03:00
}
2024-05-09 11:02:40 +03:00
build() {
#
# Begin real processing
#
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
# Are we even needed?
if [ ! -r "/etc/dropbear/root_key" ] || [ ! -s "/etc/dropbear/root_key" ]; then
echo "There is no root key in /etc/dropbear/root_key existent; exit"
return 0
fi
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
# if TMPDIR is set leave it alone otherwise set
[ -z "$TMPDIR" ] && TMPDIR='/tmp/dropbear_initrd_encrypt'
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
# check if TMPDIR exsists if not make it
[ -d "$TMPDIR" ] || mkdir -p "$TMPDIR"
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
umask 0022
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
[ -d /etc/dropbear ] && mkdir -p /etc/dropbear
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
copy_openssh_keys || generate_keys
display_fingerprints
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
add_checked_modules "/drivers/net/"
add_binary "rm"
add_binary "killall"
add_binary "dropbear"
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
add_dir "/root/.ssh"
cat /etc/dropbear/root_key >"${BUILDROOT}"/root/.ssh/authorized_keys
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
add_full_dir "/etc/dropbear"
add_file "/lib/libnss_files.so.2"
add_dir "/var/run"
add_dir "/var/log"
touch "${BUILDROOT}"/var/log/lastlog
2015-07-13 23:43:43 +03:00
2024-05-09 11:02:40 +03:00
add_runscript
2015-07-13 23:43:43 +03:00
}
2024-05-09 11:02:40 +03:00
help() {
cat <<HELPEOF
2015-07-15 05:51:47 +03:00
This hook is meant to be used in conjunction with mkinitcpio-netconf and/or
mkinitcpio-ppp. It DOES NOT provide any default shell. It will only install
and start dropbear on early userspace. In the package mkinitcpio-utils you
2015-07-15 05:51:47 +03:00
will find hooks and shells for remote unlocking a luks root partition,
among others.
2015-07-13 23:43:43 +03:00
HELPEOF
}