Raspberry Pi - Browser v2

passwd
> /etc/motd

hostname rpi-briefing # also: rpi-statusdisplay/rpi-timeclockdisplay
echo `hostname` > /etc/hostname
sed 's/^127.0.1.1\t.*$/127.0.1.1\t'`hostname`'/g' /etc/hosts

apt-get update && apt-get --no-install-recommends install aptitude

systemctl disable ssh.service && systemctl enable ssh.socket

ln -sf /usr/share/zoneinfo/America/Chicago /etc/localtime
echo "America/Chicago" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata

sed -i -e 's/^# en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen
dpkg-reconfigure -f noninteractive locales

aptitude update && aptitude full-upgrade

aptitude install netcat-traditional screen rsync psmisc file patch ethtool strace tcpdump vim bzip2 xz-utils
aptitude --without-recommends install dnsutils

aptitude install watchdog
sed -i -e 's/^#watchdog-device/watchdog-device/g' /etc/watchdog.conf
sed -i -e 's/^#max-load-1\t/max-load-1\t/g' /etc/watchdog.conf
echo "# Raspberry Pi doesn't work with the default timeout of 60; set it to 10 instead" >> /etc/watchdog.conf
echo $'watchdog-timeout\t= 10' >> /etc/watchdog.conf

adduser tdobes
adduser tdobes adm
adduser tdobes systemd-journal

aptitude install firmware-brcm80211 # rpi3 wifi firmware
aptitude install ifmetric iw wireless-tools ifplugd wpasupplicant
sed -i -e 's/^REGDOMAIN=$/REGDOMAIN=US/g' /etc/default/crda
sed -i -e 's/^INTERFACES=""/INTERFACES="eth0"/g' /etc/default/ifplugd
sed -i -e 's/^allow-hotplug eth0/#allow-hotplug eth0/g' /etc/network/interfaces
/etc/init.d/ifplugd restart

echo >> /etc/network/interfaces
echo 'allow-hotplug wlan0' >> /etc/network/interfaces
echo 'iface wlan0 inet manual' >> /etc/network/interfaces
echo '  wpa-driver nl80211,wext' >> /etc/network/interfaces
echo '  wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf' >> /etc/network/interfaces
echo >> /etc/network/interfaces
echo 'iface mcp inet dhcp' >> /etc/network/interfaces
echo '  metric 1' >> /etc/network/interfaces
cat > /etc/wpa_supplicant/wpa_supplicant.conf <<EOF
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
  ssid="mcp-2.4"
  scan_ssid=1
  psk="**PASSWORD**"
  priority=9
  id_str="mcp"
}

network={
  ssid="mcp-5.8"
  scan_ssid=1
  psk="**PASSWORD**"
  priority=10
  id_str="mcp"
}
EOF
#chmod -x /etc/wpa_supplicant/action_wpa.sh # ensures that ifplugd doesn't disconnect wifi – see http://raspberrypi.stackexchange.com/questions/31780/wpa-supplicant-conf-with-two-network-cards-not-working-when-wpa-roam

aptitude install xserver-xorg-video-fbturbo xserver-xorg-input-evdev # using evdev instead of libinput because it pulls in a ton more deps
aptitude install xinit evilwm xdotool x11vnc unclutter x11-xserver-utils
aptitude install --without-recommends chromium-browser
aptitude install fonts-symbola # takes care of emoji

sed -i -e 's/^allowed_users=console/allowed_users=anybody/g' /etc/X11/Xwrapper.config
sed -i 's/START_UNCLUTTER="true"/START_UNCLUTTER="false"/g' /etc/default/unclutter
sed -i -e 's/^use-ssh-agent$/#use-ssh-agent/g' /etc/X11/Xsession.options

adduser --shell /bin/false --gecos "Browser" --disabled-password browser


echo '#!/bin/sh' > /usr/local/bin/browser-xsession.sh
echo >> /usr/local/bin/browser-xsession.sh
echo 'pkill -9 evilwm' >> /usr/local/bin/browser-xsession.sh
echo 'pkill -9 x11vnc' >> /usr/local/bin/browser-xsession.sh
echo >> /usr/local/bin/browser-xsession.sh
echo 'xset s off #disable screensaver' >> /usr/local/bin/browser-xsession.sh
echo 'xset dpms 0 0 0 #disable automatic power saving' >> /usr/local/bin/browser-xsession.sh
echo 'unclutter -grab -idle 2 & #daemon to auto-hide mouse' >> /usr/local/bin/browser-xsession.sh
echo >> /usr/local/bin/browser-xsession.sh
echo '#SHELL=/bin/bash xterm &' >> /usr/local/bin/browser-xsession.sh
echo >> /usr/local/bin/browser-xsession.sh
echo "exec evilwm -fn '*-clean-*'" >> /usr/local/bin/browser-xsession.sh
chmod +x /usr/local/bin/browser-xsession.sh
ln -s /usr/local/bin/browser-xsession.sh ~browser/.xsession

mkdir ~browser/.vnc
x11vnc -storepasswd **PASSWORD** ~browser/.vnc/passwd
chown -R browser:browser ~browser/.vnc
chmod 0600 ~browser/.vnc/passwd

echo '[Unit]' > /etc/systemd/system/startx.service
echo 'Description=Start Xorg for HDMI' >> /etc/systemd/system/startx.service
echo >> /etc/systemd/system/startx.service
echo '[Service]' >> /etc/systemd/system/startx.service
echo 'ExecStart=-/usr/bin/startx -- :0 -nolisten tcp vt2' >> /etc/systemd/system/startx.service
echo 'ExecStopPost=-/usr/bin/pkill -9 -U browser evilwm' >> /etc/systemd/system/startx.service
echo 'User=browser' >> /etc/systemd/system/startx.service
echo 'Restart=always' >> /etc/systemd/system/startx.service
echo 'RestartSec=1' >> /etc/systemd/system/startx.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/startx.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/startx.service
echo >> /etc/systemd/system/startx.service
echo '[Install]' >> /etc/systemd/system/startx.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/startx.service

systemctl enable startx.service

echo '[Unit]' > /etc/systemd/system/x11vnc.service
echo 'Description=Start X11VNC for Slideshow' >> /etc/systemd/system/x11vnc.service
echo 'After=startx.service' >> /etc/systemd/system/x11vnc.service
echo 'Requires=startx.service' >> /etc/systemd/system/x11vnc.service
echo >> /etc/systemd/system/x11vnc.service
echo '[Service]' >> /etc/systemd/system/x11vnc.service
echo 'ExecStart=-/usr/bin/x11vnc -q -usepw -N -ncache 0 -shared -forever' >> /etc/systemd/system/x11vnc.service
echo 'User=browser' >> /etc/systemd/system/x11vnc.service
echo 'Environment=DISPLAY=:0' >> /etc/systemd/system/x11vnc.service
echo 'Restart=always' >> /etc/systemd/system/x11vnc.service
echo 'RestartSec=1' >> /etc/systemd/system/x11vnc.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/x11vnc.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/x11vnc.service
echo >> /etc/systemd/system/x11vnc.service
echo '[Install]' >> /etc/systemd/system/x11vnc.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/x11vnc.service

systemctl enable x11vnc.service

echo '[Unit]' > /etc/systemd/system/browser.service
echo 'Description=Browser' >> /etc/systemd/system/browser.service
echo 'After=startx.service' >> /etc/systemd/system/browser.service
echo 'Requires=startx.service' >> /etc/systemd/system/browser.service
echo >> /etc/systemd/system/browser.service
echo '[Service]' >> /etc/systemd/system/browser.service
echo 'ExecStart=-/usr/local/bin/browser.sh' >> /etc/systemd/system/browser.service
echo 'User=browser' >> /etc/systemd/system/browser.service
echo 'Environment=DISPLAY=:0' >> /etc/systemd/system/browser.service
echo 'Restart=always' >> /etc/systemd/system/browser.service
echo 'RestartSec=1' >> /etc/systemd/system/browser.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/browser.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/browser.service
echo >> /etc/systemd/system/browser.service
echo '[Install]' >> /etc/systemd/system/browser.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/browser.service

systemctl enable browser.service

# rpi-briefing: NETWORK_CHECK=music.mcp.lcl, URL=http://music.mcp.lcl/morning_briefing/cycler.html, 1920x1080 (1918 1078)
# rpi-statusdisplay (old): NETWORK_CHECK=rpi-relaycontrol.mcp.lcl, URL=http://rpi-relaycontrol.mcp.lcl/, 1920x1200 (1918 1198)
# rpi-statusdisplay (new): NETWORK_CHECK=music.mcp.lcl, URL=http://music.mcp.lcl/statusdisplay/, 1920x1200 (1918 1198)
# rpi-timeclockdisplay: NETWORK_CHECK=database.mcp.lcl, URL=http://database.mcp.lcl/timeclock/right.php, 1920x1080 (1918 1078)

echo '#!/bin/sh' > /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo 'NETWORK_CHECK=music.mcp.lcl' >> /usr/local/bin/browser.sh
echo 'URL=http://music.mcp.lcl/statusdisplay/' >> /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo '# get rid of cache and settings' >> /usr/local/bin/browser.sh
echo 'rm -r ~/.cache/chromium 2> /dev/null' >> /usr/local/bin/browser.sh
echo 'rm -r ~/.config/chromium 2> /dev/null' >> /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo '# to get --disable-web-security to work (which allows cross-origin requests), you have to specify a user-data-dir' >> /usr/local/bin/browser.sh
echo "# also, chrome segfaults if it's not an abolute path" >> /usr/local/bin/browser.sh
echo 'chrome_data_dir=`realpath ~/.chromedata`' >> /usr/local/bin/browser.sh
echo 'rm -r $chrome_data_dir 2> /dev/null' >> /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo 'echo -n waiting for network' >> /usr/local/bin/browser.sh
echo 'while ! ping -c 1 $NETWORK_CHECK > /dev/null 2> /dev/null ; do' >> /usr/local/bin/browser.sh
echo '  echo -n .' >> /usr/local/bin/browser.sh
echo '  sleep 1' >> /usr/local/bin/browser.sh
echo 'done' >> /usr/local/bin/browser.sh
echo 'echo done!' >> /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo '# move the window to appropriate location (not needed for chromium)' >> /usr/local/bin/browser.sh
echo '#sh -c '"'"'sleep 1 ; echo -n attempting to move simplebrowser ; while ! xdotool search --onlyvisible --name simplebrowser.py windowmove 0 0 windowsize 1918 1078; do echo -n . ; sleep 1 ; done ; echo done!'"'"' &' >> /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo '# start simplebrowser' >> /usr/local/bin/browser.sh
echo '#exec nice -n 1 simplebrowser.py $URL' >> /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo '# start chromium' >> /usr/local/bin/browser.sh
echo 'exec nice -n 1 /usr/lib/chromium-browser/chromium-browser --disable-preconnect --disable-breakpad --disable-sync --no-sandbox --disable-plugins --disable-translate --dns-prefetch-disable --data-reduction-proxy-server-experiments-disabled --disable-bundled-ppapi-flash --no-pings --no-first-run --chrome-frame --disable-session-crashed-bubble --disable-web-security --user-data-dir=$chrome_data_dir --enable-logging=stderr --start-fullscreen --kiosk --app=$URL' >> /usr/local/bin/browser.sh
# note: we saw CPU usage creep up to 100% on morning briefing display with --disable-gpu - so I'm trying without it for a while...
echo '# --disable-gpu' >> /usr/local/bin/browser.sh
chmod +x /usr/local/bin/browser.sh

# HDMI mode, 1920x1080@60 Hz with audio - see https://www.raspberrypi.org/documentation/configuration/config-txt/video.md
sed -i 's/#hdmi_group=1/hdmi_group=2/g; s/#hdmi_drive=2/hdmi_drive=2/g; s/#hdmi_mode=1/hdmi_mode=82\n\nhdmi_force_mode=1/g; s/#disable_overscan=1/disable_overscan=1/g; s/#hdmi_force_hotplug=1/hdmi_force_hotplug=1/g' /boot/config.txt
# HDMI mode, 1920x1200@60 Hz without audio - see https://www.raspberrypi.org/documentation/configuration/config-txt/video.md
sed -i 's/#hdmi_group=1/hdmi_group=2/g; s/#hdmi_drive=2/hdmi_drive=1/g; s/#hdmi_mode=1/hdmi_mode=68\n\nhdmi_force_mode=1/g; s/#disable_overscan=1/disable_overscan=1/g; s/#hdmi_force_hotplug=1/hdmi_force_hotplug=1/g' /boot/config.txt

# quiet boot
sed -i -e 's/.*/& quiet/' /boot/cmdline.txt

systemctl stop rsyslog.service && systemctl disable rsyslog.service
rm /var/log/auth.log* /var/log/daemon.log* /var/log/debug* /var/log/kern.log* /var/log/messages* /var/log/user.log* /var/log/syslog*

systemctl disable rsync.service
systemctl disable sshswitch.service

old (qtwebkit-based):

aptitude install python-pyside.qtwebkit

echo '#!/usr/bin/env python' > /usr/local/bin/simplebrowser.py
echo >> /usr/local/bin/simplebrowser.py
echo 'import sys' >> /usr/local/bin/simplebrowser.py
echo 'from PySide.QtCore import *' >> /usr/local/bin/simplebrowser.py
echo 'from PySide.QtGui import *' >> /usr/local/bin/simplebrowser.py
echo 'from PySide.QtWebKit import *' >> /usr/local/bin/simplebrowser.py
echo >> /usr/local/bin/simplebrowser.py
echo 'app = QApplication(sys.argv)' >> /usr/local/bin/simplebrowser.py
echo >> /usr/local/bin/simplebrowser.py
echo 'if len(sys.argv) == 2:' >> /usr/local/bin/simplebrowser.py
echo '  url = QUrl(sys.argv[1])' >> /usr/local/bin/simplebrowser.py
echo 'else:' >> /usr/local/bin/simplebrowser.py
echo "  url = QUrl('http://www.google.com/')" >> /usr/local/bin/simplebrowser.py
echo >> /usr/local/bin/simplebrowser.py
echo 'web = QWebView()' >> /usr/local/bin/simplebrowser.py
echo 'web.load(url)' >> /usr/local/bin/simplebrowser.py
echo 'web.show()' >> /usr/local/bin/simplebrowser.py
echo >> /usr/local/bin/simplebrowser.py
echo 'sys.exit(app.exec_())' >> /usr/local/bin/simplebrowser.py
chmod +x /usr/local/bin/simplebrowser.py

echo '#!/bin/sh' > /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo 'NETWORK_CHECK=music.mcp.lcl' >> /usr/local/bin/browser.sh
echo 'URL=http://music.mcp.lcl/morning_briefing/cycler.html' >> /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo 'echo -n waiting for network' >> /usr/local/bin/browser.sh
echo 'while ! ping -c 1 $NETWORK_CHECK > /dev/null 2> /dev/null ; do' >> /usr/local/bin/browser.sh
echo '  echo -n .' >> /usr/local/bin/browser.sh
echo '  sleep 1' >> /usr/local/bin/browser.sh
echo 'done' >> /usr/local/bin/browser.sh
echo 'echo done!' >> /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo '# move the window to appropriate location' >> /usr/local/bin/browser.sh
echo 'sh -c '"'"'sleep 1 ; echo -n attempting to move simplebrowser ; while ! xdotool search --onlyvisible --name simplebrowser.py windowmove 0 0 windowsize 1918 1078; do echo -n . ; sleep 1 ; done ; echo done!'"'"' &' >> /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo '# start simplebrowser' >> /usr/local/bin/browser.sh
echo 'exec nice -n 1 simplebrowser.py $URL' >> /usr/local/bin/browser.sh
chmod +x /usr/local/bin/browser.sh
computer/raspberry_pi_browser_v2.txt · Last modified: 2019/02/23 13:07 by tdobes
Recent changes RSS feed Driven by DokuWiki Valid XHTML 1.0 Valid CSS