• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2014 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# This a simple script to make running Mojo shell easier (on Linux).
7
8DIRECTORY="$(dirname "$0")"/../../out/Debug
9PORT=$(($RANDOM % 8192 + 2000))
10
11do_help() {
12  cat << EOF
13Usage: $(basename "$0") [-d DIRECTORY] [-|--] <mojo_shell arguments ...>
14
15DIRECTORY defaults to $DIRECTORY.
16
17Example:
18  $(basename "$0") mojo:mojo_sample_app
19EOF
20}
21
22kill_http_server() {
23  echo "Killing SimpleHTTPServer ..."
24  kill $HTTP_SERVER_PID
25  wait $HTTP_SERVER_PID
26}
27
28while [ $# -gt 0 ]; do
29  case "$1" in
30    -h|--help)
31      do_help
32      exit 0
33      ;;
34    -d)
35      shift
36      if [ $# -eq 0 ]; then
37        do_help
38        exit 1
39      fi
40      DIRECTORY="$1"
41      ;;
42    --show-bash-alias)
43      echo alias\ mojosh\=\'\"\$\(pwd\ \|\ sed\ \'\"\'\"\'s\/\\\(\.\*\\\/src\\\
44\)\.\*\/\\1\/\'\"\'\"\'\)\/mojo\/tools\/mojosh\.sh\"\'
45      exit 0
46      ;;
47    # Separate arguments to mojo_shell (e.g., in case you want to pass it -d).
48    -|--)
49      shift
50      break
51      ;;
52    *)
53      break
54      ;;
55  esac
56  shift
57done
58
59echo "Base directory: $DIRECTORY"
60
61echo "Running SimpleHTTPServer in directory $DIRECTORY/lib on port $PORT"
62cd $DIRECTORY/lib || exit 1
63python -m SimpleHTTPServer $PORT &
64# Kill the HTTP server on exit (even if the user kills everything using ^C).
65HTTP_SERVER_PID=$!
66trap kill_http_server EXIT
67cd ..
68
69echo "Running:"
70echo "./mojo_shell --origin=http://127.0.0.1:$PORT --disable-cache $*"
71./mojo_shell --origin=http://127.0.0.1:$PORT --disable-cache $*
72