source: iovar-bash/iosh

Last change on this file was 0:15ffd1df08ea, checked in by Shawn Wilson <shawn@…>, 18 months ago

saw_031117_1 - Initial commit for iovar-bash.

  • Property exe set to *
File size: 2.0 KB
Line 
1#!/bin/bash
2#
3# Copyright (C) 2016-2017 Virgo Venture, Inc.
4# @%@~LICENSE~@%@
5
6# location of the IOVAR shell we are connecting to:
7IOSH='http://localhost:8080/$/bin/sh'
8
9script=$1
10
11test "$script" = '' && {
12
13    #echo entering interactive mode...
14
15    echo "+++ iovar: $IOSH"
16    echo -n "+++ version: "
17    cmd=$(echo -ne 'echo $IOVAR_VERSION' | hexdump -v -e '/1 "%02x"' | sed 's/\(..\)/%\1/g')
18    curl --cookie $HOME/.iosh-cookies --cookie-jar $HOME/.iosh-cookies "$IOSH?cmd=$cmd"
19
20    echo "+++ setting VIEW=text"
21    cmd=$(echo -ne 'export VIEW=text' | hexdump -v -e '/1 "%02x"' | sed 's/\(..\)/%\1/g')
22    curl --cookie $HOME/.iosh-cookies --cookie-jar $HOME/.iosh-cookies "$IOSH?cmd=$cmd"
23
24    # formatting: http://misc.flogisoft.com/bash/tip_colors_and_formatting
25    prompt='\x1B[38;5;154m\x1B[1miosh $\x1B[0m\x1B[38;5;51m '
26
27    echo -n -e "$prompt"
28    while read line
29    do
30        #echo $line
31
32        test "$line" = 'exit' && exit 0
33
34        test "$line" = '' || {
35
36            # url-encode the command line
37            # solution from: http://stackoverflow.com/questions/296536/how-to-urlencode-data-for-curl-command
38            cmd=$(echo -ne "$line" | hexdump -v -e '/1 "%02x"' | sed 's/\(..\)/%\1/g')
39
40            #echo -n -e '\x1B[1m\x1B[97m' # bold white
41            echo -n -e '\x1B[97m' # white
42            curl --cookie $HOME/.iosh-cookies --cookie-jar $HOME/.iosh-cookies "$IOSH?cmd=$cmd"
43            #echo -n -e '\x1B[0m' # normal
44        }
45
46        echo -n -e "$prompt"
47
48    done < /dev/stdin
49
50    exit 0
51   
52} || {
53
54    # convert possible relative path in script to absolute
55    script=$(readlink -m "$script")
56
57    # url-encode any arguments
58    shift
59    args=''
60    for arg in "$@"
61    do
62        arg=$(echo -ne "$arg" | hexdump -v -e '/1 "%02x"' | sed 's/\(..\)/%\1/g')
63        args="$args&=$arg"
64    done
65
66    #echo executing script: $script
67    #echo args: $args
68
69    echo -n -e '\x1B[97m' # white
70    curl --cookie $HOME/.iosh-cookies --cookie-jar $HOME/.iosh-cookies "$IOSH?=file:${script}${args}"
71
72    exit $?
73}
74
Note: See TracBrowser for help on using the repository browser.