lfs-execline-scripts

Repository for execline scripts used in my linux-from-scratch builds
Log | Files | Refs

bare.sh (1340B)


      1 #!/usr/bin/execlineb -S1
      2 # do execlineb -WS1 for testing (errors out on bad syntax)
      3 # this was an attempt to define SERVICE as the same as argv[0] but didn't work for some reason
      4 #foreground {
      5 #  if { eltest "$#" = 0 } 
      6 #        define SERVICE ${0}
      7 #        #shift -n 1
      8 #}
      9 # we may need to change this bc said file may ned to run some code
     10 # we can put maybe EXTSCRIPTS=1 in said config if it needs to run an external script, which we can
     11 # then check for and tghen run said script
     12 foreground {
     13   if { eltest -e "/etc/svc.d/default/${0}" }
     14     { envfile { "/etc/svc.d/default/${0}" } }
     15 }
     16 
     17 define bins ""
     18 
     19 # loop thru std $PATH
     20 forx i { "/bin" "/sbin" "/usr/bin" "/usr/sbin" "/usr/local/bin" "/usr/local/sbin" }
     21   #importas -S PATH
     22   #if ex: /bin/$0 is executable
     23   if { eltest -x "${i}/${0}" }
     24     {
     25       # set bins to path of executable
     26       define bins ${i}/${0}
     27     }
     28   #exit 1111 # exit forx loop
     29 
     30 foreground {
     31   if { eltest -v bins } 
     32     exit 1
     33 } # foregroudn wrapper
     34 
     35 # set PID to pid of running process (may (not) exist)
     36 backtick PID { pidof -o %PPID $bins }
     37 
     38 case -N -- $1
     39   {
     40     "-s" { if { eltest -v PID } exec $bins $PARAMS } # if $PID is empty, run $bins $PARAMS
     41     "-k" { if { eltest ! -v PID } kill -9 $PID } # if $PID isn't empty, run kill -9 $PID &>/dev/null
     42   } foreground { /bin/printf "usage: %s -s|-k\n" $0 } exit 1