Skip to content

Instantly share code, notes, and snippets.

@elfrank
Last active December 21, 2015 18:39
Show Gist options
  • Save elfrank/6348515 to your computer and use it in GitHub Desktop.
Save elfrank/6348515 to your computer and use it in GitHub Desktop.
#!/bin/bash
FRAMEBUFFER_ID=0
FILE="/usr/hover/bin/scripts/screenshot.jpg"
while getopts ":f:p:n:h" optname
do
case "$optname" in
"f")
FRAMEBUFFER_ID=$OPTARG
echo "framebuffer id is $FRAMEBUFFER_ID"
;;
"n")
FILE=$OPTARG
echo "file is $FILE"
;;
"?")
echo "Unknown option $OPTARG"
;;
":")
echo "No argument value for option $OPTARG"
;;
"h")
echo "help"
;;
*)
# Should not occur
echo "Unknown error while processing options"
;;
esac
done
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
echo "Mac"
`screencapture -t jpg -x $FILE`
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Do something under Linux platform
export DISPLAY=:$FRAMEBUFFER_ID
DISPLAY=:$FRAMEBUFFER_ID import -window root $FILE
echo "Linux"
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
# Do something under Windows NT platform
echo "Window"
fi
#!/bin/bash
SIZE="1024,768"
'''if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
echo "Mac"
`/Applications/Chromium.app/Contents/MacOS/Chromium $BROWSER_ARGS $URL`
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Do something under Linux platform
echo "Linux"
export DISPLAY=:0
$BROWSER_PATH $WEBGL_ARGS $BROWSER_ARGS $URL
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
# Do something under Windows NT platform
echo "Windows"
fi'''
BROWSER="chrome"
BROWSER_PATH="/mnt/storage/chromium/out/29.0.1548.1/Release_Prometheus/chrome"
URL="http://get.webgl.org/"
while getopts ":f:u:s:h:" optname
do
case "$optname" in
"f")
FRAMEBUFFER_ID=$OPTARG
echo "framebuffer id is $FRAMEBUFFER_ID"
;;
"u")
URL=$OPTARG
echo "url is $URL"
;;
"s")
SIZE=$OPTARG
echo "size is $SIZE"
;;
"?")
echo "Unknown option $OPTARG"
;;
":")
echo "No argument value for option $OPTARG"
;;
"h")
echo "help"
;;
*)
# Should not occur
echo "Unknown error while processing options"
;;
esac
done
WEBGL_ARGS="--use-gl=osmesa --enable-webgl --ignore-gpu-blacklist"
#BROWSER_ARGS="--kiosk --window-size=$SIZE"
BROWSER_ARGS="--kiosk"
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
echo "Mac"
`/Applications/Chromium.app/Contents/MacOS/Chromium $BROWSER_ARGS $URL`
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Do something under Linux platform
echo "Linux"
export DISPLAY=:0
$BROWSER_PATH $WEBGL_ARGS $BROWSER_ARGS $URL
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
# Do something under Windows NT platform
echo "Windows"
fi
-------------------------
Steps
-------------------------
sudo sh /usr/hover/bin/scripts/xvfb start
bash /usr/hover/bin/scripts/start_browser.sh -f 0 -s 1024,768 -u "http://localhost:3000/building_images/scene?building_id=17&framebuffer_id=0" &
bash /usr/hover/bin/scripts/capture_framebuffer.sh -f 0 -n /usr/hover/bin/scripts/screenshot.jpg
bash /usr/hover/bin/scripts/stop_browser.sh
sudo sh /usr/hover/bin/scripts/xvfb stop
-------------------------
Notes
-------------------------
* Change path on star_browser.sh
- /mnt/storage/chromium/out/29.0.1548.1/Release_Prometheus/chrome
* Avoid login
#!/bin/bash
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
echo "Mac"
killall -9 "Chromium"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Do something under Linux platform
killall chrome
echo "Linux"
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
# Do something under Windows NT platform
echo "Window"
fi
#! /bin/bash
# location: /usr/hover/bin/xvfb
# make it executable: chmod 744 /usr/hover/bin/xvfb
BUFFER_ID=0
WIDTH=1024
HEIGHT=768
SIZE=$WIDTH"x"$HEIGHT"x24"
XVFB=/usr/bin/Xvfb
XVFBARGS=":$BUFFER_ID -auth ~/.Xauthority_$BUFFER_ID -screen $BUFFER_ID $SIZE"
PIDFILE=/tmp/xvfb_$BUFFER_ID.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
/sbin/start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
;;
stop)
echo -n "Stopping virtual X frame buffer: Xvfb"
/sbin/start-stop-daemon --stop --quiet --pidfile $PIDFILE
rm -f $PIDFILE
echo "."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /usr/hover/bin/xvfb {start|stop|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment