Recipe for Potter Hallway Display Renderer

  • base netinst install of jessie - deselect everything from tasksel
    • hostname display-p – domain ces.pnw.edu
    • auto-partition, but change root to discard,noatime and delete/recreate swap as standard (not extended) partition
  • > /etc/motd
  • apt-get --no-install-recommends install aptitude
  • aptitude install ssh (this will pull in xauth, but that's okay)
  • aptitude install less fbset screen rsync psmisc file patch ethtool strace tcpdump vim bzip2 xz-utils
  • aptitude --without-recommends install dnsutils
  • adduser tdobes adm
  • adduser tdobes systemd-journal
  • aptitude install dbus
  • sed -i -e 's/Port 22/Port 22\nPort 2222/g' /etc/ssh/sshd_config
  • sed -i -e 's/^deb.* main$/& contrib non-free/g' /etc/apt/sources.list
  • aptitude update && aptitude forget-new
  • aptitude install intel-microcode firmware-linux-nonfree # nonfree firmware for ATI card
  • aptitude install ifplugd
  • 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
  • aptitude --without-recommends install ntp
    echo '[Unit]' > /etc/systemd/system/ntp.service
    echo 'Description=Network Time Protocol daemon' >> /etc/systemd/system/ntp.service
    echo 'After=network.target' >> /etc/systemd/system/ntp.service
    echo >> /etc/systemd/system/ntp.service
    echo '[Service]' >> /etc/systemd/system/ntp.service
    echo 'ExecStart=/usr/sbin/ntpd -n -g -u ntp:ntp' >> /etc/systemd/system/ntp.service
    echo >> /etc/systemd/system/ntp.service
    echo '[Install]' >> /etc/systemd/system/ntp.service
    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ntp.service
    systemctl enable ntp.service
  • mkdir -p /etc/systemd/system/ssh.socket.d
    echo '[Socket]' > /etc/systemd/system/ssh.socket.d/port-2222.conf
    echo 'ListenStream=2222' >> /etc/systemd/system/ssh.socket.d/port-2222.conf
    systemctl disable ssh.service && systemctl enable ssh.socket
  • mkdir -p /etc/systemd/system/getty\@tty1.service.d
    echo '[Service]' > /etc/systemd/system/getty\@tty1.service.d/noclear.conf
    echo 'TTYVTDisallocate=no' >> /etc/systemd/system/getty\@tty1.service.d/noclear.conf
  • systemctl mask networking.service # we use ifplugd instead
    echo 'D /run/network 0755 root root' > /etc/tmpfiles.d/debian-networking.conf
    echo 'F /run/network/ifstate 0644 root root - lo=lo' >> /etc/tmpfiles.d/debian-networking.conf
  • aptitude purge acpid acpi-support-base # systemd-logind takes care of this
  • sed -i -e 's/^GRUB_CMDLINE_LINUX_DEFAULT="quiet"$/GRUB_CMDLINE_LINUX_DEFAULT="quiet panic=5"/g' /etc/default/grub && update-grub
  • systemctl mask keyboard-setup.service
    systemctl mask console-setup.service
    systemctl mask rc-local.service
  • aptitude --without-recommends install irqbalance
  • aptitude install xserver-xorg-video-ati xserver-xorg-input-evdev
  • aptitude install xinit xinput evilwm xdotool x11vnc unclutter x11-xserver-utils
  • 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
  • dpkg-reconfigure x11-common – set “Users allowed to start the X server” to “Anybody”
  • adduser display # Name: Info Display (no password)
  • echo '#!/bin/sh' > /usr/local/bin/wait_network_up.sh
    echo >> /usr/local/bin/wait_network_up.sh
    echo 'echo -n waiting for any ethernet interface to come up' >> /usr/local/bin/wait_network_up.sh
    echo 'while ! ip link | grep "state UP" > /dev/null 2>/dev/null ; do' >> /usr/local/bin/wait_network_up.sh
    echo '  echo -n .' >> /usr/local/bin/wait_network_up.sh
    echo 'done' >> /usr/local/bin/wait_network_up.sh
    echo 'echo done!' >> /usr/local/bin/wait_network_up.sh
    chmod +x /usr/local/bin/wait_network_up.sh
  • Set up X11:
echo '#!/bin/sh' > /usr/local/bin/display-xsession.sh
echo >> /usr/local/bin/display-xsession.sh
echo 'pkill -9 evilwm' >> /usr/local/bin/display-xsession.sh
echo 'pkill -9 x11vnc' >> /usr/local/bin/display-xsession.sh
echo >> /usr/local/bin/display-xsession.sh
echo 'xrandr --output DVI-0 --mode 1920x1080' >> /usr/local/bin/display-xsession.sh
echo 'xrandr --output DVI-1 --mode 1920x1080' >> /usr/local/bin/display-xsession.sh
echo >> /usr/local/bin/display-xsession.sh
echo 'x11vnc -q -usepw -N -ncache 0 -shared -forever &' >> /usr/local/bin/display-xsession.sh
echo >> /usr/local/bin/display-xsession.sh
echo 'xset s off #disable screensaver' >> /usr/local/bin/display-xsession.sh
echo 'xset -dpms #disable automatic power saving' >> /usr/local/bin/display-xsession.sh
echo 'unclutter -grab -idle 2 & #daemon to auto-hide mouse' >> /usr/local/bin/display-xsession.sh
echo >> /usr/local/bin/display-xsession.sh
echo '#SHELL=/bin/bash xterm &' >> /usr/local/bin/display-xsession.sh
echo >> /usr/local/bin/display-xsession.sh
echo "# for some reason, this doesn't work unless you do it twice:" >> /usr/local/bin/display-xsession.sh
echo 'systemd-notify READY=1' >> /usr/local/bin/display-xsession.sh
echo 'systemd-notify READY=1' >> /usr/local/bin/display-xsession.sh
echo >> /usr/local/bin/display-xsession.sh
echo "exec evilwm -fn '*-clean-*'" >> /usr/local/bin/display-xsession.sh
chmod +x /usr/local/bin/display-xsession.sh
ln -s /usr/local/bin/display-xsession.sh /home/display/.xsession

echo '[Unit]' > /etc/systemd/system/startx\@.service
echo 'Description=Start Xorg for %I' >> /etc/systemd/system/startx\@.service
echo >> /etc/systemd/system/startx\@.service
echo '[Service]' >> /etc/systemd/system/startx\@.service
echo 'ExecStart=-/usr/bin/startx' >> /etc/systemd/system/startx\@.service # when you specify additional Xorg parameters, you have to include "-nolisten tcp" since it overrides the Debian defaults
echo 'ExecStopPost=-/usr/bin/pkill -9 -U %I evilwm' >> /etc/systemd/system/startx\@.service
echo 'ExecStartPre=/usr/local/bin/wait_network_up.sh' >> /etc/systemd/system/startx\@.service # terrible hack to prevent double-start of X (something kills it when the network comes up - WTH?)
echo 'User=%I' >> /etc/systemd/system/startx\@.service
echo 'Type=notify' >> /etc/systemd/system/startx\@.service
echo 'NotifyAccess=all' >> /etc/systemd/system/startx\@.service
echo 'Restart=always' >> /etc/systemd/system/startx\@.service
echo 'RestartSec=1' >> /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\@display.service # doesn't work on old systemd releases
ln -s /etc/systemd/system/startx\@.service /etc/systemd/system/multi-user.target.wants/startx\@display.service

echo '[Unit]' > /etc/systemd/system/xterm.service
echo 'Description=xterm for troubleshooting' >> /etc/systemd/system/xterm.service
echo 'After=startx@display.service' >> /etc/systemd/system/xterm.service
echo 'Requires=startx@display.service' >> /etc/systemd/system/xterm.service
echo >> /etc/systemd/system/xterm.service
echo '[Service]' >> /etc/systemd/system/xterm.service
echo 'ExecStart=-/usr/bin/xterm' >> /etc/systemd/system/xterm.service
echo 'User=display' >> /etc/systemd/system/xterm.service
echo 'Environment=DISPLAY=:0' >> /etc/systemd/system/xterm.service
echo 'Environment=SHELL=/bin/sh' >> /etc/systemd/system/xterm.service
  • mkdir ~display/.vnc
    x11vnc -storepasswd **PASSWORD** ~display/.vnc/passwd
    chown -R display:display ~display/.vnc
    chmod 0600 ~display/.vnc/passwd
  • aptitude install fonts-freefont-ttf ttf-mscorefonts-installer ttf-bitstream-vera ttf-dejavu # for displaying information channel
  • 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 'if len(sys.argv) >= 3:' >> /usr/local/bin/simplebrowser.py
    echo '  web.setWindowTitle(sys.argv[2])' >> /usr/local/bin/simplebrowser.py
    echo 'if len(sys.argv) >= 7:' >> /usr/local/bin/simplebrowser.py
    echo '  web.setGeometry(int(sys.argv[5]), int(sys.argv[6]), int(sys.argv[3]), int(sys.argv[4]))' >> /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
    
    # NOTE: If you're fighting a javascript problem, add this line after creating the QWebView:
    # web.settings().globalSettings().setAttribute(QWebSettings.WebAttribute.DeveloperExtrasEnabled, True)
  • Set up infodisplay web browser stuff:
    echo '#!/bin/sh' > /usr/local/bin/browser.sh
    echo >> /usr/local/bin/browser.sh
    echo 'echo -n waiting for network/server' >> /usr/local/bin/browser.sh
    echo 'while ! ping -c 1 display-server-p > /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_browser.sh &' >> /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 http://display-server-p/display/?computername=`hostname` browser 1920 1080 0 0' >> /usr/local/bin/browser.sh
    chmod +x /usr/local/bin/browser.sh
    
    echo '#!/bin/sh' > /usr/local/bin/move_browser.sh
    echo >> /usr/local/bin/move_browser.sh
    echo 'POS_X=0' >> /usr/local/bin/move_browser.sh
    echo 'POS_Y=0' >> /usr/local/bin/move_browser.sh
    echo 'SIZE_X=1920' >> /usr/local/bin/move_browser.sh
    echo 'SIZE_Y=1080' >> /usr/local/bin/move_browser.sh
    echo >> /usr/local/bin/move_browser.sh
    echo 'WINDOW_ID=' >> /usr/local/bin/move_browser.sh
    echo 'while [ -z "$WINDOW_ID" ]; do' >> /usr/local/bin/move_browser.sh
    echo -n '  WINDOW_ID=`xwininfo -name browser 2>/dev/null | grep "Window id" | awk ' >> /usr/local/bin/move_browser.sh
    echo -n "'" >> /usr/local/bin/move_browser.sh
    echo -n '{print $4}' >> /usr/local/bin/move_browser.sh
    echo -n "'" >> /usr/local/bin/move_browser.sh
    echo '`' >> /usr/local/bin/move_browser.sh
    echo 'done' >> /usr/local/bin/move_browser.sh
    echo >> /usr/local/bin/move_browser.sh
    echo 'xdotool set_window --overrideredirect 1 $WINDOW_ID windowunmap $WINDOW_ID windowmap $WINDOW_ID' >> /usr/local/bin/move_browser.sh
    echo >> /usr/local/bin/move_browser.sh
    echo "# try this three times to ensure window doesn't move again:" >> /usr/local/bin/move_browser.sh
    echo 'for i in $(seq 1 3); do' >> /usr/local/bin/move_browser.sh
    echo '  CUR_POS=' >> /usr/local/bin/move_browser.sh
    echo '  CUR_SIZE=' >> /usr/local/bin/move_browser.sh
    echo '  while [ "${POS_X},${POS_Y}" != "$CUR_POS" -o "${SIZE_X}x${SIZE_Y}" != "$CUR_SIZE" ]; do' >> /usr/local/bin/move_browser.sh
    echo '    xdotool windowmove $WINDOW_ID $POS_X $POS_Y windowsize $WINDOW_ID $SIZE_X $SIZE_Y' >> /usr/local/bin/move_browser.sh
    echo '    sleep 1' >> /usr/local/bin/move_browser.sh
    echo -n '    CUR_POS=`xdotool getwindowgeometry $WINDOW_ID | grep Position | awk ' >> /usr/local/bin/move_browser.sh
    echo -n "'" >> /usr/local/bin/move_browser.sh
    echo -n '{print $2}' >> /usr/local/bin/move_browser.sh
    echo -n "'" >> /usr/local/bin/move_browser.sh
    echo '`' >> /usr/local/bin/move_browser.sh
    echo -n '    CUR_SIZE=`xdotool getwindowgeometry $WINDOW_ID | grep Geometry | awk ' >> /usr/local/bin/move_browser.sh
    echo -n "'" >> /usr/local/bin/move_browser.sh
    echo -n '{print $2}' >> /usr/local/bin/move_browser.sh
    echo -n "'" >> /usr/local/bin/move_browser.sh
    echo '`' >> /usr/local/bin/move_browser.sh
    echo '  done' >> /usr/local/bin/move_browser.sh
    echo '  sleep 2' >> /usr/local/bin/move_browser.sh
    echo 'done' >> /usr/local/bin/move_browser.sh
    chmod +x /usr/local/bin/move_browser.sh
    
    echo '[Unit]' > /etc/systemd/system/browser.service
    echo 'Description=Web Browser' >> /etc/systemd/system/browser.service
    echo 'After=startx@display.service network.target' >> /etc/systemd/system/browser.service
    echo 'Requires=startx@display.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=display' >> /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 >> /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
    
    systemctl start browser
  • convenience shortcuts:
    echo '#!/bin/sh' > /usr/local/sbin/display_off.sh
    echo "su -s /bin/sh display -c 'DISPLAY=:0 xset dpms force off'" >> /usr/local/sbin/display_off.sh
    chmod +x /usr/local/sbin/display_off.sh
    
    echo '#!/bin/sh' > /usr/local/sbin/display_on.sh
    echo "su -s /bin/sh display -c 'DISPLAY=:0 xset dpms force on'" >> /usr/local/sbin/display_on.sh
    chmod +x /usr/local/sbin/display_on.sh

on 205.215.88.172

power control ideas:

new:
/usr/local/bin/handle_display_power.sh:
#!/bin/sh

power=`cat ~display/power.txt`

case "$power" in
  "on")
    xset dpms force on && echo turned display on
    ;;
  "off")
    xset dpms force off && echo turned display off
    ;;
  *)
    echo invalid power state specified
    exit 1
esac


(then add systemd path unit to trigger this to run when file is changed, plus run manually when starting X)



old
/usr/local/bin/display-state.sh:
#!/bin/sh

[ "display" != "$USER" ] && exec sudo -u display $0 "$@"

STATE=`DISPLAY=:0 xset q | grep 'Monitor is' | sed 's/.*Monitor is //g' | tr '[A-Z]' '[a-z]'`
REQUEST=`echo $1 | tr '[A-Z]' '[a-z]'`

if [ "$#" -ne 1 ]
then
  echo $STATE
elif [ "$STATE" != "$REQUEST" ]
then
  DISPLAY=:0 xset dpms force $REQUEST
fi


(also reads back display state, which is handy)
computer/hallway_display_renderer.txt · Last modified: 2016/08/28 02:57 by tdobes
Recent changes RSS feed Driven by DokuWiki Valid XHTML 1.0 Valid CSS