Raspberry Pi - Slideshow v2

passwd
> /etc/motd

hostname rpi-slideshow1 # update as necessary
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 --without-recommends install feh

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 "Slideshow" --disabled-password slideshow


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

mkdir ~slideshow/.vnc
x11vnc -storepasswd **PASSWORD** ~slideshow/.vnc/passwd
chown -R slideshow:slideshow ~slideshow/.vnc
chmod 0600 ~slideshow/.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 slideshow evilwm' >> /etc/systemd/system/startx.service
echo 'User=slideshow' >> /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=slideshow' >> /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/slideshow.service
echo 'Description=slideshow' >> /etc/systemd/system/slideshow.service
echo 'After=startx.service' >> /etc/systemd/system/slideshow.service
echo 'Requires=startx.service' >> /etc/systemd/system/slideshow.service
echo >> /etc/systemd/system/slideshow.service
echo '[Service]' >> /etc/systemd/system/slideshow.service
echo 'ExecStart=-/usr/bin/feh -F -D 7 -S filename -Y' >> /etc/systemd/system/slideshow.service
echo 'WorkingDirectory=/opt/pictures' >> /etc/systemd/system/slideshow.service
echo 'Nice=1' >> /etc/systemd/system/slideshow.service
echo 'User=slideshow' >> /etc/systemd/system/slideshow.service
echo 'Environment=DISPLAY=:0' >> /etc/systemd/system/slideshow.service
echo 'Restart=always' >> /etc/systemd/system/slideshow.service
echo 'RestartSec=1' >> /etc/systemd/system/slideshow.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/slideshow.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/slideshow.service
echo >> /etc/systemd/system/slideshow.service
echo '[Install]' >> /etc/systemd/system/slideshow.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/slideshow.service

systemctl enable slideshow.service

ssh-keygen
** press enter for default location, then press enter twice for no passphrase
# before running this, temporarily set PermitRootLogin to yes in /etc/ssh/sshd_config on ds-storage
cat ~/.ssh/id_rsa.pub | ssh ds-storage.mcp.lcl "mkdir -p ~slideshow/.ssh && chmod 0700 ~slideshow/.ssh && cat >> ~slideshow/.ssh/authorized_keys && chown -R slideshow:slideshow ~slideshow/.ssh"
# now that you're done, put the file back to its original state on ds-storage

mkdir -p /opt/pictures
rsync -rltvi --del slideshow@ds-storage.mcp.lcl:/mnt/digitalsky/waiting-slideshows/`hostname`/ /opt/pictures/
chown -R tdobes:slideshow /opt/pictures
chmod 0755 /opt/pictures
chmod 0644 /opt/pictures/*



echo '#!/bin/sh' > /usr/local/bin/sync_images.sh
echo >> /usr/local/bin/sync_images.sh
echo 'pidfile=/var/run/sync_images.pid' >> /usr/local/bin/sync_images.sh
echo 'server=ds-storage.mcp.lcl' >> /usr/local/bin/sync_images.sh
echo 'source=slideshow@$server:/mnt/digitalsky/waiting-slideshows/`hostname`/' >> /usr/local/bin/sync_images.sh
echo 'dest=/opt/pictures/' >> /usr/local/bin/sync_images.sh
echo >> /usr/local/bin/sync_images.sh
echo 'if [ -e $pidfile ] && kill -0 `cat $pidfile` 2>/dev/null; then' >> /usr/local/bin/sync_images.sh
echo '  echo '"'"'WARNING: sync_images is still running!'"'" >> /usr/local/bin/sync_images.sh
echo '  exit 1' >> /usr/local/bin/sync_images.sh
echo 'else' >> /usr/local/bin/sync_images.sh
echo '  trap "rm -f $pidfile; exit" INT TERM EXIT' >> /usr/local/bin/sync_images.sh
echo '  echo $$ > $pidfile' >> /usr/local/bin/sync_images.sh
echo 'fi' >> /usr/local/bin/sync_images.sh
echo >> /usr/local/bin/sync_images.sh
echo 'if ! ping -c 1 $server > /dev/null 2> /dev/null; then' >> /usr/local/bin/sync_images.sh
echo '  echo -n Waiting for network/server.' >> /usr/local/bin/sync_images.sh
echo '  while ! ping -c 1 $server > /dev/null 2> /dev/null; do' >> /usr/local/bin/sync_images.sh
echo '    echo -n .' >> /usr/local/bin/sync_images.sh
echo '    sleep 1' >> /usr/local/bin/sync_images.sh
echo '  done' >> /usr/local/bin/sync_images.sh
echo '  echo Done!' >> /usr/local/bin/sync_images.sh
echo 'fi' >> /usr/local/bin/sync_images.sh
echo >> /usr/local/bin/sync_images.sh
echo 'while ! files=`rsync -rlti --del $source $dest | wc -l`; do' >> /usr/local/bin/sync_images.sh
echo "  echo 'Sync attempt interrupted; retrying...'" >> /usr/local/bin/sync_images.sh
echo 'done' >> /usr/local/bin/sync_images.sh
echo >> /usr/local/bin/sync_images.sh
echo 'if [ $files -gt 0 ]; then' >> /usr/local/bin/sync_images.sh
echo '  chown -R tdobes:slideshow $dest' >> /usr/local/bin/sync_images.sh
echo '  systemctl --no-block try-restart slideshow.service' >> /usr/local/bin/sync_images.sh
echo 'fi' >> /usr/local/bin/sync_images.sh
echo >> /usr/local/bin/sync_images.sh
echo 'rm $pidfile' >> /usr/local/bin/sync_images.sh
echo 'trap - INT TERM EXIT' >> /usr/local/bin/sync_images.sh
chmod +x /usr/local/bin/sync_images.sh

echo '@reboot root /usr/local/bin/sync_images.sh' > /etc/cron.d/sync_images
echo '30 * * * * root /usr/local/bin/sync_images.sh' >> /etc/cron.d/sync_images

# DVI mode, 1280x1024@60 Hz, no overscan - 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=35\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
computer/raspberry_pi_slideshow_v2.txt · Last modified: 2019/01/05 14:58 by tdobes
Recent changes RSS feed Driven by DokuWiki Valid XHTML 1.0 Valid CSS