- Status Closed
- Percent Complete
- Task Type Bug Report
- Category Core
- Operating System Release 1 (Zaxxon)
- Severity Medium
- Reported Version SuperZaxxon Final 1.54
Opened by russ - 03.03.2014
Last edited by Grazvydas - 22.03.2014
FS#332 - op_lidsettings.sh and op_power.sh scripts fail for some usernames
/usr/pandora/scripts/op_lidsettings.sh and /usr/pandora/scripts/op_power.sh fail for some usernames due to poor shell scripting
these scripts find their config files by grepping /etc/passwd for the uer currently running xfce4-session, but the loose regexp matches too much. this shell fragment from op_lidsettings.sh:
grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":"
when a use called "me" is logged in, returns
/home/root
/usr/games
/var/run/dbus
/home/me
rather than just "/home/me"
all instances of that construct (reading and writing settings, in both op_lidsettings.sh and op_power.sh) should be changed to
grep /etc/passwd -e ^$(ps u -C xfce4-session | tail -n1 | awk '{print $1}'): | cut -f 6 -d ":"
to correctly match only the complete username field in /etc/passwd
22.03.2014 17:02
Reason for closing: Fixed
Additional comments about closing: applied
It doesn't look like we have active firmware developers to fix this, but if you could prepare a patch or fixed versions of the scripts, I could apply them for next update.
"finding the user's home directory" really ought to be factored out to somewhere generic (/usr/pandora/scripts/op_paths.sh perhaps, assuming there's some reason this all doesn't just use $HOME), but if this OS release series is moribund I'll just fix what's broken rather than cleaning up the ugliness. patch inline below.
diff -ur /tmp/ubifs_root/usr/pandora/scripts/op_lidsettings.sh /usr/pandora/scripts/op_lidsettings.sh
--- /tmp/ubifs_root/usr/pandora/scripts/op_lidsettings.sh 2013-12-18 23:05:23.000000000 +1100
+++ /usr/pandora/scripts/op_lidsettings.sh 2014-03-03 17:13:09.100952719 +1100
@@ -1,6 +1,6 @@
#!/bin/bash
# change what to do when the lid is closed/opened
-case "$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidconfig)" in
+case "$(cat $(grep /etc/passwd -e ^$(ps u -C xfce4-session | tail -n1 | awk '{print $1}'): | cut -f 6 -d ":")/.lidconfig)" in
"lowpower")
current="the Pandora goes into low power mode"
;;
@@ -14,4 +14,4 @@
sel=$(zenity --title="Lid settings" --height=250 --list --column "id" --column "Please select" --hide-column=1 --text="What should happen when you close the Pandora's lid?\n(the opposite of the selected action is performed when opening the lid again)\nAt the moment $current when you close the lid." "brightness" "Turn off the screen." "lowpower" "Go into low power mode (same as when pressing the
power button for less than 3 seconds)" "shutdown" "Shut the pandora down.") || exit
-echo "$sel" > $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidconfig
+echo "$sel" > $(grep /etc/passwd -e ^$(ps u -C xfce4-session | tail -n1 | awk '{print $1}'): | cut -f 6 -d ":")/.lidconfig
diff -ur /tmp/ubifs_root/usr/pandora/scripts/op_power.sh /usr/pandora/scripts/op_power.sh
--- /tmp/ubifs_root/usr/pandora/scripts/op_power.sh 2013-12-18 23:05:23.000000000 +1100
+++ /usr/pandora/scripts/op_power.sh 2014-03-17 12:02:15.230625296 +1100
@@ -12,9 +12,9 @@
return 1 # 0 when debugging, 1 when not
}
-test -e $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidconfig && lidconfig=$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidconfig) # read lid conf. file if it exists
+test -e $(grep /etc/passwd -e ^$(ps u -C xfce4-session | tail -n1 | awk '{print $1}'): | cut -f 6 -d ":")/.lidconfig && lidconfig=$(cat $(grep /etc/passwd -e ^$(ps u -C xfce4-session | tail -n1 | awk '{print $1}'): | cut -f 6 -d ":")/.lidconfig) # read lid conf. file if it exists
-#powerbuttonconfig=$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.powerbuttonconfig)
+#powerbuttonconfig=$(cat $(grep /etc/passwd -e ^$(ps u -C xfce4-session | tail -n1 | awk '{print $1}'): | cut -f 6 -d ":")/.powerbuttonconfig)
if [ -e /tmp/powerstate ]; then
powerstate="$(cat /tmp/powerstate)"