Raspberry Pi - Timeclock v2

General setup

  • run raspberrypi-ua-netinst on SD card (default install)
  • 1920×1200 monitor, speakers on analog 3.5mm out, USB keypad
  • SSH in as root…
passwd
> /etc/motd
echo rpi-timeclock-1 > /etc/hostname
sed -i s/pi/rpi-timeclock-1/g /etc/hosts
echo "America/Chicago" > /etc/timezone
ln -sf /usr/share/zoneinfo/America/Chicago /etc/localtime
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
apt-get update
apt-get --no-install-recommends install aptitude
aptitude full-upgrade

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

aptitude install firmware-brcm80211 # for rpi3 wifi

aptitude install watchdog
# no need to set watchdog module in /etc/default/watchdog (compiled into kernel)
sed -i 's/dtparam=audio=on/dtparam=audio=on\n\ndtparam=watchdog=on/g' /boot/config.txt
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

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

Xorg, Timeclock, and Browser software

aptitude install xserver-xorg-video-fbturbo xserver-xorg-input-libinput
aptitude install xinit evilwm xdotool x11vnc unclutter x11-xserver-utils

aptitude --without-recommends install python-pyside.qtwebkit
# x11-apps for xclock, python-psycopg2 for database connection, libjpeg-progs to rotate JPEG images, alsa-utils for aplay
aptitude install x11-apps python-psycopg2 libjpeg-progs alsa-utils

sed -i 's/#dtparam=audio=on/dtparam=audio=on/g' /boot/config.txt

adduser --shell /bin/false --gecos "MCP Timeclock" --disabled-password timeclock

# for SFX:
adduser timeclock audio
adduser tdobes audio # for troubleshooting

systemctl start alsa-restore.service
amixer sset PCM 0
systemctl restart alsa-restore.service

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

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

mkdir ~timeclock/.vnc
x11vnc -storepasswd **PASSWORD** ~timeclock/.vnc/passwd
chown -R timeclock:timeclock ~timeclock/.vnc
chmod 0600 ~timeclock/.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 timeclock evilwm' >> /etc/systemd/system/startx.service
echo 'User=timeclock' >> /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/timeclock-vnc.service
echo 'Description=VNC Server' >> /etc/systemd/system/timeclock-vnc.service
echo 'After=startx.service' >> /etc/systemd/system/timeclock-vnc.service
echo 'Requires=startx.service' >> /etc/systemd/system/timeclock-vnc.service
echo >> /etc/systemd/system/timeclock-vnc.service
echo '[Service]' >> /etc/systemd/system/timeclock-vnc.service
echo 'ExecStart=/usr/bin/x11vnc -q -usepw -N -ncache 0 -shared -forever' >> /etc/systemd/system/timeclock-vnc.service
echo 'User=timeclock' >> /etc/systemd/system/timeclock-vnc.service
echo 'Environment=DISPLAY=:0' >> /etc/systemd/system/timeclock-vnc.service
echo 'Restart=always' >> /etc/systemd/system/timeclock-vnc.service
echo 'RestartSec=1' >> /etc/systemd/system/timeclock-vnc.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/timeclock-vnc.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/timeclock-vnc.service
echo >> /etc/systemd/system/timeclock-vnc.service
echo '[Install]' >> /etc/systemd/system/timeclock-vnc.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/timeclock-vnc.service
systemctl enable timeclock-vnc.service

echo '#!/bin/sh' > /usr/local/bin/browser.sh
echo >> /usr/local/bin/browser.sh
echo 'NETWORK_CHECK=database.mcp.lcl' >> /usr/local/bin/browser.sh
echo 'URL=http://database.mcp.lcl/timeclock/left2.php?computername=`hostname`' >> /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 1 1 windowsize 1278 920; do echo -n . ; sleep 1 ; done ; echo done!'"'"' &' >> /usr/local/bin/browser.sh # for old 4:3 monitor
echo 'sh -c '"'"'sleep 1 ; echo -n attempting to move simplebrowser ; while ! xdotool search --onlyvisible --name simplebrowser.py windowmove 1 1 windowsize 1918 1048; 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

echo '#!/bin/sh' > /usr/local/bin/timeclock-clock.sh
echo >> /usr/local/bin/timeclock-clock.sh
#echo 'sh -c '"'"'sleep 1 ; echo -n attempting to move xclock ; while ! xdotool search --name xclock windowmove 1019 987 ; do echo -n . ; sleep 1 ; done ; echo done!'"'"' &' >> /usr/local/bin/timeclock-clock.sh # for old 4:3 monitor
echo 'sh -c '"'"'sleep 1 ; echo -n attempting to move xclock ; while ! xdotool search --name xclock windowmove 1659 1163 ; do echo -n . ; sleep 1 ; done ; echo done!'"'"' &' >> /usr/local/bin/timeclock-clock.sh
echo 'exec xclock -digital -twelve -fg green -bg black -update 1' >> /usr/local/bin/timeclock-clock.sh
chmod +x /usr/local/bin/timeclock-clock.sh

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=timeclock' >> /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

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

echo '# Elan (new) keypads' > /etc/udev/rules.d/mcp-timeclock-keypad.rules
echo 'KERNEL=="event*", SUBSYSTEM=="input", SUBSYSTEMS=="usb", ATTRS{idVendor}=="04f3", ATTRS{idProduct}=="0635", GROUP="timeclock", MODE="0660"' >> /etc/udev/rules.d/mcp-timeclock-keypad.rules
echo '# Old keypads' >> /etc/udev/rules.d/mcp-timeclock-keypad.rules
echo 'KERNEL=="event*", SUBSYSTEM=="input", SUBSYSTEMS=="usb", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a02a", GROUP="timeclock", MODE="0660"' >> /etc/udev/rules.d/mcp-timeclock-keypad.rules

systemctl disable rsyslog.service
systemctl disable rsync.service
systemctl disable sshswitch.service
systemctl stop 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

sed -i 's/^.*$/& quiet/' /boot/cmdline.txt
echo >> /boot/config.txt
echo disable_splash=1 >> /boot/config.txt


###  copy timeclock code to /opt/timeclock/
rsync -aix rpi-timeclock-1:/opt/timeclock /opt/
###  copy ssh key and known_hosts files to /home/timeclock/.ssh/
rsync -aix rpi-timeclock-1:/home/timeclock/.ssh /home/timeclock/


echo '#!/bin/sh' > /usr/local/bin/timeclock-gui.sh
echo >> /usr/local/bin/timeclock-gui.sh
echo 'echo -n waiting for network/server' >> /usr/local/bin/timeclock-gui.sh
echo 'while ! ping -c 1 database.mcp.lcl > /dev/null 2> /dev/null ; do' >> /usr/local/bin/timeclock-gui.sh
echo '  echo -n .' >> /usr/local/bin/timeclock-gui.sh
echo '  sleep 1' >> /usr/local/bin/timeclock-gui.sh
echo 'done' >> /usr/local/bin/timeclock-gui.sh
echo 'echo done!' >> /usr/local/bin/timeclock-gui.sh
echo >> /usr/local/bin/timeclock-gui.sh
echo '# move the window to appropriate location, then move mouse' >> /usr/local/bin/timeclock-gui.sh
#echo 'sh -c '"'"'sleep 1 ; echo -n attempting to find timeclock gui ; while ! xdotool search --name "MCP TimeClock" ; do echo -n . ; sleep 1 ; done ; xdotool mousemove 0 0 ; xdotool mousemove 860 1004 ; sleep 1 ; xdotool search --name "MCP TimeClock" windowactivate ; echo done!'"'"' &' >> /usr/local/bin/timeclock-gui.sh # old 4:3 monitor
echo 'sh -c '"'"'sleep 1 ; echo -n attempting to find timeclock gui ; while ! xdotool search --name "MCP TimeClock" ; do echo -n . ; sleep 1 ; done ; xdotool mousemove 1 1 ; xdotool mousemove 140 1100 ; sleep 1 ; xdotool search --name "MCP TimeClock" windowactivate ; echo done!'"'"' &' >> /usr/local/bin/timeclock-gui.sh
echo >> /usr/local/bin/timeclock-gui.sh
echo '# start timeclock gui' >> /usr/local/bin/timeclock-gui.sh
echo 'exec /opt/timeclock/timeclock-gui.py' >> /usr/local/bin/timeclock-gui.sh
chmod +x /usr/local/bin/timeclock-gui.sh

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

echo $'\tpost-up /bin/systemctl restart browser.service timeclock-gui.service' >> /etc/network/interfaces
computer/raspberry_pi_timeclock_v2.txt · Last modified: 2018/04/07 23:15 by tdobes
Recent changes RSS feed Driven by DokuWiki Valid XHTML 1.0 Valid CSS