aports/main/openrc/firstboot.initd
Kit 299a1c1afb main/openrc: fix parsing quoted kernel options in firstboot
Quoted kernel options in /proc/cmdline look like this:

modules=something "ssh_key=ssh-rsa foobar user@foo" quiet

Without the eval this would be parsed as: opt='modules=something'
opt='"ssh_key=ssh-rsa' opt='foobar' opt='user@foo"' opt='quiet'

With the eval in this branch the options are parsed correctly.

Since ssh keys need spaces and therefor must be quoted, passing ssh_key
by kernel option cannot work as currently implemented.

fixes #9504
2020-05-29 10:02:33 +00:00

35 lines
715 B
Plaintext

#!/sbin/openrc-run
# The first boot init service
# read kernel options
init_KOPT() {
eval "set -- $(cat /proc/cmdline 2>/dev/null)"
for opt; do
case "$opt" in
ssh_*=*)
eval "KOPT_${opt%%=*}='${opt#*=}'" ;;
esac
done
}
start() {
rm -f /etc/runlevels/*/$RC_SVCNAME
init_KOPT
local rc=0
ebegin "Starting ${RC_SVCNAME}"
if [ -n "$KOPT_ssh_key" ] && [ ! -f "/root/.ssh/authorized_keys" ]; then
einfo "Fetching ssh keys"
mkdir -pm 700 /root/.ssh
case "$KOPT_ssh_key" in
https://*|ftps://*|http://*)
wget -q "$KOPT_ssh_key" -O /root/.ssh/authorized_keys
rc=$?;;
*) echo "$KOPT_ssh_key" > /root/.ssh/authorized_keys;;
esac
chmod 600 /root/.ssh/authorized_keys
fi
eend $rc
}