Created
May 20, 2016 10:48
-
-
Save kiliankoe/95db824ecb000b7b7570f0b94a3aee70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ ! -z $QUERY_STRING ] | |
then | |
error=""; | |
case $QUERY_STRING in | |
kaffee|"kaffee=") | |
cat <<-"EOK" | |
Status: 418 I'm a teapot | |
Content-type: text/html | |
<HTML> | |
<HEAD><TITLE>418 I'm a teapot</TITLE></HEAD> | |
<BODY> | |
<H1>Error</H1> | |
<P>Sorry, I'm a teapot. See section 2.3.2 of <A HREF="http://tools.ietf.org/html/rfc2324">RFC 2324 for details.</A></P> | |
</BODY> | |
</HTML> | |
EOK | |
;; | |
reboot|"reboot=") | |
cat <<-"EOR" | |
Content-type: text/json | |
["rebooting"] | |
EOR | |
sudo reboot | |
exit 0;; | |
shutdown|"shutdown=") | |
cat <<-"EOR" | |
Content-type: text/json | |
["shutting down"] | |
EOR | |
sudo halt | |
exit 0;; | |
zihsd|"zihsd=") | |
cat <<-"EOR" | |
Content-type: text/json | |
["displayed zih"] | |
EOR | |
DISPLAY=:0 sudo -u pi omxplayer /var/www/zihsd.mp4 -r 15 > /dev/null | |
sudo -u pi /usr/bin/xrefresh -display :0 | |
exit 0;; | |
restart|"restart=") | |
cat <<-"EOR" | |
Content-type: text/json | |
["restarting Chromium"] | |
EOR | |
sudo killall chromium | |
DISPLAY=:0 sudo -u pi chromium --disk-cache-dir="/var/tmp" --disable-translate --incognito --kiosk "http://localhost/" | |
exit 0;; | |
gitreset|"gitreset=") | |
echo "Content-type: text/json" | |
echo "" | |
echo -n "[\"" | |
sudo -u pi git --git-dir=/home/pi/infoscreen/.git --work-tree=/home/pi reset --hard | |
echo "\"]" | |
exit 0;; | |
gitpull|"gitpull=") | |
echo "Content-type: text/json" | |
echo "" | |
echo -n "[\"" | |
sudo -u pi git --git-dir=/home/pi/infoscreen/.git --work-tree=/home/pi pull origin master | |
echo "\"]" | |
exit 0;; | |
refresh|"refresh=") | |
error="501";; | |
reload|"reload=") | |
error="501";; | |
*) error="400";; | |
esac | |
if [ -n $error ] | |
then | |
case $error in | |
400) | |
cat <<-"EO4" | |
Status: 400 Bad Request | |
Content-type: text/html | |
<HTML> | |
<HEAD><TITLE>400 Bad Request</TITLE></HEAD> | |
<BODY> | |
<H1>Error</H1> | |
<P>Sorry, but no.</A></P> | |
</BODY> | |
</HTML> | |
EO4 | |
;; | |
501) | |
cat <<-"EO5" | |
Status: 501 Not Implemented | |
Content-type: text/html | |
<HTML> | |
<HEAD><TITLE>501 Not Implemented</TITLE></HEAD> | |
<BODY> | |
<H1>Error</H1> | |
<P>Sorry, but this functionality is not implemented. Yet.</P> | |
</BODY> | |
</HTML> | |
EO5 | |
;; | |
*) #echo "Wat?" ;; | |
esac | |
exit 1; | |
fi | |
else | |
cat <<-"EOM" | |
Status: 300 Multiple Choices | |
Content-type: text/json | |
[ | |
["reboot", "shutdown", "gitreset", "gitpull", "restart", "zihsd", "kaffee"], | |
[ | |
"Reboot the Pi", | |
"Shutdown the Pi", | |
"Reset testing code", | |
"Pull new code from git", | |
"Restart browser", | |
"Show the way to ZIH SD", | |
"Make coffee" | |
] | |
] | |
EOM | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment