diff --git a/bootstrap.sh b/bootstrap.sh index 6f14d46..d92baa1 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -30,7 +30,7 @@ # license and credits. # Set branch -BRANCH=master +BRANCH=devel ############ ### Global Declarations diff --git a/install.sh b/install.sh index 0633b4f..5e243a5 100755 --- a/install.sh +++ b/install.sh @@ -39,7 +39,7 @@ declare THISSCRIPT TOOLPATH VERSION GITBRNCH GITURL GITPROJ PACKAGE GITPROJWWW declare GITPROJSCRIPT GITURLWWW GITURLSCRIPT INSTANCES WEBPATH CHAMBER VERBOSE declare REPLY SOURCE SCRIPTSOURCE SCRIPTPATH CHAMBERNAME WEBSOURCE HOMEPATH -declare TILTCOLOR TILTCOLORS +declare TILTCOLOR TILTCOLORS DUMMYDEVICE # Color/character codes declare BOLD SMSO RMSO FGBLK FGRED FGGRN FGYLW FGBLU FGMAG FGCYN FGWHT FGRST declare BGBLK BGRED BGGRN BGYLW BGBLU BGMAG BGCYN BGWHT BGRST DOT HHR LHR RESET @@ -383,7 +383,7 @@ getscriptpath() { # See if we already have chambers installed if [ -n "${INSTANCES[*]}" ]; then # We've already got BrewPi installed in multi-chamber - echo -e "\nThe following chambers are already configured on this Pi:\n" + echo -e "\nThe following chambers are already configured on this system:\n" # shellcheck disable=2128 for instance in $INSTANCES do @@ -456,39 +456,40 @@ getscriptpath() { ### Install a udev rule to connect this instance to an Arduino ############ -doport(){ +doport() { if [ -n "$CHAMBER" ]; then declare -i count=-1 - #declare -a port declare -a serial declare -a manuf rules="/etc/udev/rules.d/99-arduino.rules" - devices=$(ls /dev/ttyACM* /dev/ttyUSB* 2> /dev/null) - # Get a list of USB TTY devices - for device in "${devices[@]}"; do + + # Get a list of all USB devices (/dev/tty(ACM*|ttyUSB*)) + mapfile -t < <(find "/dev/" \( -name "ttyACM*" -o -name "ttyUSB*" \)) + + # Create a list of manufacturer/serial number for attached devices + for device in "${MAPFILE[@]}"; do declare ok=false # Walk device tree | awk out the stanza with the last device in chain board=$(udevadm info --a -n "$device" | awk -v RS='' '/ATTRS{maxchild}=="0"/') thisSerial=$(echo "$board" | grep "serial" | cut -d'"' -f 2) - grep -q "$thisSerial" "$rules" 2> /dev/null || ok=true # Serial not in file - [ -z "$board" ] && ok=false # Board exists + thisManuf=$(echo "$board" | grep "manufacturer" | cut -d'"' -f 2) + # Check to make sure the serial number is not currently assigned + grep -q "$thisSerial" "$rules" 2> /dev/null || ok=true + [ -z "$device" ] && ok=false # Board exists if "$ok"; then ((count++)) - # Get the device Product ID, Vendor ID and Serial Number - #idProduct=$(echo "$board" | grep "idProduct" | cut -d'"' -f 2) - #idVendor=$(echo "$board" | grep "idVendor" | cut -d'"' -f 2) - #port[count]="$device" - serial[count]=$(echo "$board" | grep "serial" | cut -d'"' -f 2) - manuf[count]=$(echo "$board" | grep "manufacturer" | cut -d'"' -f 2) + serial[count]="$thisSerial" + manuf[count]="$thisManuf" fi done + # Display a menu of devices to associate with this chamber if [ "$count" -gt 0 ]; then # There's more than one (it's 0-based) echo -e "\nThe following seem to be the Arduinos available on this system:\n" for (( c=0; c<=count; c++ )) do - echo -e "[$c] Manuf: ${manuf[c]}, Serial: ${serial[c]}" + echo -e "\t[$c] ${manuf[c]}, SerNo: ${serial[c]}" done echo while :; do @@ -499,46 +500,54 @@ doport(){ break fi done + # Device already exists - well-meaning user may have set it up if [ -L "/dev/$CHAMBER" ]; then - echo -e "\nPort /dev/$CHAMBER already exists as a link; using it but check your setup." + # Link in /dev* already exists + echo -e "\nWarning: A link to port /dev/$CHAMBER already exists. Using it in config,\nbut check your setup.\n" + read -n 1 -s -r -p "Press any key to continue. " < /dev/tty + echo else echo -e "\nCreating rule for board ${serial[board]} as /dev/$CHAMBER." - # Concatenate the rule - rule='SUBSYSTEM=="tty", ATTRS{serial}=="sernum", SYMLINK+="chambr"' - #rule+=', GROUP="brewpi"' + # Concatenate the rule with __placeholders__ + rule='SUBSYSTEM=="tty", ATTRS{serial}=="__serial__", SYMLINK+="__chamber__"' # Replace placeholders with real values - rule="${rule/sernum/${serial[board]}}" - rule="${rule/chambr/$CHAMBER}" + rule="${rule/__serial__/${serial[board]}}" + rule="${rule/__chamber__/$CHAMBER}" echo "$rule" >> "$rules" fi - udevadm control --reload-rules - udevadm trigger - elif [ "$count" -eq 0 ]; then - # Only one (it's 0-based), use it + + # Only one (it's 0-based), use it + elif [ "$count" -eq 0 ]; then if [ -L "/dev/$CHAMBER" ]; then - echo -e "\nPort /dev/$CHAMBER already exists as a link; using it but check your setup." + # Link in /dev* already exists + echo -e "\nWarning: A link to port /dev/$CHAMBER already exists. Using it in config,\nbut check your setup.\n" + read -n 1 -s -r -p "Press any key to continue. " < /dev/tty + echo else echo -e "\nCreating rule for board ${serial[0]} as /dev/$CHAMBER." - # Concatenate the rule - rule='SUBSYSTEM=="tty", ATTRS{serial}=="sernum", SYMLINK+="chambr"' - #rule+=', GROUP="brewpi"' + # Concatenate the rule with __placeholders__ + rule='SUBSYSTEM=="tty", ATTRS{serial}=="__serial__", SYMLINK+="__chamber__"' # Replace placeholders with real values - rule="${rule/sernum/${serial[0]}}" - rule="${rule/chambr/$CHAMBER}" + rule="${rule/__serial__/${serial[0]}}" + rule="${rule/__chamber__/$CHAMBER}" echo "$rule" >> "$rules" fi + + # Reload new rules udevadm control --reload-rules udevadm trigger + + # We have selected multi-chamber but there's no devices else - # We have selected multi-chamber but there's no devices - echo -e "\nYou've configured the system for multi-chamber support however no Arduinos were" - echo -e "found to configure. The following configuration will be created, however you" + DUMMYDEVICE=true + echo -e "\nYou've configured the system for multi-chamber support, however no Arduinos" + echo -e "were found to configure. The following configuration will be created, however" echo -e "must manually create a rule for your device to match the configuration file." - echo -e "\n\tConfiguration File: $SCRIPTPATH/settings/config.cnf" + echo -e "\n\tConfiguration File: $SCRIPTPATH/settings/config.cfg" echo -e "\tDevice: /dev/$CHAMBER\n" read -n 1 -s -r -p "Press any key to continue. " < /dev/tty - echo -e "" + echo fi else echo -e "\nScripts will use default 'port = auto' setting." @@ -794,18 +803,25 @@ fixsafari() { ############ flash() { - local yn branch + local yn branch pythonpath branch="${GITBRNCH,,}" if [ ! "$branch" == "master" ]; then branch="--beta" else branch="" fi + + if [ -n "$CHAMBER" ]; then + pythonpath=$(which python) + else + pythonpath="/home/brewpi/venv/bin/python" + fi + echo -e "\nIf you have previously flashed your controller, you do not need to do so again." read -rp "Do you want to flash your controller now? [y/N]: " yn < /dev/tty yn=${yn//[^[:alpha:].-]/} case "$yn" in - [Yy]* ) eval "python3 -u $SCRIPTPATH/utils/updateFirmware.py $branch" ;; + [Yy]* ) eval "$pythonpath -u $SCRIPTPATH/utils/updateFirmware.py $branch" ;; * ) ;; esac } @@ -889,7 +905,7 @@ main() { fi fi doperms # Set script and www permissions - flash # Flash controller + [ ! "$DUMMYDEVICE" = true ] && flash # Flash controller if present # Allow BrewPi to start via daemon rm -f "$WEBPATH/do_not_run_brewpi" if [ -n "$CHAMBER" ]; then diff --git a/uninstall.sh b/uninstall.sh index 3676c32..30cbc0f 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -34,11 +34,9 @@ ############ # General constants -declare CMDLINE PACKAGE GITBRNCH THISSCRIPT VERSION APTPACKAGES +declare CMDLINE PACKAGE THISSCRIPT APTPACKAGES declare PIPPACKAGES REPLY REALUSER LINK # Version/Branch Constants -GITBRNCH="master" -VERSION="0.5.4.2" THISSCRIPT="uninstall.sh" LINK="uninstall.brewpiremix.com" @@ -49,12 +47,7 @@ LINK="uninstall.brewpiremix.com" init() { # Set up some project variables we won't have PACKAGE="BrewPi-Tools-RMX" - if [ ! "GITBRNCH" == "master" ]; then - # Use devel branch link - CMDLINE="curl -L dev$LINK | sudo bash" - else - CMDLINE="curl -L $LINK | sudo bash" - fi + CMDLINE="curl -L $LINK | sudo bash" # Packages to be uninstalled via apt APTPACKAGES="git-core pastebinit build-essential git arduino-core libapache2-mod-php apache2 python-configobj python-dev python-pip php-xml php-mbstring php-cgi php-cli php-common php libatlas-base-dev python3-numpy python3-scipy" # Packages to be uninstalled via pip @@ -130,7 +123,7 @@ log() { usage() { cat << EOF -$PACKAGE $THISSCRIPT version $VERSION +$PACKAGE $THISSCRIPT Usage: sudo ./$THISSCRIPT" EOF @@ -140,7 +133,7 @@ EOF version() { cat << EOF -$THISSCRIPT ($PACKAGE) $VERSION +$THISSCRIPT ($PACKAGE) Copyright (C) 2018, 2019 Lee C. Bussy (@LBussy) @@ -274,15 +267,20 @@ syslogd() { ############ quitproc() { - declare home instance instances + declare home instance instances pythonpath home="/home/brewpi" echo -e "\nQuitting any running BrewPi processes." > /dev/tty instances=$(find "$home" -name "brewpi.py" 2> /dev/null) IFS=$'\n' instances=("$(sort <<<"${instances[*]}")") && unset IFS # Sort list # Send quit messages to all BrewPi instances + if [ -f "/home/brewpi/venv/bin/python" ]; then + pythonpath="/home/brewpi/venv/bin/python" + else + pythonpath=$(which python) + fi for instance in $instances do - /usr/bin/python3 -u "$instance" --quit + eval "$pythonpath -u $instance --quit" done sleep 2 # Get instances again @@ -291,7 +289,7 @@ quitproc() { IFS=$'\n' instances=("$(sort <<<"${instances[*]}")") && unset IFS # Sort list # Send kill messages to all BrewPi instances for instance in $instances do - /usr/bin/python3 -u "$instance" --kill + eval "$pythonpath -u $instance --kill" done sleep 2 } @@ -341,14 +339,14 @@ killproc() { delrepo() { local webroot # Wipe out tools - if [ -d "/home/$REALUSER/brewpi-tools-rmx" ]; then - echo -e "\nClearing /home/$REALUSER/brewpi-tools-rmx." > /dev/tty - rm -fr "/home/$REALUSER/brewpi-tools-rmx" + if [ -d "$HOMEPATH/brewpi-tools-rmx" ]; then + echo -e "\nClearing $HOMEPATH/brewpi-tools-rmx." > /dev/tty + rm -fr "$HOMEPATH/brewpi-tools-rmx" fi # Wipe out legacy tools - if [ -d "/home/$REALUSER/brewpi-tools" ]; then - echo -e "\nClearing /home/$REALUSER/brewpi-tools." > /dev/tty - rm -fr "/home/$REALUSER/brewpi-tools" + if [ -d "$HOMEPATH/brewpi-tools" ]; then + echo -e "\nClearing $HOMEPATH/brewpi-tools." > /dev/tty + rm -fr "$HOMEPATH/brewpi-tools" fi # Wipe out BrewPi scripts if [ -d /home/brewpi ]; then @@ -567,7 +565,7 @@ resetpwd() { delchamber() { local chamber newchamber link home instances newlink webDir unitFile - local daemonName rules scriptDir webPath + local daemonName rules scriptDir webPath pythonpath chamber="$1" home="/home/brewpi" rules="/etc/udev/rules.d/99-arduino.rules" @@ -615,9 +613,10 @@ delchamber() { fi # Delete BrewPi scripts for chamber if [ -d "$scriptDir" ]; then + pythonpath="/home/brewpi/venv/bin/python" # Stop running instance - "$scriptDir/brewpi.py --quit" > /dev/null 2>&1 - "$scriptDir/brewpi.py --kill" > /dev/null 2>&1 + "$pythonpath $scriptDir/brewpi.py --quit" > /dev/null 2>&1 + "$pythonpath $scriptDir/brewpi.py --kill" > /dev/null 2>&1 # Remove BrewPi script instance echo -e "\nRemoving $scriptDir." rm -fr "$scriptDir" > /dev/null 2>&1