Created
February 14, 2010 10:00
-
-
Save jetztgradnet/303934 to your computer and use it in GitHub Desktop.
osgic: Scriptable Equinox console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# osgic: Scriptable Equinox console | |
# see osgic -h for help | |
# connects by default to localhost:8023 | |
SCRIPTNAME=`basename $0` | |
PORT= | |
HOST= | |
BUNDLES= | |
CMD= | |
status=0 | |
packages=0 | |
bundleInfo=0 | |
diag=0 | |
console=0 | |
haveCommand=0 | |
options="hP:H:spbd" | |
function usage() { | |
echo "usage: $SCRIPTNAME -hspbd [-H <hostname>] [-P port] [command|args]" | |
echo "$SCRIPTNAME interactive console" | |
echo "$SCRIPTNAME -s show status" | |
echo "$SCRIPTNAME -d <bundle id|name> ... diagnose bundle resolution errors" | |
echo "$SCRIPTNAME -p [<bundle id|name> ...] show packages" | |
echo "$SCRIPTNAME -b [<bundle id|name> ...] show bundle info" | |
echo "options:" | |
echo "-P <port> console port" | |
echo "-H <host> console host name" | |
} | |
# parse options | |
while getopts $options OPT $@; do | |
case "$OPT" in | |
P) PORT=$OPTARG;; | |
H) HOST=$OPTARG;; | |
h) usage; exit 0;; | |
s) status=1; haveCommand=$((haveCommand+1));; | |
p) packages=1; haveCommand=$((haveCommand+1));; | |
b) bundleInfo=1; haveCommand=$((haveCommand+1));; | |
d) diag=1; haveCommand=$((haveCommand+1));; | |
# c) console=1; haveCommand=$((haveCommand+1));; | |
esac | |
done | |
optind=$OPTIND | |
unset OPTIND | |
if [ "$optind" -gt 0 ]; then | |
# remove options | |
shift $((optind - 1)) | |
fi | |
if [ "$haveCommand" -eq 0 ]; then | |
CMD=$@ | |
if [ -z "$CMD" ]; then | |
console=1 | |
fi | |
else | |
BUNDLES=$@ | |
fi | |
if [ -z "$PORT" ]; then | |
PORT=8023 | |
fi | |
if [ -z "$HOST" ]; then | |
HOST=localhost | |
fi | |
function execConsole() { | |
local disconnect="disconnect | |
y" | |
# parse options | |
while getopts "D" OPT $@; do | |
case "$OPT" in | |
D) disconnect=;; | |
esac | |
done | |
local optind=$OPTIND | |
unset OPTIND | |
if [ "$optind" -gt 0 ]; then | |
# remove options | |
shift $((optind - 1)) | |
fi | |
local cmd="$@" | |
if [ -n "$cmd" ]; then | |
nc $HOST $PORT <<EOF | |
$cmd | |
$disconnect | |
EOF | |
else | |
nc $HOST $PORT | |
fi | |
} | |
if [ $status -gt 0 ]; then | |
execConsole ss | |
fi | |
if [ $packages -gt 0 ]; then | |
execConsole packages $@ | |
fi | |
if [ $diag -gt 0 ]; then | |
for bundle in $BUNDLES; do | |
cmd="bundle $bundle | |
diag $bundle" | |
execConsole "$cmd" | |
done | |
fi | |
if [ -n "$CMD" ]; then | |
execConsole "$CMD" | |
fi | |
if [ $bundleInfo -gt 0 ]; then | |
for bundle in $BUNDLES; do | |
execConsole bundle $bundle | |
done | |
fi | |
echo "" | |
if [ $console -gt 0 ]; then | |
execConsole -D | |
#nc $HOST $PORT | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment