|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Pi-hole: A black hole for Internet advertisements |
| 3 | +# (c) 2015 by Jacob Salmela |
| 4 | +# Network-wide ad blocking via your Raspberry Pi |
| 5 | +# http://pi-hole.net |
| 6 | +# Automatically configures the Pi to use the 2.8 LCD screen to display stats on it (also works over ssh) |
| 7 | +# |
| 8 | +# Pi-hole is free software: you can redistribute it and/or modify |
| 9 | +# it under the terms of the GNU General Public License as published by |
| 10 | +# the Free Software Foundation, either version 2 of the License, or |
| 11 | +# (at your option) any later version. |
| 12 | + |
| 13 | +############ FUNCTIONS ########### |
| 14 | +# Run this script as root or under sudo |
| 15 | +echo ":::" |
| 16 | +if [[ $EUID -eq 0 ]];then |
| 17 | + echo "::: You are root." |
| 18 | +else |
| 19 | + echo "::: sudo will be used." |
| 20 | + # Check if it is actually installed |
| 21 | + # If it isn't, exit because the install cannot complete |
| 22 | + if [[ $(dpkg-query -s sudo) ]];then |
| 23 | + export SUDO="sudo" |
| 24 | + else |
| 25 | + echo "::: Please install sudo or run this script as root." |
| 26 | + exit 1 |
| 27 | + fi |
| 28 | +fi |
| 29 | + |
| 30 | +# Borrowed from adafruit-pitft-helper < borrowed from raspi-config |
| 31 | +# https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L324-L334 |
| 32 | +getInitSys() { |
| 33 | + if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then |
| 34 | + SYSTEMD=1 |
| 35 | + elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then |
| 36 | + SYSTEMD=0 |
| 37 | + else |
| 38 | + echo "Unrecognised init system" |
| 39 | + return 1 |
| 40 | + fi |
| 41 | +} |
| 42 | + |
| 43 | +# Borrowed from adafruit-pitft-helper: |
| 44 | +# https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285 |
| 45 | +autoLoginPiToConsole() { |
| 46 | + if [ -e /etc/init.d/lightdm ]; then |
| 47 | + if [ $SYSTEMD -eq 1 ]; then |
| 48 | + $SUDO systemctl set-default multi-user.target |
| 49 | + $SUDO ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service |
| 50 | + else |
| 51 | + $SUDO update-rc.d lightdm disable 2 |
| 52 | + $SUDO sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/" |
| 53 | + fi |
| 54 | + fi |
| 55 | +} |
| 56 | + |
| 57 | +######### SCRIPT ########### |
| 58 | +# Set pi to log in automatically |
| 59 | +getInitSys |
| 60 | +autoLoginPiToConsole |
| 61 | + |
| 62 | +# Set chronomter to run automatically when pi logs in |
| 63 | +echo /usr/local/bin/chronometer.sh >> /home/pi/.bashrc |
| 64 | +# OR |
| 65 | +#$SUDO echo /usr/local/bin/chronometer.sh >> /etc/profile |
| 66 | + |
| 67 | +# Set up the LCD screen based on Adafruits instuctions: |
| 68 | +# https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install |
| 69 | +curl -SLs https://apt.adafruit.com/add-pin | $SUDO bash |
| 70 | +$SUDO apt-get -y install raspberrypi-bootloader |
| 71 | +$SUDO apt-get -y install adafruit-pitft-helper |
| 72 | +$SUDO adafruit-pitft-helper -t 28r |
| 73 | + |
| 74 | +# Download the cmdline.txt file that prevents the screen from going blank after a period of time |
| 75 | +$SUDO mv /boot/cmdline.txt /boot/cmdline.orig |
| 76 | +$SUDO curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt |
| 77 | + |
| 78 | +# Back up the original file and download the new one |
| 79 | +$SUDO mv /etc/default/console-setup /etc/default/console-setup.orig |
| 80 | +$SUDO curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup |
| 81 | + |
| 82 | +# Instantly apply the font change to the LCD screen |
| 83 | +$SUDO setupcon |
| 84 | + |
| 85 | +$SUDO reboot |
| 86 | + |
| 87 | +# Start showing the stats on the screen by running the command on another tty: |
| 88 | +# http://unix.stackexchange.com/questions/170063/start-a-process-on-a-different-tty |
| 89 | +#setsid sh -c 'exec /usr/local/bin/chronometer.sh <> /dev/tty1 >&0 2>&1' |
0 commit comments