Automated Change by GitHub Action

This commit is contained in:
okunze
2026-08-29 02:57:12 +00:00
committed by github-actions[bot]
parent a7203e0777
commit 6b88a8d613
6 changed files with 255 additions and 51 deletions
+51 -6
View File
@@ -72,11 +72,6 @@ else
fi fi
CONFIG=/boot${FIRMWARE}/config.txt CONFIG=/boot${FIRMWARE}/config.txt
set_config_var() {
if ! grep -q -E "$1=$2" $3 ; then
echo "$1=$2" | sudo tee -a $3 > /dev/null
fi
}
is_pifive() { is_pifive() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]4[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]4[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo
@@ -125,6 +120,56 @@ do_serial_hw() {
# End code lifted from raspi-config # End code lifted from raspi-config
########## ##########
set_config_var() {
# Own version that writes to [all] section
TARGET="$1=$2"
# Ensure [all] section exists
if ! grep -q "^\[all\]" "$3"; then
echo "[all]" | sudo tee -a "$3" > /dev/null
fi
# Extract the [all] section
ALL_SECTION=$(awk '
/^\[all\]/ {in_all=1; next}
/^\[/ && !/^\[all\]/ {in_all=0}
in_all {print}
' "$3")
echo "$ALL_SECTION" | grep -q "^$TARGET$"
EXISTS=$?
if [ $EXISTS -ne 0 ]
then
TMPCONFIG="/dev/shm/tmpconfig.txt"
# Append inside [all] section
sudo awk -v target="$TARGET" '
/^\[all\]/ {
print
in_all=1
next
}
/^\[/ && in_all==1 {
# We are leaving [all] section → append before next section
print target
in_all=0
}
{print}
END {
# If file ended while still in [all], append at end
if (in_all==1) {
print target
}
}
' "$3" > "$TMPCONFIG"
sudo tee "$3" < "$TMPCONFIG" > /dev/null
sudo rm "$TMPCONFIG"
fi
}
# Reuse is_pifive, set_config_var # Reuse is_pifive, set_config_var
set_nvme_default() { set_nvme_default() {
if is_pifive ; then if is_pifive ; then
@@ -271,7 +316,7 @@ then
cat $CONFIG | grep -v 'dtoverlay=dwc2' > $TMPCONFIGFILE cat $CONFIG | grep -v 'dtoverlay=dwc2' > $TMPCONFIGFILE
chmod 755 $TMPCONFIGFILE chmod 755 $TMPCONFIGFILE
sudo cp $TMPCONFIGFILE $CONFIG sudo cp $TMPCONFIGFILE $CONFIG
set_config_var dtoverlay=dwc2,dr_mode host $CONFIG set_config_var dtoverlay dwc2,dr_mode=host $CONFIG
rm $TMPCONFIGFILE rm $TMPCONFIGFILE
fi fi
+51 -6
View File
@@ -72,11 +72,6 @@ else
fi fi
CONFIG=/boot${FIRMWARE}/config.txt CONFIG=/boot${FIRMWARE}/config.txt
set_config_var() {
if ! grep -q -E "$1=$2" $3 ; then
echo "$1=$2" | sudo tee -a $3 > /dev/null
fi
}
is_pifive() { is_pifive() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]4[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]4[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo
@@ -125,6 +120,56 @@ do_serial_hw() {
# End code lifted from raspi-config # End code lifted from raspi-config
########## ##########
set_config_var() {
# Own version that writes to [all] section
TARGET="$1=$2"
# Ensure [all] section exists
if ! grep -q "^\[all\]" "$3"; then
echo "[all]" | sudo tee -a "$3" > /dev/null
fi
# Extract the [all] section
ALL_SECTION=$(awk '
/^\[all\]/ {in_all=1; next}
/^\[/ && !/^\[all\]/ {in_all=0}
in_all {print}
' "$3")
echo "$ALL_SECTION" | grep -q "^$TARGET$"
EXISTS=$?
if [ $EXISTS -ne 0 ]
then
TMPCONFIG="/dev/shm/tmpconfig.txt"
# Append inside [all] section
sudo awk -v target="$TARGET" '
/^\[all\]/ {
print
in_all=1
next
}
/^\[/ && in_all==1 {
# We are leaving [all] section → append before next section
print target
in_all=0
}
{print}
END {
# If file ended while still in [all], append at end
if (in_all==1) {
print target
}
}
' "$3" > "$TMPCONFIG"
sudo tee "$3" < "$TMPCONFIG" > /dev/null
sudo rm "$TMPCONFIG"
fi
}
# Reuse is_pifive, set_config_var # Reuse is_pifive, set_config_var
set_nvme_default() { set_nvme_default() {
if is_pifive ; then if is_pifive ; then
@@ -271,7 +316,7 @@ then
cat $CONFIG | grep -v 'dtoverlay=dwc2' > $TMPCONFIGFILE cat $CONFIG | grep -v 'dtoverlay=dwc2' > $TMPCONFIGFILE
chmod 755 $TMPCONFIGFILE chmod 755 $TMPCONFIGFILE
sudo cp $TMPCONFIGFILE $CONFIG sudo cp $TMPCONFIGFILE $CONFIG
set_config_var dtoverlay=dwc2,dr_mode host $CONFIG set_config_var dtoverlay dwc2,dr_mode=host $CONFIG
rm $TMPCONFIGFILE rm $TMPCONFIGFILE
fi fi
+49 -4
View File
@@ -69,14 +69,59 @@ else
fi fi
CONFIG=/boot${FIRMWARE}/config.txt CONFIG=/boot${FIRMWARE}/config.txt
# End code lifted from raspi-config
##########
set_config_var() { set_config_var() {
if ! grep -q -E "$1=$2" $3 ; then # Own version that writes to [all] section
echo "$1=$2" | sudo tee -a $3 > /dev/null TARGET="$1=$2"
# Ensure [all] section exists
if ! grep -q "^\[all\]" "$3"; then
echo "[all]" | sudo tee -a "$3" > /dev/null
fi
# Extract the [all] section
ALL_SECTION=$(awk '
/^\[all\]/ {in_all=1; next}
/^\[/ && !/^\[all\]/ {in_all=0}
in_all {print}
' "$3")
echo "$ALL_SECTION" | grep -q "^$TARGET$"
EXISTS=$?
if [ $EXISTS -ne 0 ]
then
TMPCONFIG="/dev/shm/tmpconfig.txt"
# Append inside [all] section
sudo awk -v target="$TARGET" '
/^\[all\]/ {
print
in_all=1
next
}
/^\[/ && in_all==1 {
# We are leaving [all] section → append before next section
print target
in_all=0
}
{print}
END {
# If file ended while still in [all], append at end
if (in_all==1) {
print target
}
}
' "$3" > "$TMPCONFIG"
sudo tee "$3" < "$TMPCONFIG" > /dev/null
sudo rm "$TMPCONFIG"
fi fi
} }
# End code lifted from raspi-config
##########
# Reuse set_config_var # Reuse set_config_var
set_nvme_default() { set_nvme_default() {
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
VERSIONINFO="2603002" VERSIONINFO="2608001"
echo "Version $VERSIONINFO" echo "Version $VERSIONINFO"
if [ -z "$1" ] if [ -z "$1" ]
+70 -27
View File
@@ -1,6 +1,5 @@
#!/bin/bash #!/bin/bash
if [ -e /boot/firmware/config.txt ] ; then if [ -e /boot/firmware/config.txt ] ; then
FIRMWARE=/firmware FIRMWARE=/firmware
else else
@@ -8,6 +7,57 @@ else
fi fi
CONFIG=/boot${FIRMWARE}/config.txt CONFIG=/boot${FIRMWARE}/config.txt
set_config_var() {
# Own version that writes to [all] section
TARGET="$1=$2"
# Ensure [all] section exists
if ! grep -q "^\[all\]" "$3"; then
echo "[all]" | sudo tee -a "$3" > /dev/null
fi
# Extract the [all] section
ALL_SECTION=$(awk '
/^\[all\]/ {in_all=1; next}
/^\[/ && !/^\[all\]/ {in_all=0}
in_all {print}
' "$3")
echo "$ALL_SECTION" | grep -q "^$TARGET$"
EXISTS=$?
if [ $EXISTS -ne 0 ]
then
TMPCONFIG="/dev/shm/tmpconfig.txt"
# Append inside [all] section
sudo awk -v target="$TARGET" '
/^\[all\]/ {
print
in_all=1
next
}
/^\[/ && in_all==1 {
# We are leaving [all] section → append before next section
print target
in_all=0
}
{print}
END {
# If file ended while still in [all], append at end
if (in_all==1) {
print target
}
}
' "$3" > "$TMPCONFIG"
sudo tee "$3" < "$TMPCONFIG" > /dev/null
sudo rm "$TMPCONFIG"
fi
}
set_config_var dtoverlay dwc2,dr_mode=host $CONFIG
CHECKGPIOMODE="libgpiod" # gpiod or rpigpio CHECKGPIOMODE="libgpiod" # gpiod or rpigpio
# Check if Raspbian, Ubuntu, others # Check if Raspbian, Ubuntu, others
@@ -56,18 +106,17 @@ daemonrtcservice=/lib/systemd/system/$rtcdaemonname.service
rtcdaemonscript=$INSTALLATIONFOLDER/$rtcdaemonname.py rtcdaemonscript=$INSTALLATIONFOLDER/$rtcdaemonname.py
echo "-----------------------------------"
echo " Argon Industria UPS Configuration"
echo "-----------------------------------"
requireinstall=0 requireinstall=0
newmode=0 newmode=0
if [ ! -z "$1" ] if [ ! -z "$1" ]
then then
requireinstall=1 requireinstall=1
newmode=3 # installation newmode=4 # installation
fi elif [ ! -f "$upsdaemonscript" ]
echo "-----------------------------------"
echo " Argon Industria UPS Configuration"
echo "-----------------------------------"
if [ ! -f "$upsdaemonscript" ]
then then
echo "Install Argon Industria UPS Tools" echo "Install Argon Industria UPS Tools"
echo -n "Press Y to continue:" echo -n "Press Y to continue:"
@@ -86,7 +135,7 @@ then
fi fi
requireinstall=1 requireinstall=1
newmode=3 # Reinstall newmode=4 # Reinstall
fi fi
@@ -117,12 +166,12 @@ get_number () {
UPSCMDFILE="/dev/shm/upscmd.txt" UPSCMDFILE="/dev/shm/upscmd.txt"
UPSSTATUSFILE="/dev/shm/upslog.txt" UPSSTATUSFILE="/dev/shm/upslog.txt"
upsconfigscript=$INSTALLATIONFOLDER/argonone-upsconfig.sh
rtcconfigscript=$INSTALLATIONFOLDER/argonups-rtcconfig.sh rtcconfigscript=$INSTALLATIONFOLDER/argonups-rtcconfig.sh
if [ -f "$UPSSTATUSFILE" ] && [ -f "$rtcconfigscript" ] if [ -f "$UPSSTATUSFILE" ] && [ -f "$rtcconfigscript" ]
then then
# cat $UPSSTATUSFILE
sudo $pythonbin $rtcdaemonscript GETBATTERY sudo $pythonbin $rtcdaemonscript GETBATTERY
fi fi
@@ -136,35 +185,28 @@ do
echo "Select option:" echo "Select option:"
echo " 1. UPS Battery Status" echo " 1. UPS Battery Status"
echo " 2. Configure RTC and/or Schedule" echo " 2. Configure RTC and/or Schedule"
echo " 3. Reinstall UPS Tools" echo " 3. Battery Meter Reset"
echo " 4. Uninstall UPS Tools" echo " 4. Reinstall UPS Tools"
echo " 5. Uninstall UPS Tools"
echo "" echo ""
echo " 0. Back" echo " 0. Back"
echo -n "Enter Number (0-4):" echo -n "Enter Number (0-5):"
newmode=$( get_number ) newmode=$( get_number )
fi fi
if [[ $newmode -ge 0 && $newmode -le 4 ]] if [[ $newmode -ge 0 && $newmode -le 5 ]]
then then
if [ $newmode -eq 1 ] if [ $newmode -eq 1 ]
then then
sudo $pythonbin $rtcdaemonscript GETBATTERY sudo $pythonbin $rtcdaemonscript GETBATTERY
#if [ -f "$UPSSTATUSFILE" ]
#then
# cat $UPSSTATUSFILE
#else
# echo "Unable to retrieve status"
#fi
elif [ $newmode -eq 2 ] elif [ $newmode -eq 2 ]
then then
$rtcconfigscript "argonupsrtc" $rtcconfigscript "argonupsrtc"
#TMPTIMESTR=`date +"%Y%d%m%H%M%S"`
#TMPDATASTR=`date +"%Y %m %d %H %M %S"`
#echo "$TMPTIMESTR" > $UPSCMDFILE
#echo "3 $TMPDATASTR" >> $UPSCMDFILE
elif [ $newmode -eq 3 ] elif [ $newmode -eq 3 ]
then
sudo $pythonbin $rtcdaemonscript BATTERYMETERRESET
elif [ $newmode -eq 4 ]
then then
# Start installation # Start installation
if [ ! -d "$INSTALLATIONFOLDER/ups" ] if [ ! -d "$INSTALLATIONFOLDER/ups" ]
@@ -217,7 +259,7 @@ do
echo "Name=Argon UPS" >> $shortcutfile echo "Name=Argon UPS" >> $shortcutfile
echo "Comment=Argon UPS" >> $shortcutfile echo "Comment=Argon UPS" >> $shortcutfile
echo "Icon=/etc/argon/ups/loading_0.png" >> $shortcutfile echo "Icon=/etc/argon/ups/loading_0.png" >> $shortcutfile
echo 'Exec='$terminalcmd' "Argon UPS" -e "'$rtcconfigscript' argonupsrtc"' >> $shortcutfile echo 'Exec='$terminalcmd' "Argon UPS" -e "'$upsconfigscript'"' >> $shortcutfile
echo "Type=Application" >> $shortcutfile echo "Type=Application" >> $shortcutfile
echo "Encoding=UTF-8" >> $shortcutfile echo "Encoding=UTF-8" >> $shortcutfile
echo "Terminal=false" >> $shortcutfile echo "Terminal=false" >> $shortcutfile
@@ -289,8 +331,9 @@ do
then then
# Called from setup script # Called from setup script
loopflag=0 loopflag=0
echo "You may need to restart for changes to take effect"
fi fi
elif [ $newmode -eq 4 ] elif [ $newmode -eq 5 ]
then then
sudo systemctl stop "$daemonname.service" sudo systemctl stop "$daemonname.service"
sudo systemctl disable "$daemonname.service" sudo systemctl disable "$daemonname.service"
+31 -5
View File
@@ -26,6 +26,7 @@ UPS_LOGFILE="/dev/shm/upslog.txt"
UPS_CMDFILE="/dev/shm/upscmd.txt" UPS_CMDFILE="/dev/shm/upscmd.txt"
RTC_CONFIGFILE = "/etc/argonupsrtc.conf" RTC_CONFIGFILE = "/etc/argonupsrtc.conf"
BATTERY_CONFIGFILE = "/etc/argonupsbattery.conf"
############# #############
@@ -130,11 +131,11 @@ def ups_sendcmd(cmdstr):
return outobj return outobj
def ups_loadlogdata(): def ups_loadlogdata(fname = UPS_LOGFILE):
# status, version, time, schedule # status, version, time, schedule
outobj = {} outobj = {}
try: try:
fp = open(UPS_LOGFILE, "r") fp = open(fname, "r")
logdata = fp.read() logdata = fp.read()
alllines = logdata.split("\n") alllines = logdata.split("\n")
ctr = 0 ctr = 0
@@ -151,6 +152,28 @@ def ups_loadlogdata():
return outobj return outobj
def ups_checkbatterydata(forcereset = False):
sendcmdid = -1
if forcereset == True:
sendcmdid = 9
else:
batterdataobj = ups_loadlogdata(BATTERY_CONFIGFILE)
try:
curtime = datetime.datetime.now()
lastreset = datetime.datetime.strptime(batterdataobj["lastreset"], "%a %b %d %H:%M:%S %Y")
# Compare difference
if curtime - lastreset > datetime.timedelta(days=30):
sendcmdid = 9
except:
# File not exists or entry not exists for reset
sendcmdid = 9
if sendcmdid == 9:
with open(BATTERY_CONFIGFILE, "w") as txt_file:
txt_file.write("lastreset: "+time.asctime(time.localtime(time.time()))+"\n")
return sendcmdid
def ups_check(readq): def ups_check(readq):
CMDSTARTBYTE=0xfe CMDSTARTBYTE=0xfe
CMDCONTROLBYTECOUNT=3 CMDCONTROLBYTECOUNT=3
@@ -160,12 +183,14 @@ def ups_check(readq):
lastcmdtime="" lastcmdtime=""
loopCtr = CHECKSTATUSLOOPFREQ loopCtr = CHECKSTATUSLOOPFREQ
sendcmdid = -1
ups_debuglog("serial", "Starting "+UPS_SERIALPORT) ups_debuglog("serial", "Starting "+UPS_SERIALPORT)
updatedesktopicon("Argon UPS", "Argon UPS", "/etc/argon/ups/loading_0.png") updatedesktopicon("Argon UPS", "Argon UPS", "/etc/argon/ups/loading_0.png")
sendcmdid = ups_checkbatterydata()
cmddatastr = ""
while True: # Outer loop to reconnect to device while True: # Outer loop to reconnect to device
qdata = "" qdata = ""
@@ -448,7 +473,7 @@ def updatedesktopicon(icontitle, statusstr, tmpiconfile):
#ups_debuglog("desktop-update-text", statusstr) #ups_debuglog("desktop-update-text", statusstr)
#ups_debuglog("desktop-update-icon", tmpiconfile) #ups_debuglog("desktop-update-icon", tmpiconfile)
with open(curfolder+"/Desktop/argonone-ups.desktop", "w") as txt_file: with open(curfolder+"/Desktop/argonone-ups.desktop", "w") as txt_file:
txt_file.write("[Desktop Entry]\nName="+icontitle+"\nComment="+statusstr+"\nIcon="+tmpiconfile+"\nExec=lxterminal --working-directory="+curfolder+"/ -t \"Argon UPS\" -e \"/etc/argon/argonone-upsconfig.sh argonupsrtc\"\nType=Application\nEncoding=UTF-8\nTerminal=false\nCategories=None;\n") txt_file.write("[Desktop Entry]\nName="+icontitle+"\nComment="+statusstr+"\nIcon="+tmpiconfile+"\nExec=lxterminal --working-directory="+curfolder+"/ -t \"Argon UPS\" -e \"/etc/argon/argonone-upsconfig.sh\"\nType=Application\nEncoding=UTF-8\nTerminal=false\nCategories=None;\n")
except Exception as desktope: except Exception as desktope:
#pass #pass
try: try:
@@ -486,7 +511,8 @@ if len(sys.argv) > 1:
print(outobj["power"]) print(outobj["power"])
except: except:
print("Error retrieving battery status") print("Error retrieving battery status")
elif cmd == "BATTERYMETERRESET":
ups_sendcmd("9")
elif cmd == "GETRTCSCHEDULE": elif cmd == "GETRTCSCHEDULE":
tmptime = getRTCpoweronschedule() tmptime = getRTCpoweronschedule()
if tmptime.year > 1999: if tmptime.year > 1999: