Spectro installer, plus other minor fixes

This commit is contained in:
Phillip Burgess 2020-01-16 20:27:46 -08:00
parent 204d71afc7
commit fb2b5ccf27
4 changed files with 224 additions and 260 deletions

View file

@ -133,7 +133,6 @@ reconfig2() {
else
# Not found; append to line (silently)
sed -i "s/$/ $3/g" $1 >/dev/null
fi
}
@ -226,7 +225,7 @@ if [ $SCREEN_SELECT -ne 4 ]; then
sed -i "s/^.*fbx2.*$/\/boot\/Pi_Eyes\/fbx2 $SCREEN_OPT \&/g" /etc/rc.local >/dev/null
else
# Insert fbx2 into rc.local before final 'exit 0'
sed -i "s/^exit 0/\/boot\/Pi_Eyes\/fbx2 $SCREEN_OPT \&\\nexit 0/g" /etc/rc.local >/dev/null
sed -i "s/^exit 0/\/boot\/Pi_Eyes\/fbx2 $SCREEN_OPT \&\\nexit 0/g" /etc/rc.local >/dev/null
fi
RADIUS=${RADIUS_VALUES[($SCREEN_SELECT-1)]}

View file

@ -47,7 +47,6 @@ QUALITY_MOD=0
# Given a list of strings representing options, display each option
# preceded by a number (1 to N), display a prompt, check input until
# a valid number within the selection range is entered.
# Can we pass an array?
selectN() {
args=("${@}")
if [[ ${args[0]} = "0" ]]; then
@ -283,4 +282,4 @@ if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
fi
echo "Reboot started..."
reboot
exit 0
sleep infinity

View file

@ -1,220 +0,0 @@
#!/bin/bash
# INSTALLER SCRIPT FOR ADAFRUIT RGB MATRIX BONNET OR HAT
# hzeller/rpi-rgb-led-matrix sees lots of active development!
# That's cool and all, BUT, to avoid tutorial breakage,
# we reference a specific commit (update this as needed):
GITUSER=https://github.com/hzeller
REPO=rpi-rgb-led-matrix
COMMIT=58830f7bb5dfb47fc24f1fd26cd7c4e3a20f13f7
if [ $(id -u) -ne 0 ]; then
echo "Installer must be run as root."
echo "Try 'sudo bash $0'"
exit 1
fi
clear
echo "This script installs software for the Adafruit"
echo "RGB Matrix Bonnet or HAT for Raspberry Pi."
echo "Steps include:"
echo "- Update package index files (apt-get update)"
echo "- Install prerequisite software"
echo "- Install RGB matrix driver software"
echo "- Configure boot options"
echo "Run time ~10 minutes. Some options require reboot."
echo "EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN."
echo
echo -n "CONTINUE? [y/N] "
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled."
exit 0
fi
# FEATURE PROMPTS ----------------------------------------------------------
# Installation doesn't begin until after all user input is taken.
INTERFACE_TYPE=0
INSTALL_RTC=0
QUALITY_MOD=0
# Given a list of strings representing options, display each option
# preceded by a number (1 to N), display a prompt, check input until
# a valid number within the selection range is entered.
# Can we pass an array?
selectN() {
args=("${@}")
for ((i=0; i<$#; i++)); do
echo $((i+1)). ${args[$i]}
done
echo
REPLY=""
while :
do
echo -n "SELECT 1-$#: "
read
if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
return $REPLY
fi
done
}
OPTION_NAMES=(NO YES)
INTERFACES=( \
"Adafruit RGB Matrix Bonnet" \
"Adafruit RGB Matrix HAT + RTC" \
)
QUALITY_OPTS=( \
"Quality (disables sound, requires soldering)" \
"Convenience (sound on, no soldering)" \
)
echo
echo "Select interface board type:"
selectN "${INTERFACES[@]}"
INTERFACE_TYPE=$?
if [ $INTERFACE_TYPE -eq 2 ]; then
# For matrix HAT, ask about RTC install
echo
echo -n "Install realtime clock support? [y/N] "
read
if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
INSTALL_RTC=1
fi
fi
echo
echo "Now you must choose between QUALITY and CONVENIENCE."
echo
echo "QUALITY: best output from the LED matrix requires"
echo "commandeering hardware normally used for sound, plus"
echo "some soldering. If you choose this option, there will"
echo "be NO sound from the audio jack or HDMI (USB audio"
echo "adapters will work and sound best anyway), AND you"
echo "must SOLDER a wire between GPIO4 and GPIO18 on the"
echo "Bonnet or HAT board."
echo
echo "CONVENIENCE: sound works normally, no extra soldering."
echo "Images on the LED matrix are not quite as steady, but"
echo "maybe OK for most uses. If eager to get started, use"
echo "'CONVENIENCE' for now, you can make the change and"
echo "reinstall using this script later!"
echo
echo "What is thy bidding?"
selectN "${QUALITY_OPTS[@]}"
QUALITY_MOD=$?
# VERIFY SELECTIONS BEFORE CONTINUING --------------------------------------
echo
echo "Interface board type: ${INTERFACES[$INTERFACE_TYPE-1]}"
if [ $INTERFACE_TYPE -eq 2 ]; then
echo "Install RTC support: ${OPTION_NAMES[$INSTALL_RTC]}"
fi
echo "Optimize: ${QUALITY_OPTS[$QUALITY_MOD-1]}"
if [ $QUALITY_MOD -eq 1 ]; then
echo "Reminder: you must SOLDER a wire between GPIO4"
echo "and GPIO18, and internal sound is DISABLED!"
fi
echo
echo -n "CONTINUE? [y/N] "
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled."
exit 0
fi
# START INSTALL ------------------------------------------------------------
# All selections are validated at this point...
# Given a filename, a regex pattern to match and a replacement string,
# perform replacement if found, else append replacement to end of file.
# (# $1 = filename, $2 = pattern to match, $3 = replacement)
reconfig() {
grep $2 $1 >/dev/null
if [ $? -eq 0 ]; then
# Pattern found; replace in file
sed -i "s/$2/$3/g" $1 >/dev/null
else
# Not found; append (silently)
echo $3 | sudo tee -a $1 >/dev/null
fi
}
echo
echo "Starting installation..."
echo "Updating package index files..."
apt-get update
echo "Downloading prerequisites..."
apt-get install -y --force-yes python-dev python-imaging
echo "Downloading RGB matrix software..."
curl -L $GITUSER/$REPO/archive/$COMMIT.zip -o $REPO-$COMMIT.zip
unzip -q $REPO-$COMMIT.zip
rm $REPO-$COMMIT.zip
mv $REPO-$COMMIT rpi-rgb-led-matrix
echo "Building RGB matrix software..."
cd rpi-rgb-led-matrix
if [ $QUALITY_MOD -eq 1 ]; then
HARDWARE_DESC=adafruit-hat-pwm make
cd bindings/python
python setup.py install
else
HARDWARE_DESC=adafruit-hat make USER_DEFINES="-DDISABLE_HARDWARE_PULSES"
cd bindings/python
python setup.py install
fi
# Change ownership to user calling sudo
cd ../../..
chown -R $SUDO_USER:$(id -g $SUDO_USER) rpi-rgb-led-matrix
# CONFIG -------------------------------------------------------------------
echo "Configuring system..."
if [ $INSTALL_RTC -ne 0 ]; then
# Enable I2C for RTC
raspi-config nonint do_i2c 0
# Do additional RTC setup for DS1307
reconfig /boot/config.txt "^.*dtoverlay=i2c-rtc.*$" "dtoverlay=i2c-rtc,ds1307"
apt-get -y remove fake-hwclock
update-rc.d -f fake-hwclock remove
sudo sed --in-place '/if \[ -e \/run\/systemd\/system \] ; then/,+2 s/^#*/#/' /lib/udev/hwclock-set
fi
if [ $QUALITY_MOD -eq 1 ]; then
# Disable sound ('easy way' -- kernel module not blacklisted)
reconfig /boot/config.txt "^.*dtparam=audio.*$" "dtparam=audio=off"
else
# Enable sound (ditto)
reconfig /boot/config.txt "^.*dtparam=audio.*$" "dtparam=audio=on"
fi
# PROMPT FOR REBOOT --------------------------------------------------------
echo "Done."
echo
echo "Settings take effect on next boot."
if [ $INSTALL_RTC -ne 0 ]; then
echo "RTC will be enabled then but time must be set"
echo "up using the 'date' and 'hwclock' commands."
fi
echo
echo -n "REBOOT NOW? [y/N] "
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Exiting without reboot."
exit 0
fi
echo "Reboot started..."
reboot
exit 0

View file

@ -1,36 +1,27 @@
#!/bin/bash
# INSTALLER SCRIPT FOR ADAFRUIT SPECTRO PROJECT
if [ $(id -u) -ne 0 ]; then
echo "Installer must be run as root."
echo "Try 'sudo bash $0'"
exit 1
fi
if [ $PWD -ne /home/pi ]; then
echo "Script should be run from the /home/pi directory."
exit 2
fi
if [! -d ./rpi-rgb-led-matrix not present]; then
echo "Please run RGB matrix installer (rgb-matrix.sh) first."
exit 2
fi
clear
echo "This script installs software for the Adafruit"
echo "Spectro project for Raspberry Pi. Steps include:"
echo "Spectro project for Raspberry Pi."
echo "Steps include:"
echo "- Update package index files (apt-get update)"
echo "- Install Python libraries: python3-dev, python3-pil,"
echo " python3-rpi.gpio"
echo "- Download Adafruit Spectro directory in current"
echo " location (MUST be adjacent to rpi-rgb-led-matrix"
echo " directory in /home/pi)"
echo "- Set Spectro task-switch button (GPIO25) to run"
echo " on startup"
echo "RGB MATRIX INSTALLER (rgb-matrix.sh) MUST BE RUN FIRST."
echo "Run time <5 minutes. Reboot required."
echo "- Install prerequisite software"
echo "- Install Spectro software"
echo "- Configure hardware and boot options"
echo "Run time ~10 minutes."
echo
echo "EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN."
echo "If you've edited any Spectro-related files, cancel"
echo "the installation and back up those files first."
echo
echo -n "CONTINUE? [y/N] "
read
@ -39,35 +30,229 @@ if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
exit 0
fi
# FEATURE PROMPTS ----------------------------------------------------------
# Installation doesn't begin until after all user input is taken.
MATRIX_SIZE=0
SLOWDOWN_GPIO=0
ENABLE_MIC=0
ENABLE_ACCEL=0
HDMI_SIZE=0
OPTION_NAMES=(NO YES)
MATRIX_WIDTHS=(64 32)
MATRIX_HEIGHTS=(32 16)
SIZE_OPTS=( \
"${MATRIX_WIDTHS[0]} x ${MATRIX_HEIGHTS[0]}" \
"${MATRIX_WIDTHS[1]} x ${MATRIX_HEIGHTS[1]}" \
)
SLOWDOWN_OPTS=( \
"0" \
"1" \
"2" \
"3" \
"4" \
)
HDMI_OPTS=( \
"640x480" \
"320x240" \
)
# Given a list of strings representing options, display each option
# preceded by a number (1 to N), display a prompt, check input until
# a valid number within the selection range is entered.
selectN() {
args=("${@}")
# If first item in list is the literal number '0', make the list
# indexed from 0 rather than 1. This is to avoid confusion when
# entering the GPIO slowdown setting (e.g. entering '1' for a
# value of '0' is awkward). In all other cases, list is indexed
# from 1 as this is more human.
if [[ ${args[0]} = "0" ]]; then
OFFSET=0
else
OFFSET=1
fi
for ((i=0; i<$#; i++)); do
echo $((i+$OFFSET)). ${args[$i]}
done
echo
REPLY=""
let LAST=$#+$OFFSET-1
while :
do
echo -n "SELECT $OFFSET-$LAST: "
read
if [[ $REPLY -ge $OFFSET ]] && [[ $REPLY -le $LAST ]]; then
let RESULT=$REPLY-$OFFSET
return $RESULT
fi
done
}
echo
echo "What size LED matrix are you using with Spectro?"
selectN "${SIZE_OPTS[@]}"
MATRIX_SIZE=$?
echo
echo "Faster Pi boards require dialing back GPIO speed"
echo "to work with the LED matrix. For Raspberry Pi 4,"
echo "this usually means the max '4' slowdown setting."
echo "For early single-core boards, '0' will often"
echo "suffice. Try '1' or '2' for anything else. There's"
echo "no hard-set rule to this. If the Spectro display"
echo "is glitchy, just re-run this installer, selecting"
echo "a higher setting until you find a stable value."
echo "GPIO slowdown setting:"
selectN "${SLOWDOWN_OPTS[@]}"
SLOWDOWN_GPIO=$?
echo
echo -n "OPTIONAL: Enable USB microphone support? [y/N] "
read
if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
ENABLE_MIC=1
fi
echo
echo -n "OPTIONAL: Enable LIS3DH accelerometer support? [y/N] "
read
if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
ENABLE_ACCEL=1
fi
# HDMI resolution selection might be handled later; right now nothing
# requires it. But in the future if anything relies on fb2matrix.py,
# HDMI resolution ultimately determines the frame rate that's possible,
# flipside being that some monitors can't handle extremely low resolutions.
# So an option might be presented here, set to 320x240 or 640x480 (the
# latter being the minimum resolution some displays can support).
# VERIFY SELECTIONS BEFORE CONTINUING --------------------------------------
echo
echo "LED matrix size: ${SIZE_OPTS[$MATRIX_SIZE]}"
echo "GPIO slowdown: ${SLOWDOWN_OPTS[$SLOWDOWN_GPIO]}"
echo "Enable USB microphone support: ${OPTION_NAMES[$ENABLE_MIC]}"
echo "Enable LIS3DH support: ${OPTION_NAMES[$ENABLE_ACCEL]}"
#echo "HDMI resolution: ${HDMI_OPTS[$HDMI_SIZE]}"
echo
echo -n "CONTINUE? [y/N] "
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled."
exit 0
fi
# Check whether RGB matrix library is present.
# If not, offer to download and run that script first (then return here).
echo
echo "Updating package index files..."
apt-get update
apt-get -qq install python3-pip python-pip
echo -n "Checking for RGB matrix library..."
pip3 freeze | grep rgbmatrix > /dev/null
if [ $? -eq 0 ]; then
echo "OK."
else
echo "not present."
echo "Would you like to download and install the RGB matrix"
echo "library (required by Spectro) first? If so, DO NOT REBOOT"
echo "when prompted. Youll return to this script for more"
echo "Spectro configuration."
echo -n "Run RGB matrix installer? [y/N] "
read
if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/rgb-matrix.sh -O rgb-matrix.sh
bash rgb-matrix.sh
echo
echo "You are now back in the main Spectro installer script."
echo "When prompted about reboot again, now it's OK!"
fi
fi
# START INSTALL ------------------------------------------------------------
# All selections are validated at this point...
# Given a filename, a regex pattern to match and a replacement string,
# perform replacement if found, else append replacement to end of file.
# (# $1 = filename, $2 = pattern to match, $3 = replacement)
reconfig() {
grep $2 $1 >/dev/null
if [ $? -eq 0 ]; then
# Pattern found; replace in file
sed -i "s/$2/$3/g" $1 >/dev/null
else
# Not found; append (silently)
echo $3 | sudo tee -a $1 >/dev/null
fi
}
# Same as above, but skips if pattern not found
reconfig2() {
grep $2 $1 >/dev/null
if [ $? -eq 0 ]; then
# Pattern found; replace in file
sed -i "s/$2/$3/g" $1 >/dev/null
fi
}
echo
echo "Starting installation..."
echo "Updating package index files..."
apt-get update
echo "Installing Python libraries..."
apt-get install -y python3-dev python3-pil python3-rpi.gpio
# Although Spectro is all Python3-ready, user additions might rely on
# Python2, so we'll install the prerequisite libraries for both 2 and 3...
echo "Downloading prerequisites..."
pip3 install psutil
pip install psutil
apt-get install -y --force-yes python3-dev python3-pillow python2.7-dev python-pillow
if [ $ENABLE_MIC -ne 0 ]; then
apt-get install -y --force-yes python3-pyaudio python3-numpy python-pyaudio python-numpy
fi
if [ $ENABLE_ACCEL -ne 0 ]; then
pip3 install adafruit-circuitpython-busdevice adafruit-circuitpython-lis3dh
pip install adafruit-circuitpython-busdevice adafruit-circuitpython-lis3dh
fi
echo "Installing Adafruit code and data..."
cd /tmp
curl -LO https://github.com/adafruit/Adafruit_Spectro_Pi/archive/master.zip
unzip -o master.zip
mv Adafruit_Spectro_Pi-master /home/pi/Adafruit_Spectro_Pi
chown -R pi:pi /home/pi/Adafruit_Spectro_Pi
echo "Downloading Spectro software..."
curl -L https://github.com/adafruit/Adafruit_Spectro_Pi/archive/master.zip -o Adafruit_Spectro_Pi.zip
unzip -q -o Adafruit_Spectro_Pi.zip
rm Adafruit_Spectro_Pi.zip
mv Adafruit_Spectro_Pi-master Adafruit_Spectro_Pi
chown -R pi:pi Adafruit_Spectro_Pi
# CONFIG -------------------------------------------------------------------
echo "Configuring system..."
if [ $ENABLE_MIC -ne 0 ]; then
# Change ALSA settings to allow USB mic use
reconfig2 /usr/share/alsa/alsa.conf "^defaults.ctl.card.*0" "defaults.ctl.card 1"
reconfig2 /usr/share/alsa/alsa.conf "^defaults.pcm.card.*0" "defaults.pcm.card 1"
fi
if [ $ENABLE_ACCEL -ne 0 ]; then
# Enable I2C for accelerometer
raspi-config nonint do_i2c 0
fi
# Make default GIFs directory
mkdir /boot/gifs
# Set up LED columns, rows and slowdown in selector.py script
reconfig2 ./Adafruit_Spectro_Pi/selector.py "^FLAGS.*$" "FLAGS\ =\ [\"--led-cols=${MATRIX_WIDTHS[$MATRIX_SIZE]}\",\ \"--led-rows=${MATRIX_HEIGHTS[$MATRIX_SIZE]}\",\ \"--led-slowdown-gpio=${SLOWDOWN_OPTS[$SLOWDOWN_GPIO]}\"]"
# Force HDMI out so /dev/fb0 exists
reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=1"
#reconfig /boot/config.txt "^.*hdmi_group.*$" "hdmi_group=2"
#reconfig /boot/config.txt "^.*hdmi_mode.*$" "hdmi_mode=87"
# Auto-start selector.py on boot
grep selector.py /etc/rc.local >/dev/null
if [ $? -eq 0 ]; then
# selector.py already in rc.local, but make sure correct:
sed -i "s/^.*selector.py.*$/cd \/home\/pi\/Adafruit_Spectro_Pi;python3 selector.py \&/g" /etc/rc.local >/dev/null
else
if [ $? -ne 0 ]; then
# Insert selector.py into rc.local before final 'exit 0'
sed -i "s/^exit 0/cd \/home\/pi\/Adafruit_Spectro_Pi;python3 selector.py \&\\nexit 0/g" /etc/rc.local >/dev/null
sed -i "s/^exit 0/cd \/home\/pi\/Adafruit_Spectro_Pi\;python3 selector.py \&\\nexit 0/g" /etc/rc.local >/dev/null
fi
# PROMPT FOR REBOOT --------------------------------------------------------
@ -75,6 +260,7 @@ fi
echo "Done."
echo
echo "Settings take effect on next boot."
echo "For proper clock time, set the time zone with raspi-config."
echo
echo -n "REBOOT NOW? [y/N] "
read
@ -84,4 +270,4 @@ if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
fi
echo "Reboot started..."
reboot
exit 0
sleep infinity