mirror of
https://github.com/okunze/Argon40-ArgonOne-Script.git
synced 2026-08-30 02:06:32 +02:00
Automated Change by GitHub Action
This commit is contained in:
committed by
github-actions[bot]
parent
a7203e0777
commit
6b88a8d613
+51
-6
@@ -72,11 +72,6 @@ else
|
||||
fi
|
||||
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() {
|
||||
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
|
||||
##########
|
||||
|
||||
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
|
||||
set_nvme_default() {
|
||||
if is_pifive ; then
|
||||
@@ -271,7 +316,7 @@ then
|
||||
cat $CONFIG | grep -v 'dtoverlay=dwc2' > $TMPCONFIGFILE
|
||||
chmod 755 $TMPCONFIGFILE
|
||||
sudo cp $TMPCONFIGFILE $CONFIG
|
||||
set_config_var dtoverlay=dwc2,dr_mode host $CONFIG
|
||||
set_config_var dtoverlay dwc2,dr_mode=host $CONFIG
|
||||
rm $TMPCONFIGFILE
|
||||
fi
|
||||
|
||||
|
||||
+51
-6
@@ -72,11 +72,6 @@ else
|
||||
fi
|
||||
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() {
|
||||
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
|
||||
##########
|
||||
|
||||
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
|
||||
set_nvme_default() {
|
||||
if is_pifive ; then
|
||||
@@ -271,7 +316,7 @@ then
|
||||
cat $CONFIG | grep -v 'dtoverlay=dwc2' > $TMPCONFIGFILE
|
||||
chmod 755 $TMPCONFIGFILE
|
||||
sudo cp $TMPCONFIGFILE $CONFIG
|
||||
set_config_var dtoverlay=dwc2,dr_mode host $CONFIG
|
||||
set_config_var dtoverlay dwc2,dr_mode=host $CONFIG
|
||||
rm $TMPCONFIGFILE
|
||||
fi
|
||||
|
||||
|
||||
+51
-6
@@ -69,15 +69,60 @@ else
|
||||
fi
|
||||
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
|
||||
}
|
||||
|
||||
# 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 set_config_var
|
||||
set_nvme_default() {
|
||||
set_config_var dtparam nvme $CONFIG
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSIONINFO="2603002"
|
||||
VERSIONINFO="2608001"
|
||||
|
||||
echo "Version $VERSIONINFO"
|
||||
if [ -z "$1" ]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
if [ -e /boot/firmware/config.txt ] ; then
|
||||
FIRMWARE=/firmware
|
||||
else
|
||||
@@ -8,6 +7,57 @@ else
|
||||
fi
|
||||
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
|
||||
|
||||
# Check if Raspbian, Ubuntu, others
|
||||
@@ -56,18 +106,17 @@ daemonrtcservice=/lib/systemd/system/$rtcdaemonname.service
|
||||
rtcdaemonscript=$INSTALLATIONFOLDER/$rtcdaemonname.py
|
||||
|
||||
|
||||
echo "-----------------------------------"
|
||||
echo " Argon Industria UPS Configuration"
|
||||
echo "-----------------------------------"
|
||||
|
||||
requireinstall=0
|
||||
newmode=0
|
||||
if [ ! -z "$1" ]
|
||||
then
|
||||
requireinstall=1
|
||||
newmode=3 # installation
|
||||
fi
|
||||
|
||||
echo "-----------------------------------"
|
||||
echo " Argon Industria UPS Configuration"
|
||||
echo "-----------------------------------"
|
||||
if [ ! -f "$upsdaemonscript" ]
|
||||
newmode=4 # installation
|
||||
elif [ ! -f "$upsdaemonscript" ]
|
||||
then
|
||||
echo "Install Argon Industria UPS Tools"
|
||||
echo -n "Press Y to continue:"
|
||||
@@ -86,7 +135,7 @@ then
|
||||
fi
|
||||
|
||||
requireinstall=1
|
||||
newmode=3 # Reinstall
|
||||
newmode=4 # Reinstall
|
||||
|
||||
fi
|
||||
|
||||
@@ -117,12 +166,12 @@ get_number () {
|
||||
|
||||
UPSCMDFILE="/dev/shm/upscmd.txt"
|
||||
UPSSTATUSFILE="/dev/shm/upslog.txt"
|
||||
upsconfigscript=$INSTALLATIONFOLDER/argonone-upsconfig.sh
|
||||
rtcconfigscript=$INSTALLATIONFOLDER/argonups-rtcconfig.sh
|
||||
|
||||
|
||||
if [ -f "$UPSSTATUSFILE" ] && [ -f "$rtcconfigscript" ]
|
||||
then
|
||||
# cat $UPSSTATUSFILE
|
||||
sudo $pythonbin $rtcdaemonscript GETBATTERY
|
||||
fi
|
||||
|
||||
@@ -136,35 +185,28 @@ do
|
||||
echo "Select option:"
|
||||
echo " 1. UPS Battery Status"
|
||||
echo " 2. Configure RTC and/or Schedule"
|
||||
echo " 3. Reinstall UPS Tools"
|
||||
echo " 4. Uninstall UPS Tools"
|
||||
echo " 3. Battery Meter Reset"
|
||||
echo " 4. Reinstall UPS Tools"
|
||||
echo " 5. Uninstall UPS Tools"
|
||||
echo ""
|
||||
echo " 0. Back"
|
||||
|
||||
echo -n "Enter Number (0-4):"
|
||||
echo -n "Enter Number (0-5):"
|
||||
|
||||
newmode=$( get_number )
|
||||
fi
|
||||
if [[ $newmode -ge 0 && $newmode -le 4 ]]
|
||||
if [[ $newmode -ge 0 && $newmode -le 5 ]]
|
||||
then
|
||||
if [ $newmode -eq 1 ]
|
||||
then
|
||||
sudo $pythonbin $rtcdaemonscript GETBATTERY
|
||||
#if [ -f "$UPSSTATUSFILE" ]
|
||||
#then
|
||||
# cat $UPSSTATUSFILE
|
||||
#else
|
||||
# echo "Unable to retrieve status"
|
||||
#fi
|
||||
elif [ $newmode -eq 2 ]
|
||||
then
|
||||
$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 ]
|
||||
then
|
||||
sudo $pythonbin $rtcdaemonscript BATTERYMETERRESET
|
||||
elif [ $newmode -eq 4 ]
|
||||
then
|
||||
# Start installation
|
||||
if [ ! -d "$INSTALLATIONFOLDER/ups" ]
|
||||
@@ -217,7 +259,7 @@ do
|
||||
echo "Name=Argon UPS" >> $shortcutfile
|
||||
echo "Comment=Argon UPS" >> $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 "Encoding=UTF-8" >> $shortcutfile
|
||||
echo "Terminal=false" >> $shortcutfile
|
||||
@@ -289,8 +331,9 @@ do
|
||||
then
|
||||
# Called from setup script
|
||||
loopflag=0
|
||||
echo "You may need to restart for changes to take effect"
|
||||
fi
|
||||
elif [ $newmode -eq 4 ]
|
||||
elif [ $newmode -eq 5 ]
|
||||
then
|
||||
sudo systemctl stop "$daemonname.service"
|
||||
sudo systemctl disable "$daemonname.service"
|
||||
|
||||
@@ -26,6 +26,7 @@ UPS_LOGFILE="/dev/shm/upslog.txt"
|
||||
UPS_CMDFILE="/dev/shm/upscmd.txt"
|
||||
|
||||
RTC_CONFIGFILE = "/etc/argonupsrtc.conf"
|
||||
BATTERY_CONFIGFILE = "/etc/argonupsbattery.conf"
|
||||
|
||||
|
||||
#############
|
||||
@@ -130,11 +131,11 @@ def ups_sendcmd(cmdstr):
|
||||
|
||||
return outobj
|
||||
|
||||
def ups_loadlogdata():
|
||||
def ups_loadlogdata(fname = UPS_LOGFILE):
|
||||
# status, version, time, schedule
|
||||
outobj = {}
|
||||
try:
|
||||
fp = open(UPS_LOGFILE, "r")
|
||||
fp = open(fname, "r")
|
||||
logdata = fp.read()
|
||||
alllines = logdata.split("\n")
|
||||
ctr = 0
|
||||
@@ -151,6 +152,28 @@ def ups_loadlogdata():
|
||||
|
||||
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):
|
||||
CMDSTARTBYTE=0xfe
|
||||
CMDCONTROLBYTECOUNT=3
|
||||
@@ -160,12 +183,14 @@ def ups_check(readq):
|
||||
|
||||
lastcmdtime=""
|
||||
loopCtr = CHECKSTATUSLOOPFREQ
|
||||
sendcmdid = -1
|
||||
|
||||
ups_debuglog("serial", "Starting "+UPS_SERIALPORT)
|
||||
|
||||
updatedesktopicon("Argon UPS", "Argon UPS", "/etc/argon/ups/loading_0.png")
|
||||
|
||||
sendcmdid = ups_checkbatterydata()
|
||||
cmddatastr = ""
|
||||
|
||||
while True: # Outer loop to reconnect to device
|
||||
|
||||
qdata = ""
|
||||
@@ -448,7 +473,7 @@ def updatedesktopicon(icontitle, statusstr, tmpiconfile):
|
||||
#ups_debuglog("desktop-update-text", statusstr)
|
||||
#ups_debuglog("desktop-update-icon", tmpiconfile)
|
||||
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:
|
||||
#pass
|
||||
try:
|
||||
@@ -486,7 +511,8 @@ if len(sys.argv) > 1:
|
||||
print(outobj["power"])
|
||||
except:
|
||||
print("Error retrieving battery status")
|
||||
|
||||
elif cmd == "BATTERYMETERRESET":
|
||||
ups_sendcmd("9")
|
||||
elif cmd == "GETRTCSCHEDULE":
|
||||
tmptime = getRTCpoweronschedule()
|
||||
if tmptime.year > 1999:
|
||||
|
||||
Reference in New Issue
Block a user