diff --git a/home/.bash_profile b/home/.bash_profile new file mode 100644 index 0000000..df3fa39 --- /dev/null +++ b/home/.bash_profile @@ -0,0 +1,6 @@ +#!/bin/bash + +# If this is a tty, and the one where we want to run X, do so +if [ "$(tty)" == "/dev/tty1" ]; then + exec startx +fi diff --git a/home/.chilipie-kiosk-version b/home/.chilipie-kiosk-version index 7dafe5b..c56a7c0 100644 --- a/home/.chilipie-kiosk-version +++ b/home/.chilipie-kiosk-version @@ -1,3 +1,3 @@ -v1.2.1 +v2.0.0-dev # https://github.com/futurice/chilipie-kiosk diff --git a/home/.xsession b/home/.xsession index e360328..a18eebe 100755 --- a/home/.xsession +++ b/home/.xsession @@ -1,13 +1,34 @@ #!/bin/bash -xset s off # don't activate screensaver -xset -dpms # disable DPMS (Energy Star) features. -xset s noblank # don't blank the video device +# Start cursor at the top-left corner, as opposed to the default of dead-center +# (so it doesn't accidentally trigger hover styles on elements on the page) +DISPLAY=:0.0 xdotool mousemove 0 0 -unclutter -idle 5 -root & # hide cursor afer 5 seconds of inactivity +# Set some useful X preferences +xset s off # don't activate screensaver +xset -dpms # disable DPMS (Energy Star) features. +xset s noblank # don't blank the video device -~/on-pi-startup.sh & # start our default application +# Set X screen background +sudo nitrogen --set-centered background.png -sudo nitrogen --set-centered background.png # set X screen background +# Hide cursor afer 5 seconds of inactivity +unclutter -idle 5 -root & -exec matchbox-window-manager -use_titlebar no # switch to our window manager +# Make sure Chromium profile is marked clean, even if it crashed +if [ -f .config/chromium/Default/Preferences ]; then + cat .config/chromium/Default/Preferences \ + | jq '.profile.exit_type = "SessionEnded" | .profile.exited_cleanly = true' \ + > .config/chromium/Default/Preferences-clean + mv .config/chromium/Default/Preferences{-clean,} +fi + +# Remove notes of previous sessions, if any +find .config/chromium/ -name "Last *" | xargs rm + +# Start and detach Chromium +# http://peter.sh/experiments/chromium-command-line-switches/ +chromium-browser --start-fullscreen --disable-infobars & + +# Finally, switch process to our window manager +exec matchbox-window-manager -use_titlebar no diff --git a/home/crontab.example b/home/crontab.example new file mode 100644 index 0000000..c317818 --- /dev/null +++ b/home/crontab.example @@ -0,0 +1,9 @@ +# m h dom mon dow command + +# 0 7 * * 1-5 ~/display-on.sh # turn display on weekdays at 7 AM +# 0 19 * * 1-5 ~/display-off.sh # turn display off weekdays at 7 PM + +0 3 * * * sudo reboot # reboot the pi every night at 3 AM + +# * * * * * DISPLAY=:0.0 xdotool key ctrl+R +* * * * * DISPLAY=:0.0 xdotool key ctrl+Tab diff --git a/home/display-on.sh b/home/display-on.sh index 572f20b..6bdf0a6 100755 --- a/home/display-on.sh +++ b/home/display-on.sh @@ -1,3 +1,3 @@ #!/bin/bash -sudo tvservice -p > /dev/null && sudo chvt 1 && sudo chvt 8 # for whatever reason, cycling virtual terminals helps wake up the display in some cases +sudo tvservice -p > /dev/null && sudo chvt 2 && sudo chvt 1 # for whatever reason, cycling virtual terminals helps wake up the display in some cases diff --git a/home/on-pi-startup.sh b/home/on-pi-startup.sh deleted file mode 100755 index f35850d..0000000 --- a/home/on-pi-startup.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# Make sure Chromium profile is marked clean, even if it crashed -# https://stedolan.github.io/jq/manual/ -if [ -f .config/chromium/Default/Preferences ]; then - cat .config/chromium/Default/Preferences \ - | jq '.profile.exit_type = "SessionEnded" | .profile.exited_cleanly = true' \ - > .config/chromium/Default/Preferences-clean - mv .config/chromium/Default/Preferences{-clean,} -fi - -# Remove notes of previous sessions, if any -find .config/chromium/ -name "Last *" | xargs rm - -# http://peter.sh/experiments/chromium-command-line-switches/ -chromium-browser --start-fullscreen - -# If you need to run Chromium manually for whatever reason: -# $ DISPLAY=:0.0 chromium-browser & diff --git a/image-setup.md b/image-setup.md index 48d5eeb..66fee5b 100644 --- a/image-setup.md +++ b/image-setup.md @@ -2,101 +2,72 @@ ## Baseline setup -Replace `$TAG` with whatever version is being built, e.g. `v1.2.1`. +Replace `$TAG` with whatever version is being built, e.g. `v2.0.0`. -1. Flash your SD card (assuming OS X): - 1. Get [Ubuntu MATE 16.04](https://ubuntu-mate.org/raspberry-pi/) and decompress into an `.img` file - 1. `$ diskutil list` to check correct device - 1. `$ diskutil unmountDisk /dev/disk2` to prepare it for imaging - 1. `$ sudo dd bs=1m if=ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img of=/dev/rdisk2` (will take a while) -1. Boot your Raspberry Pi using the SD card (the setup should be done on a Pi 3, but the resulting image will work on Pi 2 as well) -1. Answer basic questions (timezone, keyboard layout, default user, etc) - 1. Set hostname to `chilipie-kiosk` - 1. Set username/password to `pi:raspberry` (or whatever you want) - 1. Log in automatically after boot -1. At this point you can already SSH onto the Pi and do the rest of the setup remotely -1. `$ sudo visudo` and add `pi ALL=(ALL) NOPASSWD: ALL` to allow sudo without password prompt -1. Disable MATE's default desktop with `$ sudo graphical disable` (though later nodm will boot directly to matchbox anyway) -1. Clean up MATE's desktop cruft with `$ rm -rf ~/*` -1. Remove some packages we don't need: `$ sudo apt-get purge -y $(dpkg --get-selections 'sonic*' 'thunderbird*' 'libreoffice*' 'minecraft*' 'scratch*' 'shotwell*' 'simple-scan*' 'hexchat*' 'pidgin*' 'transmission*' 'youtube-dl*' 'atril*' 'idle*' 'brasero*' 'omxplayer*' 'rhythmbox*' 'supercollider*' 'vlc*' | cut -f 1 | tr '\n' ' ')` -1. Install some packages we'll need: `$ sudo apt-get update && sudo apt-get install -y vim nodm matchbox-window-manager unclutter mailutils nitrogen jq` - * When mailutils prompts about its setup, "local only" is fine (we install mailutils so that you can check `mail` for cronjob output) -1. For the time being, the Chromium from Ubuntu repo's [keeps segfaulting](https://ubuntu-mate.community/t/chromium-crashes-when-starting-segfaults/4578/27), so use the [alternate installation method](https://ubuntu-mate.community/t/tutorial-install-working-chromium-50/6762) instead of installing the `chromium-browser` package directly -1. Remove unnecessary packages with `$ sudo apt-get autoremove -y && sudo apt-get clean` -1. Make sure [automatic software updates are disabled](http://ask.xmodulo.com/disable-automatic-updates-ubuntu.html), in `/etc/apt/apt.conf.d/10periodic`: - - APT::Periodic::Unattended-Upgrade "0"; - APT::Periodic::Update-Package-Lists "0"; - APT::Periodic::Download-Upgradeable-Packages "0"; - APT::Periodic::AutocleanInterval "0"; - -1. In `/etc/default/nodm`, set: - - NODM_ENABLED=true - NODM_USER=pi - NODM_FIRST_VT=8 - -1. In `/usr/share/plymouth/themes/ubuntu-mate-text/ubuntu-mate-text.plymouth`, set: - - [ubuntu-text] - title=chilipie-kiosk - black=0x000000 - -1. In `/usr/share/plymouth/themes/ubuntu-mate-logo/ubuntu-mate-logo.script`, set: - - Window.SetBackgroundTopColor (0, 0, 0); - Window.SetBackgroundBottomColor (0, 0, 0); - -1. Replace the Plymouth theme logos with `$ cd /usr/share/plymouth/themes/ubuntu-mate-logo && sudo rm ubuntu-mate-logo{,16}.png && sudo ln -s /home/pi/background.png ubuntu-mate-logo.png && sudo ln -s /home/pi/background.png ubuntu-mate-logo16.png` -1. Check that the version in `.chilipie-kiosk-version` matches `$TAG`, and it's on GitHub -1. Get default scripts with `$ wget "https://github.com/futurice/chilipie-kiosk/archive/master.zip" && unzip master.zip && cp -v $(find chilipie-kiosk-master/home/ -type f) . && rm -rf chilipie-kiosk-master/ master.zip` -1. Put in the example crontab with `$ crontab -e`: - - # m h dom mon dow command - - # 0 7 * * 1-5 ~/display-on.sh # turn display on weekdays at 7 AM - # 0 19 * * 1-5 ~/display-off.sh # turn display off weekdays at 7 PM - -1. Disable overscan for HDMI output (as this is rarely needed on modern displays) by uncommenting `disable_overscan=1` in `/boot/config.txt` -1. Set up WiFi (for Raspberry Pi 3 only): - 1. Check the interface name with `$ ifconfig`, e.g. `wlan0` - 1. Append to `/etc/network/interfaces`: - - ``` - # Internal WiFi adapter - allow-hotplug wlan0 - iface wlan0 inet dhcp - wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf - iface default inet dhcp - ``` - - 1. In `/etc/wpa_supplicant/wpa_supplicant.conf`: - - ``` - network={ - # Your network name goes here: - ssid="networkname" - # EITHER: uncomment this for a password-protected WLAN: - #psk="secretpassword" - # OR: uncomment this for an unprotected WLAN: - #key_mgmt=NONE - } - ``` - - 1. Symlink the file, for convenience: `$ ln -s /etc/wpa_supplicant/wpa_supplicant.conf wlan.conf` - -1. Disable SSH access (because the default credentials aren't very secure): `$ sudo systemctl disable ssh.service` -1. Reboot (should land you in Chromium) -1. Tell Chromium "Don't ask again" about being the default browser -1. Configure Chromium to start from "where you left off", and navigate to https://github.com/futurice/chilipie-kiosk/blob/$TAG/first-boot.md -1. Unpower the Pi +1. Check that the version in `.chilipie-kiosk-version` matches `$TAG`, and it's on GitHub +1. Get Raspbian Lite (`2018-06-27-raspbian-stretch-lite.zip`) +1. Flash it onto an SD card (use [Etcher](https://etcher.io) or `dd`) +1. Re-mount the card +1. Update the file `/Volumes/boot/cmdline.txt` on the card: + ```diff + -dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=4d3ee428-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh + +dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=4d3ee428-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet + ``` +1. Boot your Pi from the SD card +1. Run `sudo raspi-config` and: + 1. Set localization options + 1. Set hostname to `chilipie-kiosk` + 1. Join a WiFi (if wired network isn't available for setup) + 1. Enable SSH + 1. Set automatic CLI login after boot +1. At this point you can already SSH onto the Pi and do the rest of the setup remotely +1. [Resize the root partition](https://elinux.org/RPi_Resize_Flash_Partitions#Manually_resizing_the_SD_card_on_Raspberry_Pi) to make space for additional software + 1. `sudo fdisk /dev/mmcblk0` + 1. `p` + 1. Make note of the "Start" value of the 2nd partition (e.g. `98304`) + 1. `d` + 1. `2` + 1. `n` + 1. `p` + 1. `2` + 1. For "First sector", enter the "Start" value from above (e.g. `98304`) + 1. For "Last sector", enter `+3G` + 1. If asked if you want to remove the existing "ext4" signature, say `y` + 1. `w` + 1. `sudo shutdown -r now` + 1. `sudo resize2fs /dev/mmcblk0p2` + 1. `df -h` +1. Install some packages we'll need: `sudo apt-get update && sudo apt-get install -y vim matchbox-window-manager unclutter mailutils nitrogen jq chromium-browser xserver-xorg xinit rpd-plym-splash` + - If `nodm` prompts whether it should be enabled by default, say "yes" + - TODO TODO TODO: nodm NOT NEEDED ANYMORE? + - If mailutils prompts about its setup, "local only" is fine (we install mailutils so that you can check `mail` for cronjob output) +1. Disable overscan (as it's rarely needed on modern displays) in `/boot/config.txt` with: + ```diff + -#disable_overscan=1 + +disable_overscan=1 + ``` +1. Get default scripts with `wget "https://github.com/futurice/chilipie-kiosk/archive/master.zip" && unzip master.zip && cp -v $(find chilipie-kiosk-master/home/ -type f) . && rm -rf chilipie-kiosk-master/ master.zip` +1. [Customize Plymouth boot theme](https://scribles.net/customizing-boot-up-screen-on-raspberry-pi/): + 1. `sudo cp background.png /usr/share/plymouth/themes/pix/splash.png` + 1. In `/boot/config.txt`, append `disable_splash=1` + 1. In `/boot/cmdline.txt`: + ```diff + -TODO + +dwc_otg.lpm_enable=0 console=serial0,115200 console=tty3 root=PARTUUID=4d3ee428-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash quiet plymouth.ignore-serial-consoles logo.nologo vt.global_cursor_default=0 + ``` +1. Put in the example crontab with `crontab crontab.example` +1. Disable SSH access again (because the default credentials aren't very secure) with `sudo raspi-config` +1. Reboot (should land you in Chromium) +1. Tell Chromium "Don't ask again" about being the default browser +1. Configure Chromium to start from "where you left off", and navigate to https://github.com/futurice/chilipie-kiosk/blob/$TAG/first-boot.md +1. Unpower the Pi ## Dumping the image Assuming OS X: -1. `$ diskutil list` to check correct device -1. `$ diskutil unmountDisk /dev/disk2` to prepare it for imaging -1. `$ sudo dd bs=1m count=7680 if=/dev/disk2 of=chilipie-kiosk-$TAG.img` (only dump the relevant first ~8 GB, matching the original `ubuntu-mate` image size; takes around 15 minutes) -1. `$ COPYFILE_DISABLE=1 tar -zcvf chilipie-kiosk-$TAG.img.tar.gz chilipie-kiosk-$TAG.img` -1. `$ openssl sha1 chilipie-kiosk-$TAG.img*` and include hash in release notes +1. `diskutil list` to check correct device +1. `diskutil unmountDisk /dev/disk3` to prepare it for imaging +1. `sudo dd bs=1m count=3500 if=/dev/disk3 of=chilipie-kiosk-$TAG.img` (only dump the relevant first ~4 GB; takes around 15 minutes) +1. `COPYFILE_DISABLE=1 tar -zcvf chilipie-kiosk-$TAG.img.tar.gz chilipie-kiosk-$TAG.img` +1. `openssl sha1 chilipie-kiosk-$TAG.img*` and include hash in release notes