From c6af909787ba0256b9f09903d9274acf0cd6aeaf Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 22 Oct 2017 20:14:16 +0200 Subject: ^C abort in tmux. More polishing. --- make-boot-image.sh | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'make-boot-image.sh') diff --git a/make-boot-image.sh b/make-boot-image.sh index 17baf51..93a2d1d 100755 --- a/make-boot-image.sh +++ b/make-boot-image.sh @@ -1,6 +1,6 @@ #!/bin/bash -xe PS4='+ ($LINENO) ' # To ease debugging -VERSION="1.0" +VERSION="1.0rc1" # Config # ########## @@ -387,7 +387,7 @@ machine_info() { } network_conf() { - killall udhcpc # Reap background udhcpc in case of rc2 retry + pidof udhcpc >/dev/null && killall udhcpc # Reap background udhcpc in case of rc2 retry ip -oneline link | grep LOWER_UP | cut -d: -f2 | grep -v sit | grep -v lo | while read iface do udhcpc -b $iface -t 15 @@ -426,6 +426,7 @@ autorun() { rm /run/autorun_res else res=1 fi + echo_color green black "tmux-main-pane exit code : $res" return $res } @@ -554,8 +555,22 @@ fi EOF add_initrd_script "/etc/rc.d/tmux-main-pane" <<"EOF" # Drop a in-tmux rescue shell in case of failure, prevents clearing screen with valuable informations -trap 'res=$?; echo $res > /run/autorun_res ; [ "$res" -eq 0 ] || rescue_shell; tmux kill-server' EXIT . /etc/rc.d/funcs # Load helper functions +# Helper to trap user interruption and error cases +# Will exit the entire tmux, leaving last error code availble in a file +cleanup() { + res=$? + echo $res > /run/autorun_res + if [ $res -ne 0 ] + then rm /run/rescue + echo_color green black "/etc/rc.d/tmux-main-pane is exiting. Spawn rescue_shell in tmux now" + rescue_shell + fi + tmux kill-server + exit +} +trap cleanup INT TERM + case $1 in initrd) echo -ne "\e]2;initrd-autorun.sh\007" # Term title (tmux) message initrd autorun @@ -564,23 +579,26 @@ case $1 in nfs) source nfs-mount if [ $? -ne 0 ] then echo_color white red "----- NFS server : not mounted ------" - echo_color green black "Check for failure above. Exiting rescue shell twice will retry mount" - return 1 + echo_color green black "Check for failure above. Exiting rescue shell will retry everything" + false; cleanup fi if ! [ -x /mnt/nfs/nfs-autorun.sh ] then echo_color white red "----- NFS server : missing script ------" echo_color green black "Check nfs-autorun.sh : should be present, readable and executable" ls -l /mnt/nfs - return 2 + false; cleanup fi echo_color white green "----- NFS server ready ------" message nfs autorun echo -ne "\e]2;nfs-autorun.sh\007" # Term title (tmux) - cd /mnt/nfs && source ./nfs-autorun.sh + cd /mnt/nfs + source ./nfs-autorun.sh ;; *) echo "Usage : $0 (nfs|initrd)" - return 1 ;; + false; cleanup ;; esac +# Don't add code here, $? from source ...-autorun.sh is used in cleanup +cleanup EOF add_initrd_script "/bin/nfs-mount" <<"EOF" echo -ne "\e]2;$0\007" # Term title (tmux) -- cgit v1.2.3