diff options
Diffstat (limited to 'launch')
-rwxr-xr-x | launch/launch | 92 |
1 files changed, 44 insertions, 48 deletions
diff --git a/launch/launch b/launch/launch index b4c1c7a..b8757e6 100755 --- a/launch/launch +++ b/launch/launch @@ -7,8 +7,8 @@ Usage: $(me): [-gh] [COMMAND] [COMMAND ARGS]... Args: - -g: Force generate cache - -h: show this help message + -g, --gen-cache : Force generate cache + -h, --help : show this help message Config Syntax: +host [HOSTNAME] @@ -22,51 +22,51 @@ HELPDOC gencache() { awk ' - BEGIN { - print "run=\"$1\"; shift" - print "case \"$run\" in" - } - { - sub(/#.*/, "") # Remove comments - if (!/^\s*$/) { - if (/^\+host/) { - sub(/\s*\+host\s*/, "") - h++ - hosts[h] = $0 +BEGIN { + print "run=\"$1\"; shift" + print "case \"$run\" in" +} +{ + sub(/#.*/, "") # Remove comments + if (!/^\s*$/) { + if (/^\+host/) { + sub(/\s*\+host\s*/, "") + h++ + hosts[h] = $0 + } + else { + if (!/^\t/) { + hostnum = 1 + o++ + opts[o] = $0 } else { - if (!/^\t/) { - hostnum = 1 - o++ - opts[o] = $0 - } - else { - sub(/^\t/, "") - if ($0 == "^") - $0 = cache - else if ($0 ~ /^[0-9]*$/) - $0 = cmds[hosts[$0]":"opts[o]] - cmds[hosts[hostnum]":"opts[o]] = cache = $0 - hostnum++ - } + sub(/^\t/, "") + if ($0 == "^") + $0 = cache + else if ($0 ~ /^[0-9]*$/) + $0 = cmds[hosts[$0]":"opts[o]] + cmds[hosts[hostnum]":"opts[o]] = cache = $0 + hostnum++ } } } - END { - for (host in hosts) { - if (hosts[host] != "'`hostname`'") - continue - for (cmd in cmds) { - if (cmd ~ hosts[host] && cmds[cmd] && cmds[cmd] != "-") { - i = cmd - sub(/.*:/, "", cmd) - print "\t"cmd") "cmds[i]" \"$@\" & ;;" - } +} +END { + for (host in hosts) { + if (hosts[host] != "'`hostname`'") + continue + for (cmd in cmds) { + if (cmd ~ hosts[host] && cmds[cmd] && cmds[cmd] != "-") { + i = cmd + sub(/.*:/, "", cmd) + print "\t"cmd") "cmds[i]" \"$@\" & ;;" } - print "\t*) command -v \"$run\" >/dev/null && exec \"$run\" \"$@\" || echo \"\\`$run${@:+ $@}\\` Does not exist or exited with an error\" ;;" - print "esac" } + print "\t*) command -v \"$run\" >/dev/null && exec \"$run\" \"$@\" || echo \"\\`$run${@:+ $@}\\` Does not exist or exited with an error\" ;;" + print "esac" } +} ' $conf > $cache chmod +x $cache } @@ -77,10 +77,9 @@ conf=$confdir/config if [ ! -e $conf ]; then mkdir -p $confdir echo "#HOSTS\n+host $(hostname)\n\n#OPTS\ntest\n\techo \"Tested!\"" > $conf - echo "Config file created at $conf! Exiting" - echo + echo "No config file exists! new config file created at $conf! Exiting\n" printhelp - exit 0 + exit 1 fi # Cache file setup @@ -91,10 +90,7 @@ cache=$cachedir/cache # Command line options case "$1" in - -g) echo "Generating new cache: $cache"; gencache && cat $cache; exit ;; - -h) printhelp && exit ;; - '') printhelp && exit ;; + -g|--gen-cache) echo "Generating new cache: $cache"; gencache && cat $cache ;; + -h|--help|'') printhelp ;; + *) exec $cache "$@" ;; # Run esac - -# Run -exec $cache "$@" |