From ea3bfb6c4dafd2ada57466b0ca6cbef754100b03 Mon Sep 17 00:00:00 2001 From: okunze Date: Fri, 24 Nov 2023 21:02:47 +0000 Subject: [PATCH] Automated Change by GitHub Action --- source/argon1.sh | 784 ++++++++++++++++-------------------- source/argonone-irconfig.sh | 3 - 2 files changed, 357 insertions(+), 430 deletions(-) diff --git a/source/argon1.sh b/source/argon1.sh index 2e5cbac..bcfc9a1 100644 --- a/source/argon1.sh +++ b/source/argon1.sh @@ -1,5 +1,31 @@ #!/bin/bash +echo "*************" +echo " Argon Setup " +echo "*************" + +# Helper variables +ARGONDOWNLOADSERVER=https://download.argon40.com + +INSTALLATIONFOLDER=/etc/argon + +versioninfoscript=$INSTALLATIONFOLDER/argon-versioninfo.sh + +uninstallscript=$INSTALLATIONFOLDER/argon-uninstall.sh +shutdownscript=/lib/systemd/system-shutdown/argon-shutdown.sh +configscript=$INSTALLATIONFOLDER/argon-config +unitconfigscript=$INSTALLATIONFOLDER/argon-unitconfig.sh + +setupmode="Setup" + +if [ -f $configscript ] +then + setupmode="Update" + echo "Updating files" +else + sudo mkdir $INSTALLATIONFOLDER + sudo chmod 755 $INSTALLATIONFOLDER +fi ########## # Start code lifted from raspi-config @@ -84,50 +110,85 @@ do_serial_hw() { # End code lifted from raspi-config ########## -argon_create_file() { - if [ -f $1 ]; then - sudo rm $1 - fi - sudo touch $1 - sudo chmod 666 $1 -} - argon_check_pkg() { - RESULT=$(dpkg-query -W -f='${Status}\n' "$1" 2> /dev/null | grep "installed") + RESULT=$(dpkg-query -W -f='${Status}\n' "$1" 2> /dev/null | grep "installed") - if [ "" == "$RESULT" ]; then - echo "NG" - else - echo "OK" - fi + if [ "" == "$RESULT" ]; then + echo "NG" + else + echo "OK" + fi } +CHECKDEVICE="one" +# Check if has RTC +# Todo for multiple OS + +#i2cdetect -y 1 | grep -q ' 51 ' +#if [ $? -eq 0 ] +#then +# CHECKDEVICE="eon" +#fi + +CHECKGPIOMODE="libgpiod" # libgpiod or rpigpio + # Check if Raspbian, Ubuntu, others CHECKPLATFORM="Others" +CHECKPLATFORMVERSION="" +CHECKPLATFORMVERSIONNUM="" if [ -f "/etc/os-release" ] then source /etc/os-release if [ "$ID" = "raspbian" ] then CHECKPLATFORM="Raspbian" + CHECKPLATFORMVERSION=$VERSION_ID elif [ "$ID" = "debian" ] then # For backwards compatibility, continue using raspbian CHECKPLATFORM="Raspbian" + CHECKPLATFORMVERSION=$VERSION_ID elif [ "$ID" = "ubuntu" ] then CHECKPLATFORM="Ubuntu" + CHECKPLATFORMVERSION=$VERSION_ID + fi + echo ${CHECKPLATFORMVERSION} | grep -e "\." > /dev/null + if [ $? -eq 0 ] + then + CHECKPLATFORMVERSIONNUM=`cut -d "." -f2 <<< $CHECKPLATFORMVERSION ` + CHECKPLATFORMVERSION=`cut -d "." -f1 <<< $CHECKPLATFORMVERSION ` fi fi +gpiopkg="python3-libgpiod" +if [ "$CHECKGPIOMODE" = "rpigpio" ] +then + if [ "$CHECKPLATFORM" = "Raspbian" ] + then + gpiopkg="raspi-gpio python3-rpi.gpio" + else + gpiopkg="python3-rpi.gpio" + fi +fi if [ "$CHECKPLATFORM" = "Raspbian" ] then - pkglist=(raspi-gpio python3-rpi.gpio python3-smbus i2c-tools) + if [ "$CHECKDEVICE" = "eon" ] + then + pkglist=($gpiopkg python3-smbus i2c-tools smartmontools) + else + pkglist=($gpiopkg python3-smbus i2c-tools) + fi else # Todo handle lgpio # Ubuntu has serial and i2c enabled - pkglist=(python3-rpi.gpio python3-smbus i2c-tools) + if [ "$CHECKDEVICE" = "eon" ] + then + pkglist=($gpiopkg python3-smbus i2c-tools smartmontools) + else + pkglist=($gpiopkg python3-smbus i2c-tools) + fi fi for curpkg in ${pkglist[@]}; do @@ -159,279 +220,173 @@ then fi fi -# Helper variables -daemonname="argononed" -powerbuttonscript=/usr/bin/$daemonname.py -shutdownscript="/lib/systemd/system-shutdown/"$daemonname"-poweroff.py" +# Fan Setup +basename="argonone" +daemonname=$basename"d" +irconfigscript=$INSTALLATIONFOLDER/${basename}-ir +fanconfigscript=$INSTALLATIONFOLDER/${basename}-fanconfig.sh +powerbuttonscript=$INSTALLATIONFOLDER/$daemonname.py +unitconfigfile=/etc/argonunits.conf daemonconfigfile=/etc/$daemonname.conf -configscript=/usr/bin/argonone-config -removescript=/usr/bin/argonone-uninstall - -powerbuttonshutdownscript=$powerbuttonscript - - daemonfanservice=/lib/systemd/system/$daemonname.service +daemonhddconfigfile=/etc/${daemonname}-hdd.conf + +# Fan Config Script +sudo wget $ARGONDOWNLOADSERVER/scripts/argonone-fanconfig.sh -O $fanconfigscript --quiet +sudo chmod 755 $fanconfigscript + + +# Fan Daemon/Service Files +sudo wget $ARGONDOWNLOADSERVER/scripts/argononed.py -O $powerbuttonscript --quiet +sudo wget $ARGONDOWNLOADSERVER/scripts/argononed.service -O $daemonfanservice --quiet +sudo chmod 644 $daemonfanservice + +# IR Files +sudo wget $ARGONDOWNLOADSERVER/scripts/argonone-irconfig.sh -O $irconfigscript --quiet +sudo chmod 755 $irconfigscript + +# Other utility scripts +sudo wget $ARGONDOWNLOADSERVER/scripts/argon-versioninfo.sh -O $versioninfoscript --quiet +sudo chmod 755 $versioninfoscript + +sudo wget $ARGONDOWNLOADSERVER/scripts/argonsysinfo.py -O $INSTALLATIONFOLDER/argonsysinfo.py --quiet + +sudo wget $ARGONDOWNLOADSERVER/scripts/argonregister.py -O $INSTALLATIONFOLDER/argonregister.py --quiet + +sudo wget "$ARGONDOWNLOADSERVER/scripts/argonpowerbutton-${CHECKGPIOMODE}.py" -O $INSTALLATIONFOLDER/argonpowerbutton.py --quiet + +sudo wget $ARGONDOWNLOADSERVER/scripts/argononed.py -O $powerbuttonscript --quiet + +sudo wget $ARGONDOWNLOADSERVER/scripts/argon-unitconfig.sh -O $unitconfigscript --quiet +sudo chmod 755 $unitconfigscript + +# Generate default Fan config file if non-existent if [ ! -f $daemonconfigfile ]; then - # Generate config file for fan speed sudo touch $daemonconfigfile sudo chmod 666 $daemonconfigfile + echo '#' >> $daemonconfigfile - echo '# Argon One Fan Configuration' >> $daemonconfigfile + echo '# Argon Fan Speed Configuration (CPU)' >> $daemonconfigfile echo '#' >> $daemonconfigfile - echo '# List below the temperature (Celsius) and fan speed (in percent) pairs' >> $daemonconfigfile - echo '# Use the following form:' >> $daemonconfigfile - echo '# min.temperature=speed' >> $daemonconfigfile - echo '#' >> $daemonconfigfile - echo '# Example:' >> $daemonconfigfile - echo '# 55=10' >> $daemonconfigfile - echo '# 60=55' >> $daemonconfigfile - echo '# 65=100' >> $daemonconfigfile - echo '#' >> $daemonconfigfile - echo '# Above example sets the fan speed to' >> $daemonconfigfile - echo '#' >> $daemonconfigfile - echo '# NOTE: Lines begining with # are ignored' >> $daemonconfigfile - echo '#' >> $daemonconfigfile - echo '# Type the following at the command line for changes to take effect:' >> $daemonconfigfile - echo '# sudo systemctl restart '$daemonname'.service' >> $daemonconfigfile - echo '#' >> $daemonconfigfile - echo '# Start below:' >> $daemonconfigfile - echo '55=10' >> $daemonconfigfile + echo '55=30' >> $daemonconfigfile echo '60=55' >> $daemonconfigfile echo '65=100' >> $daemonconfigfile fi -# Generate script that runs every shutdown event -argon_create_file $shutdownscript +if [ "$CHECKDEVICE" = "eon" ] +then + if [ ! -f $daemonhddconfigfile ]; then + sudo touch $daemonhddconfigfile + sudo chmod 666 $daemonhddconfigfile -echo "#!/usr/bin/python3" >> $shutdownscript -echo 'import sys' >> $shutdownscript -echo 'import time' >> $shutdownscript -echo 'import smbus' >> $shutdownscript -echo 'import RPi.GPIO as GPIO' >> $shutdownscript -echo 'rev = GPIO.RPI_REVISION' >> $shutdownscript -echo 'if rev == 2 or rev == 3:' >> $shutdownscript -echo ' bus = smbus.SMBus(1)' >> $shutdownscript -echo 'else:' >> $shutdownscript -echo ' bus = smbus.SMBus(0)' >> $shutdownscript + echo '#' >> $daemonhddconfigfile + echo '# Argon Fan Speed Configuration (HDD)' >> $daemonhddconfigfile + echo '#' >> $daemonhddconfigfile + echo '35=30' >> $daemonhddconfigfile + echo '40=55' >> $daemonhddconfigfile + echo '45=100' >> $daemonhddconfigfile + fi +fi -echo 'if len(sys.argv)>1:' >> $shutdownscript -echo ' address=0x1a' >> $shutdownscript +# Generate default Unit config file if non-existent +if [ ! -f $unitconfigfile ]; then + sudo touch $unitconfigfile + sudo chmod 666 $unitconfigfile -# Fan off -echo " bus.write_byte(address,0)" >> $shutdownscript + echo '#' >> $unitconfigfile +fi -# powercut signal -echo ' if sys.argv[1] == "poweroff" or sys.argv[1] == "halt":' >> $shutdownscript -echo " try:" >> $shutdownscript -echo " bus.write_byte(address,0xFF)" >> $shutdownscript -echo " except:" >> $shutdownscript -echo " rev=0" >> $shutdownscript +if [ "$CHECKDEVICE" = "eon" ] +then + # RTC Setup + basename="argoneon" + daemonname=$basename"d" + + rtcconfigfile=/etc/argoneonrtc.conf + rtcconfigscript=$INSTALLATIONFOLDER/${basename}-rtcconfig.sh + daemonrtcservice=/lib/systemd/system/$daemonname.service + rtcdaemonscript=$INSTALLATIONFOLDER/$daemonname.py + + oledconfigscript=$INSTALLATIONFOLDER/${basename}-oledconfig.sh + oledlibscript=$INSTALLATIONFOLDER/${basename}oled.py + oledconfigfile=/etc/argoneonoled.conf + + # Generate default RTC config file if non-existent + if [ ! -f $rtcconfigfile ]; then + sudo touch $rtcconfigfile + sudo chmod 666 $rtcconfigfile + + echo '#' >> $rtcconfigfile + echo '# Argon RTC Configuration' >> $rtcconfigfile + echo '#' >> $rtcconfigfile + fi + # Generate default OLED config file if non-existent + if [ ! -f $oledconfigfile ]; then + sudo touch $oledconfigfile + sudo chmod 666 $oledconfigfile + + echo '#' >> $oledconfigfile + echo '# Argon OLED Configuration' >> $oledconfigfile + echo '#' >> $oledconfigfile + echo 'switchduration=30' >> $oledconfigfile + echo 'screenlist="clock cpu storage raid ram temp ip"' >> $oledconfigfile + fi + + + # RTC Config Script + sudo wget $ARGONDOWNLOADSERVER/scripts/argoneon-rtcconfig.sh -O $rtcconfigscript --quiet + sudo chmod 755 $rtcconfigscript + + # RTC Daemon/Service Files + sudo wget $ARGONDOWNLOADSERVER/scripts/argoneond.py -O $rtcdaemonscript --quiet + sudo wget $ARGONDOWNLOADSERVER/scripts/argoneond.service -O $daemonrtcservice --quiet + sudo wget $ARGONDOWNLOADSERVER/scripts/argoneonoled.py -O $oledlibscript --quiet + sudo chmod 644 $daemonrtcservice + + # OLED Config Script + sudo wget $ARGONDOWNLOADSERVER/scripts/argoneon-oledconfig.sh -O $oledconfigscript --quiet + sudo chmod 755 $oledconfigscript + + + if [ ! -d $INSTALLATIONFOLDER/oled ] + then + sudo mkdir $INSTALLATIONFOLDER/oled + fi + + for binfile in font8x6 font16x12 font32x24 font64x48 font16x8 font24x16 font48x32 bgdefault bgram bgip bgtemp bgcpu bgraid bgstorage bgtime + do + sudo wget $ARGONDOWNLOADSERVER/oled/${binfile}.bin -O $INSTALLATIONFOLDER/oled/${binfile}.bin --quiet + done + + +fi + + +# Argon Uninstall Script +sudo wget $ARGONDOWNLOADSERVER/scripts/argon-uninstall.sh -O $uninstallscript --quiet +sudo chmod 755 $uninstallscript + +# Argon Shutdown script +sudo wget $ARGONDOWNLOADSERVER/scripts/argon-shutdown.sh -O $shutdownscript --quiet sudo chmod 755 $shutdownscript -# Generate script to monitor shutdown button +# Argon Config Script +if [ -f $configscript ]; then + sudo rm $configscript +fi +sudo touch $configscript -argon_create_file $powerbuttonscript +# To ensure we can write the following lines +sudo chmod 666 $configscript -echo "#!/usr/bin/python3" >> $powerbuttonscript -echo 'import smbus' >> $powerbuttonscript -echo 'import RPi.GPIO as GPIO' >> $powerbuttonscript -echo 'import os' >> $powerbuttonscript -echo 'import time' >> $powerbuttonscript -echo 'from threading import Thread' >> $powerbuttonscript -echo 'rev = GPIO.RPI_REVISION' >> $powerbuttonscript -echo 'if rev == 2 or rev == 3:' >> $powerbuttonscript -echo ' bus = smbus.SMBus(1)' >> $powerbuttonscript -echo 'else:' >> $powerbuttonscript -echo ' bus = smbus.SMBus(0)' >> $powerbuttonscript - -echo 'GPIO.setwarnings(False)' >> $powerbuttonshutdownscript -echo 'GPIO.setmode(GPIO.BCM)' >> $powerbuttonshutdownscript -echo 'shutdown_pin=4' >> $powerbuttonshutdownscript -echo 'GPIO.setup(shutdown_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)' >> $powerbuttonshutdownscript - -echo 'def shutdown_check():' >> $powerbuttonshutdownscript -echo ' while True:' >> $powerbuttonshutdownscript -echo ' pulsetime = 1' >> $powerbuttonshutdownscript -echo ' GPIO.wait_for_edge(shutdown_pin, GPIO.RISING)' >> $powerbuttonshutdownscript -echo ' time.sleep(0.01)' >> $powerbuttonshutdownscript -echo ' while GPIO.input(shutdown_pin) == GPIO.HIGH:' >> $powerbuttonshutdownscript -echo ' time.sleep(0.01)' >> $powerbuttonshutdownscript -echo ' pulsetime += 1' >> $powerbuttonshutdownscript -echo ' if pulsetime >=2 and pulsetime <=3:' >> $powerbuttonshutdownscript -echo ' os.system("reboot")' >> $powerbuttonshutdownscript -echo ' elif pulsetime >=4 and pulsetime <=5:' >> $powerbuttonshutdownscript -echo ' os.system("shutdown now -h")' >> $powerbuttonshutdownscript - -echo 'def get_fanspeed(tempval, configlist):' >> $powerbuttonscript -echo ' for curconfig in configlist:' >> $powerbuttonscript -echo ' curpair = curconfig.split("=")' >> $powerbuttonscript -echo ' tempcfg = float(curpair[0])' >> $powerbuttonscript -echo ' fancfg = int(float(curpair[1]))' >> $powerbuttonscript -echo ' if tempval >= tempcfg:' >> $powerbuttonscript -echo ' if fancfg < 1:' >> $powerbuttonscript -echo ' return 0' >> $powerbuttonscript -echo ' elif fancfg < 25:' >> $powerbuttonscript -echo ' return 25' >> $powerbuttonscript -echo ' return fancfg' >> $powerbuttonscript -echo ' return 0' >> $powerbuttonscript - -echo 'def load_config(fname):' >> $powerbuttonscript -echo ' newconfig = []' >> $powerbuttonscript -echo ' try:' >> $powerbuttonscript -echo ' with open(fname, "r") as fp:' >> $powerbuttonscript -echo ' for curline in fp:' >> $powerbuttonscript -echo ' if not curline:' >> $powerbuttonscript -echo ' continue' >> $powerbuttonscript -echo ' tmpline = curline.strip()' >> $powerbuttonscript -echo ' if not tmpline:' >> $powerbuttonscript -echo ' continue' >> $powerbuttonscript -echo ' if tmpline[0] == "#":' >> $powerbuttonscript -echo ' continue' >> $powerbuttonscript -echo ' tmppair = tmpline.split("=")' >> $powerbuttonscript -echo ' if len(tmppair) != 2:' >> $powerbuttonscript -echo ' continue' >> $powerbuttonscript -echo ' tempval = 0' >> $powerbuttonscript -echo ' fanval = 0' >> $powerbuttonscript -echo ' try:' >> $powerbuttonscript -echo ' tempval = float(tmppair[0])' >> $powerbuttonscript -echo ' if tempval < 0 or tempval > 100:' >> $powerbuttonscript -echo ' continue' >> $powerbuttonscript -echo ' except:' >> $powerbuttonscript -echo ' continue' >> $powerbuttonscript -echo ' try:' >> $powerbuttonscript -echo ' fanval = int(float(tmppair[1]))' >> $powerbuttonscript -echo ' if fanval < 0 or fanval > 100:' >> $powerbuttonscript -echo ' continue' >> $powerbuttonscript -echo ' except:' >> $powerbuttonscript -echo ' continue' >> $powerbuttonscript -echo ' newconfig.append( "{:5.1f}={}".format(tempval,fanval))' >> $powerbuttonscript -echo ' if len(newconfig) > 0:' >> $powerbuttonscript -echo ' newconfig.sort(reverse=True)' >> $powerbuttonscript -echo ' except:' >> $powerbuttonscript -echo ' return []' >> $powerbuttonscript -echo ' return newconfig' >> $powerbuttonscript - -echo 'def temp_check():' >> $powerbuttonscript -echo ' address=0x1a' >> $powerbuttonscript - -echo ' fanconfig = ["65=100", "60=55", "55=10"]' >> $powerbuttonscript -echo ' tmpconfig = load_config("'$daemonconfigfile'")' >> $powerbuttonscript -echo ' if len(tmpconfig) > 0:' >> $powerbuttonscript -echo ' fanconfig = tmpconfig' >> $powerbuttonscript -echo ' prevblock=0' >> $powerbuttonscript -echo ' while True:' >> $powerbuttonscript - -echo ' try:' >> $powerbuttonscript -echo ' tempfp = open("/sys/class/thermal/thermal_zone0/temp", "r")' >> $powerbuttonscript -echo ' temp = tempfp.readline()' >> $powerbuttonscript -echo ' tempfp.close()' >> $powerbuttonscript -echo ' val = float(int(temp)/1000)' >> $powerbuttonscript -echo ' except IOError:' >> $powerbuttonscript -echo ' val = 0' >> $powerbuttonscript - -echo ' block = get_fanspeed(val, fanconfig)' >> $powerbuttonscript -echo ' if block < prevblock:' >> $powerbuttonscript -echo ' time.sleep(30)' >> $powerbuttonscript -echo ' prevblock = block' >> $powerbuttonscript -echo ' try:' >> $powerbuttonscript -echo ' if block > 0:' >> $powerbuttonscript -echo ' bus.write_byte(address,100)' >> $powerbuttonscript -echo ' time.sleep(1)' >> $powerbuttonscript -echo ' bus.write_byte(address,block)' >> $powerbuttonscript -echo ' except IOError:' >> $powerbuttonscript -echo ' temp=""' >> $powerbuttonscript -echo ' time.sleep(30)' >> $powerbuttonscript - -echo 'try:' >> $powerbuttonscript -echo ' t1 = Thread(target = shutdown_check)' >> $powerbuttonshutdownscript -echo ' t2 = Thread(target = temp_check)' >> $powerbuttonscript -echo ' t1.start()' >> $powerbuttonshutdownscript -echo ' t2.start()' >> $powerbuttonscript -echo 'except:' >> $powerbuttonscript -echo ' t1.stop()' >> $powerbuttonshutdownscript -echo ' t2.stop()' >> $powerbuttonscript -echo ' GPIO.cleanup()' >> $powerbuttonshutdownscript - -sudo chmod 755 $powerbuttonscript - -argon_create_file $daemonfanservice - -# Fan Daemon -echo "[Unit]" >> $daemonfanservice -echo "Description=Argon One Fan and Button Service" >> $daemonfanservice -echo "After=multi-user.target" >> $daemonfanservice -echo '[Service]' >> $daemonfanservice -echo 'Type=simple' >> $daemonfanservice -echo "Restart=always" >> $daemonfanservice -echo "RemainAfterExit=true" >> $daemonfanservice -echo "ExecStart=/usr/bin/python3 $powerbuttonscript" >> $daemonfanservice -echo '[Install]' >> $daemonfanservice -echo "WantedBy=multi-user.target" >> $daemonfanservice - -sudo chmod 644 $daemonfanservice - -argon_create_file $removescript - -# Uninstall Script -echo '#!/bin/bash' >> $removescript -echo 'echo "-------------------------"' >> $removescript -echo 'echo "Argon One Uninstall Tool"' >> $removescript -echo 'echo "-------------------------"' >> $removescript -echo 'echo -n "Press Y to continue:"' >> $removescript -echo 'read -n 1 confirm' >> $removescript -echo 'echo' >> $removescript -echo 'if [ "$confirm" = "y" ]' >> $removescript -echo 'then' >> $removescript -echo ' confirm="Y"' >> $removescript -echo 'fi' >> $removescript -echo '' >> $removescript -echo 'if [ "$confirm" != "Y" ]' >> $removescript -echo 'then' >> $removescript -echo ' echo "Cancelled"' >> $removescript -echo ' exit' >> $removescript -echo 'fi' >> $removescript -echo 'if [ -d "/home/pi/Desktop" ]; then' >> $removescript -echo ' sudo rm "/home/pi/Desktop/argonone-config.desktop"' >> $removescript -echo ' sudo rm "/home/pi/Desktop/argonone-uninstall.desktop"' >> $removescript -echo 'fi' >> $removescript -echo 'if [ -f '$powerbuttonscript' ]; then' >> $removescript -echo ' sudo systemctl stop '$daemonname'.service' >> $removescript -echo ' sudo systemctl disable '$daemonname'.service' >> $removescript -echo ' sudo /usr/bin/python3 '$shutdownscript' uninstall' >> $removescript -echo ' sudo rm '$powerbuttonscript >> $removescript -echo ' sudo rm '$shutdownscript >> $removescript -echo ' sudo rm '$removescript >> $removescript -echo ' echo "Removed Argon One Services."' >> $removescript -echo ' echo "Cleanup will complete after restarting the device."' >> $removescript -echo 'fi' >> $removescript - -sudo chmod 755 $removescript - -argon_create_file $configscript - -# Config Script echo '#!/bin/bash' >> $configscript -echo 'daemonconfigfile='$daemonconfigfile >> $configscript -echo 'echo "--------------------------------------"' >> $configscript -echo 'echo "Argon One Fan Speed Configuration Tool"' >> $configscript -echo 'echo "--------------------------------------"' >> $configscript -echo 'echo "WARNING: This will remove existing configuration."' >> $configscript -echo 'echo -n "Press Y to continue:"' >> $configscript -echo 'read -n 1 confirm' >> $configscript -echo 'echo' >> $configscript -echo 'if [ "$confirm" = "y" ]' >> $configscript -echo 'then' >> $configscript -echo ' confirm="Y"' >> $configscript -echo 'fi' >> $configscript -echo '' >> $configscript -echo 'if [ "$confirm" != "Y" ]' >> $configscript -echo 'then' >> $configscript -echo ' echo "Cancelled"' >> $configscript -echo ' exit' >> $configscript -echo 'fi' >> $configscript -echo 'echo "Thank you."' >> $configscript + +echo 'echo "--------------------------"' >> $configscript +echo 'echo "Argon Configuration Tool"' >> $configscript +echo "$versioninfoscript simple" >> $configscript +echo 'echo "--------------------------"' >> $configscript echo 'get_number () {' >> $configscript echo ' read curnumber' >> $configscript @@ -458,142 +413,98 @@ echo ' return' >> $configscript echo '}' >> $configscript echo '' >> $configscript -echo 'loopflag=1' >> $configscript -echo 'while [ $loopflag -eq 1 ]' >> $configscript +echo 'mainloopflag=1' >> $configscript +echo 'while [ $mainloopflag -eq 1 ]' >> $configscript echo 'do' >> $configscript echo ' echo' >> $configscript -echo ' echo "Select fan mode:"' >> $configscript -echo ' echo " 1. Always on"' >> $configscript -echo ' echo " 2. Adjust to temperatures (55C, 60C, and 65C)"' >> $configscript -echo ' echo " 3. Customize behavior"' >> $configscript -echo ' echo " 4. Cancel"' >> $configscript -echo ' echo "NOTE: You can also edit $daemonconfigfile directly"' >> $configscript -echo ' echo -n "Enter Number (1-4):"' >> $configscript +echo ' echo "Choose Option:"' >> $configscript +echo ' echo " 1. Configure Fan"' >> $configscript +echo ' echo " 2. Configure IR"' >> $configscript + +uninstalloption="4" + +if [ "$CHECKDEVICE" = "eon" ] +then + # ArgonEON Has RTC + echo ' echo " 3. Configure RTC and/or Schedule"' >> $configscript + echo ' echo " 4. Configure OLED"' >> $configscript + uninstalloption="6" +fi + +unitsoption=$(($uninstalloption-1)) +echo " echo \" $unitsoption. Configure Units\"" >> $configscript + +echo " echo \" $uninstalloption. Uninstall\"" >> $configscript +echo ' echo ""' >> $configscript +echo ' echo " 0. Exit"' >> $configscript +echo " echo -n \"Enter Number (0-$uninstalloption):\"" >> $configscript echo ' newmode=$( get_number )' >> $configscript -echo ' if [[ $newmode -ge 1 && $newmode -le 4 ]]' >> $configscript + + +echo ' if [ $newmode -eq 0 ]' >> $configscript echo ' then' >> $configscript -echo ' loopflag=0' >> $configscript +echo ' echo "Thank you."' >> $configscript +echo ' mainloopflag=0' >> $configscript +echo ' elif [ $newmode -eq 1 ]' >> $configscript +echo ' then' >> $configscript + +if [ "$CHECKDEVICE" = "eon" ] +then + echo ' echo "Choose Triggers:"' >> $configscript + echo ' echo " 1. CPU Temperature"' >> $configscript + echo ' echo " 2. HDD Temperature"' >> $configscript + echo ' echo ""' >> $configscript + echo ' echo " 0. Cancel"' >> $configscript + echo " echo -n \"Enter Number (0-2):\"" >> $configscript + echo ' submode=$( get_number )' >> $configscript + + echo ' if [ $submode -eq 1 ]' >> $configscript + echo ' then' >> $configscript + echo " $fanconfigscript" >> $configscript + echo ' mainloopflag=0' >> $configscript + echo ' elif [ $submode -eq 2 ]' >> $configscript + echo ' then' >> $configscript + echo " $fanconfigscript hdd" >> $configscript + echo ' mainloopflag=0' >> $configscript + echo ' fi' >> $configscript + +else + echo " $fanconfigscript" >> $configscript + echo ' mainloopflag=0' >> $configscript +fi + +echo ' elif [ $newmode -eq 2 ]' >> $configscript +echo ' then' >> $configscript +echo " $irconfigscript" >> $configscript +echo ' mainloopflag=0' >> $configscript + +if [ "$CHECKDEVICE" = "eon" ] +then + echo ' elif [ $newmode -eq 3 ]' >> $configscript + echo ' then' >> $configscript + echo " $rtcconfigscript" >> $configscript + echo ' mainloopflag=0' >> $configscript + echo ' elif [ $newmode -eq 4 ]' >> $configscript + echo ' then' >> $configscript + echo " $oledconfigscript" >> $configscript + echo ' mainloopflag=0' >> $configscript +fi + +echo " elif [ \$newmode -eq $unitsoption ]" >> $configscript +echo ' then' >> $configscript +echo " $unitconfigscript" >> $configscript +echo ' mainloopflag=0' >> $configscript + +echo " elif [ \$newmode -eq $uninstalloption ]" >> $configscript +echo ' then' >> $configscript +echo " $uninstallscript" >> $configscript +echo ' mainloopflag=0' >> $configscript echo ' fi' >> $configscript echo 'done' >> $configscript -echo 'echo' >> $configscript -echo 'if [ $newmode -eq 4 ]' >> $configscript -echo 'then' >> $configscript -echo ' echo "Cancelled"' >> $configscript -echo ' exit' >> $configscript -echo 'elif [ $newmode -eq 1 ]' >> $configscript -echo 'then' >> $configscript -echo ' echo "#" > $daemonconfigfile' >> $configscript -echo ' echo "# Argon One Fan Speed Configuration" >> $daemonconfigfile' >> $configscript -echo ' echo "#" >> $daemonconfigfile' >> $configscript -echo ' echo "# Min Temp=Fan Speed" >> $daemonconfigfile' >> $configscript -echo ' echo 1"="100 >> $daemonconfigfile' >> $configscript -echo ' sudo systemctl restart '$daemonname'.service' >> $configscript -echo ' echo "Fan always on."' >> $configscript -echo ' exit' >> $configscript -echo 'elif [ $newmode -eq 2 ]' >> $configscript -echo 'then' >> $configscript -echo ' echo "Please provide fan speeds for the following temperatures:"' >> $configscript -echo ' echo "#" > $daemonconfigfile' >> $configscript -echo ' echo "# Argon One Fan Speed Configuration" >> $daemonconfigfile' >> $configscript -echo ' echo "#" >> $daemonconfigfile' >> $configscript -echo ' echo "# Min Temp=Fan Speed" >> $daemonconfigfile' >> $configscript -echo ' curtemp=55' >> $configscript -echo ' while [ $curtemp -lt 70 ]' >> $configscript -echo ' do' >> $configscript -echo ' errorfanflag=1' >> $configscript -echo ' while [ $errorfanflag -eq 1 ]' >> $configscript -echo ' do' >> $configscript -echo ' echo -n ""$curtemp"C (0-100 only):"' >> $configscript -echo ' curfan=$( get_number )' >> $configscript -echo ' if [ $curfan -ge 0 ]' >> $configscript -echo ' then' >> $configscript -echo ' errorfanflag=0' >> $configscript -echo ' fi' >> $configscript -echo ' done' >> $configscript -echo ' echo $curtemp"="$curfan >> $daemonconfigfile' >> $configscript -echo ' curtemp=$((curtemp+5))' >> $configscript -echo ' done' >> $configscript - -echo ' sudo systemctl restart '$daemonname'.service' >> $configscript -echo ' echo "Configuration updated."' >> $configscript -echo ' exit' >> $configscript -echo 'fi' >> $configscript - -echo 'echo "Please provide fan speeds and temperature pairs"' >> $configscript -echo 'echo' >> $configscript - -echo 'loopflag=1' >> $configscript -echo 'paircounter=0' >> $configscript -echo 'while [ $loopflag -eq 1 ]' >> $configscript -echo 'do' >> $configscript -echo ' errortempflag=1' >> $configscript -echo ' errorfanflag=1' >> $configscript -echo ' while [ $errortempflag -eq 1 ]' >> $configscript -echo ' do' >> $configscript -echo ' echo -n "Provide minimum temperature (in Celsius) then [ENTER]:"' >> $configscript -echo ' curtemp=$( get_number )' >> $configscript -echo ' if [ $curtemp -ge 0 ]' >> $configscript -echo ' then' >> $configscript -echo ' errortempflag=0' >> $configscript -echo ' elif [ $curtemp -eq -2 ]' >> $configscript -echo ' then' >> $configscript -echo ' errortempflag=0' >> $configscript -echo ' errorfanflag=0' >> $configscript -echo ' loopflag=0' >> $configscript -echo ' fi' >> $configscript -echo ' done' >> $configscript -echo ' while [ $errorfanflag -eq 1 ]' >> $configscript -echo ' do' >> $configscript -echo ' echo -n "Provide fan speed for "$curtemp"C (0-100) then [ENTER]:"' >> $configscript -echo ' curfan=$( get_number )' >> $configscript -echo ' if [ $curfan -ge 0 ]' >> $configscript -echo ' then' >> $configscript -echo ' errorfanflag=0' >> $configscript -echo ' elif [ $curfan -eq -2 ]' >> $configscript -echo ' then' >> $configscript -echo ' errortempflag=0' >> $configscript -echo ' errorfanflag=0' >> $configscript -echo ' loopflag=0' >> $configscript -echo ' fi' >> $configscript -echo ' done' >> $configscript -echo ' if [ $loopflag -eq 1 ]' >> $configscript -echo ' then' >> $configscript -echo ' if [ $paircounter -eq 0 ]' >> $configscript -echo ' then' >> $configscript -echo ' echo "#" > $daemonconfigfile' >> $configscript -echo ' echo "# Argon One Fan Speed Configuration" >> $daemonconfigfile' >> $configscript -echo ' echo "#" >> $daemonconfigfile' >> $configscript -echo ' echo "# Min Temp=Fan Speed" >> $daemonconfigfile' >> $configscript -echo ' fi' >> $configscript -echo ' echo $curtemp"="$curfan >> $daemonconfigfile' >> $configscript -echo ' ' >> $configscript -echo ' paircounter=$((paircounter+1))' >> $configscript -echo ' ' >> $configscript -echo ' echo "* Fan speed will be set to "$curfan" once temperature reaches "$curtemp" C"' >> $configscript -echo ' echo' >> $configscript -echo ' fi' >> $configscript -echo 'done' >> $configscript -echo '' >> $configscript -echo 'echo' >> $configscript -echo 'if [ $paircounter -gt 0 ]' >> $configscript -echo 'then' >> $configscript -echo ' echo "Thank you! We saved "$paircounter" pairs."' >> $configscript -echo ' sudo systemctl restart '$daemonname'.service' >> $configscript -echo ' echo "Changes should take effect now."' >> $configscript -echo 'else' >> $configscript -echo ' echo "Cancelled, no data saved."' >> $configscript -echo 'fi' >> $configscript - sudo chmod 755 $configscript - -sudo systemctl daemon-reload -sudo systemctl enable $daemonname.service - -sudo systemctl start $daemonname.service - - +# Desktop Icon shortcutfile="/home/pi/Desktop/argonone-config.desktop" if [ "$CHECKPLATFORM" = "Raspbian" ] && [ -d "/home/pi/Desktop" ] then @@ -602,26 +513,22 @@ then then terminalcmd="xfce4-terminal --default-working-directory=/home/pi/ -T" fi - sudo wget http://download.argon40.com/ar1config.png -O /usr/share/pixmaps/ar1config.png --quiet - sudo wget http://download.argon40.com/ar1uninstall.png -O /usr/share/pixmaps/ar1uninstall.png --quiet + imagefile=ar1config.png + if [ "$CHECKDEVICE" = "eon" ] + then + imagefile=argoneon.png + fi + sudo wget http://download.argon40.com/$imagefile -O /usr/share/pixmaps/$imagefile --quiet + if [ -f $shortcutfile ]; then + sudo rm $shortcutfile + fi + # Create Shortcuts echo "[Desktop Entry]" > $shortcutfile - echo "Name=Argon One Configuration" >> $shortcutfile - echo "Comment=Argon One Configuration" >> $shortcutfile - echo "Icon=/usr/share/pixmaps/ar1config.png" >> $shortcutfile - echo 'Exec='$terminalcmd' "Argon One Configuration" -e '$configscript >> $shortcutfile - echo "Type=Application" >> $shortcutfile - echo "Encoding=UTF-8" >> $shortcutfile - echo "Terminal=false" >> $shortcutfile - echo "Categories=None;" >> $shortcutfile - chmod 755 $shortcutfile - - shortcutfile="/home/pi/Desktop/argonone-uninstall.desktop" - echo "[Desktop Entry]" > $shortcutfile - echo "Name=Argon One Uninstall" >> $shortcutfile - echo "Comment=Argon One Uninstall" >> $shortcutfile - echo "Icon=/usr/share/pixmaps/ar1uninstall.png" >> $shortcutfile - echo 'Exec='$terminalcmd' -t "Argon One Uninstall" --working-directory=/home/pi/ -e '$removescript >> $shortcutfile + echo "Name=Argon Configuration" >> $shortcutfile + echo "Comment=Argon Configuration" >> $shortcutfile + echo "Icon=/usr/share/pixmaps/$imagefile" >> $shortcutfile + echo 'Exec='$terminalcmd' "Argon Configuration" -e '$configscript >> $shortcutfile echo "Type=Application" >> $shortcutfile echo "Encoding=UTF-8" >> $shortcutfile echo "Terminal=false" >> $shortcutfile @@ -629,23 +536,46 @@ then chmod 755 $shortcutfile fi -# IR config script -sudo wget https://download.argon40.com/argonone-irconfig.sh -O /usr/bin/argonone-ir --quiet -sudo chmod 755 /usr/bin/argonone-ir +configcmd="$(basename -- $configscript)" -echo "***************************" -echo "Argon One Setup Completed." -echo "***************************" -echo -if [ ! "$CHECKPLATFORM" = "Raspbian" ] +if [ "$setupmode" = "Setup" ] then - echo "You may need to reboot for changes to take effect" - echo -fi -if [ -f $shortcutfile ]; then - echo Shortcuts created in your desktop. + if [ -f "/usr/bin/$configcmd" ] + then + sudo rm /usr/bin/$configcmd + fi + sudo ln -s $configscript /usr/bin/$configcmd + + if [ "$CHECKDEVICE" = "one" ] + then + sudo ln -s $configscript /usr/bin/argonone-config + sudo ln -s $uninstallscript /usr/bin/argonone-uninstall + sudo ln -s $irconfigscript /usr/bin/argonone-ir + fi + + + # Enable and Start Service(s) + sudo systemctl daemon-reload + sudo systemctl enable argononed.service + sudo systemctl start argononed.service + if [ "$CHECKDEVICE" = "eon" ] + then + sudo systemctl enable argoneond.service + sudo systemctl start argoneond.service + fi else - echo Use 'argonone-config' to configure fan - echo Use 'argonone-uninstall' to uninstall + sudo systemctl daemon-reload + sudo systemctl restart argononed.service + if [ "$CHECKDEVICE" = "eon" ] + then + sudo systemctl restart argoneond.service + fi fi + +echo "*********************" +echo " $setupmode Completed " +echo "*********************" +$versioninfoscript +echo +echo "Use '$configcmd' to configure device" echo diff --git a/source/argonone-irconfig.sh b/source/argonone-irconfig.sh index 663e4a8..9be2028 100644 --- a/source/argonone-irconfig.sh +++ b/source/argonone-irconfig.sh @@ -134,7 +134,6 @@ then irtmpconfigfile=/dev/shm/argonirconfig.txt sudo systemctl stop irexec.service sudo systemctl disable irexec.service - sudo pip3 uninstall lirc -y sudo apt-get -y remove lirc sudo rm $irexecshfile sudo rm $irdecodefile @@ -241,8 +240,6 @@ then sudo apt-get -y update sudo apt-get -y install lirc - sudo pip3 install lirc - echo "dtoverlay=gpio-ir,gpio_pin=23" | sudo tee -a $CONFIG 1> /dev/null sudo /usr/share/lirc/lirc-old2new