blob: 3a66b240cb175cfd18ed986f3fbbfcff116ae5c4 [file] [log] [blame]
#!/bin/sh
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
PROG="$(basename $0)"
CHROME_CMD="/opt/google/chrome/chrome"
# For the time being, the chrome browser and the webplot server are
# located on the same machine.
CHROME_FLAGS="--user-data-dir=/home/chronos localhost"
TMP_LOG="/tmp/${PROG}_chrome.log"
# A local die function to print the message and then exit
die() {
echo -e "$@"
exit 1
}
# Search the webplot directory.
PROG_DIR="$(find /usr/local/lib* -name $PROG)"
if [ -z "$PROG_DIR" ]; then
die "Fail to find the path of $PROG."
fi
# Start webplot if not yet.
if [ -n "$(ps a | egrep "python\s+${PROG}" | grep -v grep)" ]; then
echo "$PROG server has been started."
else
# Must run webplot as root as it needs to access system device nodes.
if [ $USER != root ]; then
die "Please run $PROG as root."
fi
echo "Start $PROG server..."
sudo python "${PROG_DIR}"/"${PROG}".py &
# Wait a while for the webplot server to get ready before launching
# a chrome tab to connect to it.
sleep 1
fi
# Note that the chrome must be launched as chronos.
# Hence, it is OK that $USER is chronos if the webpot server has been started.
echo "$USER: start to launch a new chrome tab and connect to $PROG server..."
if [ $USER = chronos ]; then
exec "$CHROME_CMD" $CHROME_FLAGS > "$TMP_LOG" 2>&1
elif [ $USER = root ]; then
exec su chronos -c "$CHROME_CMD $CHROME_FLAGS > $TMP_LOG 2>&1"
else
echo "You should login as chronos or root."
fi