AWS: Import SSH keys before meddling with the network

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Michael Tremer
2018-07-01 11:43:35 +01:00
parent 48a7737fdd
commit 2e42a9eaa1

View File

@@ -81,10 +81,27 @@ import_aws_configuration() {
echo "DOMAINNAME=${hostname#*.}" >> /var/ipfire/main/settings
fi
# Import SSH keys
local line
for line in $(get "public-keys/"); do
local key_no="${line%=*}"
local key="$(get public-keys/${key_no}/openssh-key)"
if [ -n "${key}" ] && ! grep -q "^${key}$" /root/.ssh/authorized_keys 2>/dev/null; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo "${key}" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
fi
done
# Import any DNS server settings
eval $(/usr/local/bin/readhash <(grep -E "^DNS([0-9])=" /var/ipfire/ethernet/settings 2>/dev/null))
# Import network configuration
# After this, no network connectivity will be available from this script due to the
# renaming of the network interfaces for which they have to be shut down
local config_type=1
: > /var/ipfire/ethernet/settings
@@ -193,21 +210,6 @@ import_aws_configuration() {
# Save CONFIG_TYPE
echo "CONFIG_TYPE=${config_type}" >> /var/ipfire/ethernet/settings
# Import SSH keys
local line
for line in $(get "public-keys/"); do
local key_no="${line%=*}"
local key="$(get public-keys/${key_no}/openssh-key)"
if [ -n "${key}" ] && ! grep -q "^${key}$" /root/.ssh/authorized_keys 2>/dev/null; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo "${key}" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
fi
done
# Actions performed only on the very first start
if [ ! -e "/var/ipfire/main/firstsetup_ok" ]; then
# Enable SSH