From 71c89c99fa1c66765c4d478fb9cffdf2503ab53d Mon Sep 17 00:00:00 2001 From: Anup Navare Date: Wed, 15 Mar 2017 00:19:36 +0000 Subject: [PATCH] Rescue extension for TinyIPA with DHCP network The patch adds the support for rescue mode with DHCP network in TinyIPA. Change-Id: I10cdb47eb3815db097bb3088d9dd4804b9d6a5d0 Depends-On: I9b4c1278dc5fab7888fbfe586c15e31ed3958978 Partial-Bug: #1526449 --- imagebuild/tinyipa/build_files/bootlocal.sh | 37 +++++++++++++++++ imagebuild/tinyipa/finalise-tinyipa.sh | 3 ++ imagebuild/tinyipa/udhcpc.script | 44 +++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 imagebuild/tinyipa/udhcpc.script diff --git a/imagebuild/tinyipa/build_files/bootlocal.sh b/imagebuild/tinyipa/build_files/bootlocal.sh index dbc03ed0f..a94a67d50 100755 --- a/imagebuild/tinyipa/build_files/bootlocal.sh +++ b/imagebuild/tinyipa/build_files/bootlocal.sh @@ -23,9 +23,46 @@ if ! type "ironic-python-agent" > /dev/null ; then python /tmp/get-pip.py --no-wheel --no-index --find-links=file:///tmp/wheelhouse ironic_python_agent fi +# Create ipa-rescue-config directory for rescue password +sudo mkdir -p /etc/ipa-rescue-config + export PYTHONOPTIMIZE=1 # Run IPA echo "Starting Ironic Python Agent:" date ironic-python-agent 2>&1 | tee /var/log/ironic-python-agent.log + + +create_rescue_user() { + crypted_pass=$(cat /etc/ipa-rescue-config/ipa-rescue-password) + sudo adduser rescue -D -G root # no useradd + echo "rescue:$crypted_pass" | sudo chpasswd -e + sudo sh -c "echo \"rescue ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers" # no suooers.d in tiny core. + + # Restart sshd with allowing password authentication + sudo sed -i -e 's/^PasswordAuthentication no/PasswordAuthentication yes/' /usr/local/etc/ssh/sshd_config + sudo /usr/local/etc/init.d/openssh restart +} + +# Setup DHCP network +configure_dhcp_network() { + for pidfile in `ls /var/run/udhcpc/*.pid`; do + kill `cat $pidfile` + done + + # NOTE(TheJulia): We may need to add a short wait here as + # network interface plugging actions may not be asynchronous. + INTERFACES=$(ip -o link |grep "LOWER_UP"|cut -f2 -d" "|sed 's/://'|grep -v "lo") + for interface in $INTERFACES; do + pidfile="/var/run/udhcpc/${interface}.pid" + /sbin/udhcpc -b -p ${pidfile} -i ${interface} -s /opt/udhcpc.script >> /var/log/udhcpc.log 2>&1 + done +} + +if [ -f /etc/ipa-rescue-config/ipa-rescue-password ]; then + create_rescue_user || exit 0 + configure_dhcp_network || exit 0 +else + echo "IPA has exited. No rescue password file was defined." +fi diff --git a/imagebuild/tinyipa/finalise-tinyipa.sh b/imagebuild/tinyipa/finalise-tinyipa.sh index 2ff2d6f57..3a1a115d1 100755 --- a/imagebuild/tinyipa/finalise-tinyipa.sh +++ b/imagebuild/tinyipa/finalise-tinyipa.sh @@ -141,6 +141,9 @@ cleanup_tce "$DST_DIR" # Copy bootlocal.sh to opt sudo cp "$WORKDIR/build_files/bootlocal.sh" "$FINALDIR/opt/." +# Copy udhcpc.script to opt +sudo cp "$WORKDIR/udhcpc.script" "$FINALDIR/opt/" + # Disable ZSwap sudo sed -i '/# Main/a NOZSWAP=1' "$FINALDIR/etc/init.d/tc-config" # sudo cp $WORKDIR/build_files/tc-config $FINALDIR/etc/init.d/tc-config diff --git a/imagebuild/tinyipa/udhcpc.script b/imagebuild/tinyipa/udhcpc.script new file mode 100644 index 000000000..1de671ba3 --- /dev/null +++ b/imagebuild/tinyipa/udhcpc.script @@ -0,0 +1,44 @@ +#!/bin/sh + +# udhcpc script edited by Tim Riker + +# file created to be used for static network configuration as well + +[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1 + +RESOLV_CONF="/etc/resolv.conf" +[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" +[ -n "$subnet" ] && NETMASK="netmask $subnet" + +case "$1" in + deconfig) + /sbin/ifconfig $interface 0.0.0.0 + ;; + + renew|bound) + /sbin/ifconfig $interface up + /sbin/ifconfig $interface $ip $BROADCAST $NETMASK + + if [ -n "$router" ] ; then + echo "deleting routers" + while route del default gw 0.0.0.0 dev $interface ; do + : + done + + metric=0 + for i in $router ; do + route add default gw $i dev $interface metric $((metric++)) + done + fi + + echo -n > $RESOLV_CONF + [ -n "$domain" ] && echo search $domain >> $RESOLV_CONF + for i in $dns ; do + echo adding dns $i + echo nameserver $i >> $RESOLV_CONF + done + ;; +esac + +exit 0 +