com.github.safrain.remotegsh.server.rgsh.txt Maven / Gradle / Ivy
The newest version!
#!/bin/sh
### Remote Groovy Shell bootstrap for UN*X ###
#To Modify default settings,edit these variables
DEFAULT_SERVER="{{server}}"
DEFAULT_CHARSET="{{charset}}"
server=$DEFAULT_SERVER
charset=$DEFAULT_CHARSET
usage () {
echo ""
echo "Remote Groovy Shell Client v${project.version}"
echo ""
echo "Usage: $0 [FILE] [OPTIONS]"
echo ""
echo "Options:"
echo " -s, --server Specify server url, '$DEFAULT_SERVER' as default."
echo " -c, --charset Specify request charset(make it same as server charset!), '$DEFAULT_REQUEST_CHARSET' as default."
echo ""
echo "Examples:"
echo " - Start remote groovy shell"
echo " ./rgsh"
echo ""
echo " - Start remote groovy shell at 'http://foobar.com/rgsh', request charset is 'utf-8'"
echo " ./rgsh foo.groovy -s http://foobar.com/rgsh -c utf-8"
echo ""
echo " - Upload script file and run"
echo " ./rgsh foobar.groovy"
echo ""
echo "* To change default server and charset settings,"
echo " just edit '$0'and modify DEFAULT_SERVER and DEFAULT_CHARSET variable."
echo ""
exit 1;
}
#Parse opts
ARGS=`getopt -o s:c:h -l server:,charset:,help -n "$0" -- "$@"`
if [ $? -ne 0 ];
then
usage;
fi
eval set -- "$ARGS";
while true; do
case "$1" in
-s|--server)
shift;
if [ -n "$1" ]; then
server=$1
shift;
fi
;;
-h|--help)
usage;
shift;
;;
-c|--charset)
shift;
if [ -n "$1" ]; then
charset=$1
shift;
fi
;;
--)
shift;
break;
;;
esac
done
if [ $# = 0 ];then
#Start shell
if [ -z $JAVA_HOME ];then
echo "JAVA_HOME not set, please set JAVA_HOME."
else
${JAVA_HOME}/bin/java -Dserver=$server -Dcharset=$charset -jar remote-gsh-shell-${project.version}.jar
fi
elif [ $# = 1 ];then
#Run script
curl -T $1 -X POST "$server" -s -S
else
usage;
fi