summaryrefslogtreecommitdiffstats
path: root/mojo/tools/mojosh.sh
blob: bb8a2cdca4a4f61013dda9435e4ef667a432369d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This a simple script to make running Mojo shell easier (on Linux).

DIRECTORY="$(dirname "$0")"/../../out/Debug
PORT=$(($RANDOM % 8192 + 2000))

do_help() {
  cat << EOF
Usage: $(basename "$0") [-d DIRECTORY] [-|--] <mojo_shell arguments ...>

DIRECTORY defaults to $DIRECTORY.

Example:
  $(basename "$0") mojo:mojo_sample_app
EOF
}

kill_http_server() {
  echo "Killing SimpleHTTPServer ..."
  kill $HTTP_SERVER_PID
  wait $HTTP_SERVER_PID
}

while [ $# -gt 0 ]; do
  case "$1" in
    -h|--help)
      do_help
      exit 0
      ;;
    -d)
      shift
      if [ $# -eq 0 ]; then
        do_help
        exit 1
      fi
      DIRECTORY="$1"
      ;;
    --show-bash-alias)
      echo alias\ mojosh\=\'\"\$\(pwd\ \|\ sed\ \'\"\'\"\'s\/\\\(\.\*\\\/src\\\
\)\.\*\/\\1\/\'\"\'\"\'\)\/mojo\/tools\/mojosh\.sh\"\'
      exit 0
      ;;
    # Separate arguments to mojo_shell (e.g., in case you want to pass it -d).
    -|--)
      shift
      break
      ;;
    *)
      break
      ;;
  esac
  shift
done

echo "Base directory: $DIRECTORY"

echo "Running SimpleHTTPServer in directory $DIRECTORY/lib on port $PORT"
cd $DIRECTORY/lib || exit 1
python -m SimpleHTTPServer $PORT &
# Kill the HTTP server on exit (even if the user kills everything using ^C).
HTTP_SERVER_PID=$!
trap kill_http_server EXIT
cd ..

echo "Running:"
echo "./mojo_shell --origin=http://127.0.0.1:$PORT --disable-cache $*"
./mojo_shell --origin=http://127.0.0.1:$PORT --disable-cache $*