]> Pileus Git - mkinit/commitdiff
Add reload. master
authorAndy Spencer <andy753421@gmail.com>
Sat, 7 Nov 2020 11:01:23 +0000 (11:01 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 7 Nov 2020 11:01:23 +0000 (11:01 +0000)
src/mkinit

index 4b39890ce4bb3f6be0adac0eadc9e731b6888ef3..56be91c2129e2b3fce04f482a92803311a0a14ad 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/setsid /bin/bash
 
 # Copyright (C) 2009 Andy Spencer
 # See ../COPYING for terms
@@ -6,14 +6,15 @@
 # GLobals
 COMMAND=boot
 TESTING=false
+RELOAD=false
 if [ $$ == 1 ]; then
        DAEMON=true
 else
        DAEMON=false
 fi
 
-PATH=/lib/mkinit/bin:/bin:/sbin:/usr/bin:/usr/sbin
-export PATH
+export PLAN9=/opt/plan9
+export PATH=/lib/mkinit/bin:/bin:/sbin:/usr/bin:/usr/sbin
 
 # Functions 
 function usage {
@@ -23,6 +24,7 @@ function usage {
        echo '  -h,--help      Print usage information'
        echo '  -t,--test      Fake all commands'
        echo '  -d,--daemon    For spawning stdin listener'
+       echo '  -r,--reload    Reload mkinit'
        echo ''
        echo 'Command:'
        echo '  boot           Execute boot-up procedures'
@@ -37,7 +39,7 @@ function usage {
 
 # Handle arguments
 function doopts {
-       TMP=`getopt -n "$0" -o htd -l help,test,daemon -- "$@"`
+       TMP=`getopt -n "$0" -o htdr -l help,test,daemon,reload -- "$@"`
        [ $? != 0 ] &&
                usage
        eval set -- "$TMP"
@@ -48,6 +50,7 @@ function doopts {
                -h|--help )   usage ;;
                -t|--test )   TESTING=true ;;
                -d|--daemon ) DAEMON=true ;;
+               -r|--reload ) RELOAD=true ;;
                esac
                shift
        done
@@ -62,6 +65,7 @@ function doopts {
                echo '  TESTING:' $TESTING 1>&2
                echo '  DAEMON:'  $DAEMON  1>&2
                echo '  COMMAND:' $COMMAND 1>&2
+               echo '  RELOAD:'  $RELAOD  1>&2
        fi
 }
 
@@ -90,6 +94,7 @@ function process {
                if [ "$*" ]; then
                        runamk "$@"-stop ||
                                runamk "$@"-zap
+                       sleep 0.5
                        runamk "$@"-start
                fi
                ;;
@@ -119,16 +124,18 @@ function process {
 doopts "$@"
 
 # Run whatever was requested
-process "${COMMAND[@]}"
+if ! $RELOAD; then
+       process "${COMMAND[@]}"
+fi
 
 # Fork console listener
 while $DAEMON; do
+       $TESTING || exec 0</dev/tty1 1>/dev/tty1 2>&1
        while read -ep "mkinit> " line; do
                process $line
                history -s $line
        done
        $TESTING && exit
-       exec 0</dev/console 1>/dev/console 2>&1
-       echo "Respawning on /dev/console.."
+       echo "Respawning on /dev/tty1"
        sleep 1
 done