aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-devtools/net-kexec/files/net-kexec.sh
blob: 44983d58620714fed5b8d5e75bde4793c9834ae8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
# Copyright (C) 2014 Romain Perier <romain.perier@gmail.com>
# Released under the MIT license (see COPYING.MIT for the terms)

GATEWAY=$(route | grep default | sed 's/ [ ]*/:/g' | cut -d ':' -f 2)

fail() {
    echo $1
    exit 1
}

# If we are not already connected, connect eth0 with DHCP
ifconfig eth0 | grep 'inet addr:[0-9]*\.[0-9]*\.[0-9]*\.[0-9]* ' >/dev/null
if [ $? -ne 0 ]; then
    echo "* Starting DHCP on eth0"
    udhcpc -n -i eth0 || fail "Unable to establish a DHCP session with eth0"
fi

tftp -g -r zImage $GATEWAY >/dev/null || fail "Unable to get zImage throught TFTP"
echo "* Found zImage on $TFTP_SERVER"
echo -n "Do you want to reboot to the new kernel on the fly ? [y/n] "
read boot

if [ "$boot" = "y" ]; then
    kexec -l zImage
    kexec -e
fi