Ticket #13791: slimerjs

File slimerjs, 7.3 KB (added by 0a0c4927a2b9896cf3bed2389224bbe13e9a76b5, 5 years ago)

Wrapper script for slimerjs.

Line 
1#!/bin/bash
2
3#retrieve full path of the current script
4# symlinks are resolved, so application.ini could be found
5# this code comes from http://stackoverflow.com/questions/59895/
6SOURCE="${BASH_SOURCE[0]}"
7while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
8  SLIMERDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
9  SOURCE="$(readlink "$SOURCE")"
10  [[ $SOURCE != /* ]] && SOURCE="$SLIMERDIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
11done
12SLIMERDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
13
14SYSTEM=`uname -o 2>&1`
15if [ "$SYSTEM" == "Cygwin" ]
16then
17   IN_CYGWIN=1
18   SLIMERDIR=`cygpath -w $SLIMERDIR`
19else
20   IN_CYGWIN=
21fi
22
23# retrieve the path of a gecko launcher
24if [ "$SLIMERJSLAUNCHER" == "" ]
25then
26    if [ -f "$SLIMERDIR/xulrunner/xulrunner" ]
27    then
28        SLIMERJSLAUNCHER="$SLIMERDIR/xulrunner/xulrunner"
29    else
30        if [ -f "$SLIMERDIR/xulrunner/xulrunner.exe" ]
31        then
32            SLIMERJSLAUNCHER="$SLIMERDIR/xulrunner/xulrunner.exe"
33        else
34            SLIMERJSLAUNCHER=`command -v firefox`
35            if [ "$SLIMERJSLAUNCHER" == "" ]
36            then
37                SLIMERJSLAUNCHER=`command -v xulrunner`
38                if [ "$SLIMERJSLAUNCHER" == "" ]
39                then
40                    echo "SLIMERJSLAUNCHER environment variable is missing. Set it with the path to Firefox or XulRunner"
41                    exit 1
42                fi
43            fi
44        fi
45    fi
46fi
47
48if [ ! -x "$SLIMERJSLAUNCHER" ]
49then
50    echo "SLIMERJSLAUNCHER environment variable does not contain an executable path. Set it with the path to Firefox"
51    exit 1
52fi
53
54function showHelp() {
55    echo "In following values, <bool> can be yes, no, true or false"
56    echo ""
57    echo "  --config=<file>                    Load the given configuration file"
58    echo "                                     (JSON formated)"
59    echo "  --debug=<bool>                     Prints additional warning and debug message"
60    echo "                                     (default is no)"
61    echo "  --disk-cache=<bool>                Enables disk cache (default is no)."
62    echo "  --help or -h                       Show this help"
63    #echo "  --ignore-ssl-errors=<bool>         Ignores SSL errors (default is no)."
64    echo "  --load-images=<bool>               Loads all inlined images (default is yes)"
65    echo "  --local-storage-quota=<number>     Sets the maximum size of the offline"
66    echo "                                     local storage (in KB)"
67    #echo "  --local-to-remote-url-access=<bool>   Allows local content to access remote"
68    #echo "                                        URL (default is no)"
69    echo "  --max-disk-cache-size=<number>     Limits the size of the disk cache (in KB)"
70    #echo "  --output-encoding=<enc>            Sets the encoding for the terminal output"
71    #echo "                                     (default is 'utf8')"
72    #echo "  --remote-debugger-port=<number>    Starts the script in a debug harness and"
73    #echo "                                     listens on the specified port"
74    #echo "  --remote-debugger-autorun=<bool>   Runs the script in the debugger immediately"
75    #echo "                                     (default is no)"
76    echo "  --proxy=<proxy url>                Sets the proxy server"
77    echo "  --proxy-auth=<username:password>   Provides authentication information for the"
78    echo "                                     proxy"
79    echo "  --proxy-type=[http|socks5|none|auto|system|config-url]    Specifies the proxy type (default is http)"
80    #echo "  --script-encoding=<enc>            Sets the encoding used for the starting"
81    #echo "                                     script (default is utf8)"
82    #echo "  --web-security=<bool>              Enables web security (default is yes)"
83    echo "  --version or v                     Prints out SlimerJS version"
84    #echo "  --webdriver or --wd or -w          Starts in 'Remote WebDriver mode' (embedded"
85    #echo "                                     GhostDriver) '127.0.0.1:8910'"
86    #echo "  --webdriver=[<IP>:]<PORT>          Starts in 'Remote WebDriver mode' in the"
87    #echo "                                     specified network interface"
88    #echo "  --webdriver-logfile=<file>         File where to write the WebDriver's Log "
89    #echo "                                     (default 'none') (NOTE: needs '--webdriver')"
90    #echo "  --webdriver-loglevel=[ERROR|WARN|INFO|DEBUG] WebDriver Logging Level "
91    #echo "                                 (default is 'INFO') (NOTE: needs '--webdriver')"
92    #echo "  --webdriver-selenium-grid-hub=<url> URL to the Selenium Grid HUB (default is"
93    #echo "                                      'none') (NOTE: needs '--webdriver') "
94    echo "  --error-log-file=<file>            Log all javascript errors in a file"
95    echo "  -jsconsole                         Open a window to view all javascript errors"
96    echo "                                       during the execution"
97    echo ""
98    echo "*** About profiles: see details of these Mozilla options at"
99    echo "https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile"
100    echo ""
101    echo "  --createprofile name               Create a new profile and exit"
102    echo "  -P name                            Use the specified profile to execute the script"
103    echo "  -profile path                      Use the profile stored in the specified"
104    echo "                                     directory, to execute the script"
105    echo "By default, SlimerJS use a temporary profile"
106    echo ""
107}
108
109# retrieve list of existing environment variable, because Mozilla doesn't provide an API to get this
110# list
111LISTVAR=""
112ENVVAR=`env`;
113OLDIFS=$IFS;
114IFS=$'\n';
115for v in $ENVVAR; do
116    IFS='=' read -a var <<< "$v"
117    LISTVAR="$LISTVAR,${var[0]}"
118done
119IFS=$OLDIFS;
120
121# check arguments.
122CREATE_TEMP='Y'
123HIDE_ERRORS='Y'
124shopt -s nocasematch
125for i in $*; do
126    case "$i" in
127        --help|-h)
128           showHelp
129           exit 0
130           ;;
131        -reset-profile|-profile|-p|-createprofile|-profilemanager)
132            CREATE_TEMP=''
133            ;;
134        --reset-profile|--profile|--p|--createprofile|--profilemanager)
135            CREATE_TEMP=''
136            ;;
137    esac
138    if [[ $i == --debug* ]] && [[ "$i" == *errors* ]]; then
139        HIDE_ERRORS='N'
140    fi
141done
142shopt -u nocasematch
143
144# If profile parameters, don't create a temporary profile
145PROFILE=""
146PROFILE_DIR=""
147if [ "$CREATE_TEMP" == "Y" ]
148then
149    PROFILE_DIR=`mktemp -d -q /tmp/slimerjs.XXXXXXXX`
150    if [ "$PROFILE_DIR" == "" ]; then
151        echo "Error: cannot generate temp profile"
152        exit 1
153    fi
154    if [ "$IN_CYGWIN" == 1 ]; then
155        PROFILE_DIR=`cygpath -w $PROFILE_DIR`
156    fi
157    PROFILE="--profile $PROFILE_DIR"
158else
159    PROFILE="-purgecaches"
160fi
161
162# put all arguments in a variable, to have original arguments before their transformation
163# by Mozilla
164export __SLIMER_ARGS="$@"
165export __SLIMER_ENV="$LISTVAR"
166
167# launch slimerjs with firefox/xulrunner
168if [ "$HIDE_ERRORS" == "Y" ]; then
169    "$SLIMERJSLAUNCHER" -app "$SLIMERDIR/application.ini" $PROFILE -no-remote "$@" 2> /dev/null
170else
171    "$SLIMERJSLAUNCHER" -app "$SLIMERDIR/application.ini" $PROFILE -no-remote "$@"
172fi
173
174EXITCODE=$?
175
176if [ "$PROFILE_DIR" != "" ]; then
177    rm -rf $PROFILE_DIR
178fi
179
180exit $EXITCODE