pandora-scripts: try to fix currentuser/home mess
authorGrazvydas Ignotas <notasas@gmail.com>
Tue, 22 Apr 2014 23:42:56 +0000 (02:42 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Tue, 22 Apr 2014 23:42:56 +0000 (02:42 +0300)
18 files changed:
recipes/pandora-system/pandora-scripts.bb
recipes/pandora-system/pandora-scripts/op_battlow.sh
recipes/pandora-system/pandora-scripts/op_bright.sh
recipes/pandora-system/pandora-scripts/op_bright_down.sh
recipes/pandora-system/pandora-scripts/op_bright_up.sh
recipes/pandora-system/pandora-scripts/op_common.sh [new file with mode: 0644]
recipes/pandora-system/pandora-scripts/op_createsd.sh
recipes/pandora-system/pandora-scripts/op_gamma.sh
recipes/pandora-system/pandora-scripts/op_lcdsettings.sh
recipes/pandora-system/pandora-scripts/op_ledsettings.sh
recipes/pandora-system/pandora-scripts/op_lidsettings.sh
recipes/pandora-system/pandora-scripts/op_menu.sh
recipes/pandora-system/pandora-scripts/op_paths.sh [deleted file]
recipes/pandora-system/pandora-scripts/op_power.sh
recipes/pandora-system/pandora-scripts/op_startupmanager.sh
recipes/pandora-system/pandora-scripts/op_usermanager.sh
recipes/pandora-system/pandora-state.bb
recipes/pandora-system/pandora-state/rc.pandora-state

index f36fce7..1046464 100644 (file)
@@ -5,11 +5,11 @@ COMPATIBLE_MACHINE = "omap3-pandora"
 
 RDEPENDS = "bash sed gawk grep zenity"
 
-PR = "r157"
+PR = "r158"
 
 SRC_URI = " \
-          file://op_paths.sh \
           file://op_bright.sh \
+          file://op_common.sh \
           file://op_cpuspeed.sh \
           file://op_cpuspeed.pnd \     
           file://op_dspspeed.sh \
@@ -94,7 +94,7 @@ SRC_URI = " \
 
 do_install() {
           install -d ${D}${prefix}/pandora/scripts/
-          install -m 0755 ${WORKDIR}/op_paths.sh ${D}${prefix}/pandora/scripts/
+          install -m 0755 ${WORKDIR}/op_common.sh ${D}${prefix}/pandora/scripts/
           install -m 0755 ${WORKDIR}/op_getpndmg.sh ${D}${prefix}/pandora/scripts/
          install -m 0755 ${WORKDIR}/op_osupgrade.sh ${D}${prefix}/pandora/scripts/
           install -m 0755 ${WORKDIR}/op_bright.sh ${D}${prefix}/pandora/scripts/
index de4e21a..d197b73 100644 (file)
@@ -1,6 +1,9 @@
 #!/bin/bash
-#usage op_shutdown.sh time in seconds
-xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
+# usage: op_shutdown.sh time in seconds
+
+. /usr/pandora/scripts/op_common.sh
+xfceuser=$(get_user)
+
 time=$1
 if [ x$time = "x" ]; then
        time=30
index 709b3af..872a225 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-. /usr/pandora/scripts/op_paths.sh
+. /usr/pandora/scripts/op_common.sh
 
 # get value range
 minbright=3
index 964240f..3144b31 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /usr/pandora/scripts/op_paths.sh
+. /usr/pandora/scripts/op_common.sh
 
 cur=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
 if [ "$cur" -gt "40" ]; then
index b6deab7..fc5033c 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /usr/pandora/scripts/op_paths.sh
+. /usr/pandora/scripts/op_common.sh
 
 cur=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
 max=$(cat $SYSFS_BACKLIGHT/max_brightness)
diff --git a/recipes/pandora-system/pandora-scripts/op_common.sh b/recipes/pandora-system/pandora-scripts/op_common.sh
new file mode 100644 (file)
index 0000000..da2f977
--- /dev/null
@@ -0,0 +1,52 @@
+
+# files changing between kernel versions
+
+if [ -e /sys/class/backlight/pandora-backlight ]; then
+       SYSFS_BACKLIGHT=/sys/class/backlight/pandora-backlight
+elif [ -e /sys/class/backlight/twl4030-pwm0-bl ]; then
+       SYSFS_BACKLIGHT=/sys/class/backlight/twl4030-pwm0-bl
+else
+       echo "ERROR: backlight control not found" >&2
+       SYSFS_BACKLIGHT=/dev/null
+fi
+SYSFS_BACKLIGHT_BRIGHTNESS=${SYSFS_BACKLIGHT}/brightness
+
+if [ -e /sys/devices/omapdss/display0/gamma ]; then
+       SYSFS_GAMMA=/sys/devices/omapdss/display0/gamma
+elif [ -e /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma ]; then
+       SYSFS_GAMMA=/sys/devices/platform/omap2_mcspi.1/spi1.1/gamma
+else
+       echo "ERROR: gamma control not found" >&2
+       SYSFS_GAMMA=/dev/null
+fi
+
+SYSFS_DSS_GAMMA=/sys/devices/platform/omapdss/display0/dss_gamma
+
+# scripts run as root, but often need currently logged-in user
+get_user()
+{
+       # this file is created by .xinitrc
+       test -f /tmp/currentuser && _gu_user=$(cat /tmp/currentuser)
+       if [ -z "$_gu_user" ]; then
+               # try xfce4-session. ps can output names but only upto 19 chars, so resolve manually..
+               _gu_user_id=$(ps --no-headers -o ruid -C xfce4-session | tail -n1 | awk '{print $1}')
+               _gu_user=$(grep ":x:$_gu_user_id:" /etc/passwd | awk -F: '{print $1}')
+       fi
+       if [ -z "$_gu_user" ]; then
+               echo "ERROR: can't determine currently logged-in user" >&2
+               exit 1
+       fi
+       echo $_gu_user
+}
+
+get_user_home()
+{
+       _gu_user=$(get_user)
+       _gu_user_home=$(grep "^$_gu_user:" /etc/passwd | awk -F: '{print $6}')
+       if [ -z "$_gu_user_home" ]; then
+               echo "ERROR: can't determine currently logged-in user's home" >&2
+               exit 1
+       fi
+       echo $_gu_user_home
+}
+
index 54796cd..2381e8a 100644 (file)
@@ -1,4 +1,8 @@
 #!/bin/bash
+
+. /usr/pandora/scripts/op_common.sh
+user=$(get_user)
+
 if selection=$(grep "/dev/mmcblk" /proc/mounts | cut -f 2 -d " " | sed 's/\\040/ /g' | zenity --title="Create Pandora SD Card" --width="380" --height="250" --list --text="This utility creates the needed Pandora directories on your SD Card.\nYou can also use it to format your SD Card.\n\nPlease select the SD Card to be used (no data will be changed yet):" --column="Select card"); then
 selection2=$(echo "$selection" | sed 's/ /\\\\040/g')
 device=$(grep "${selection2}" /proc/mounts | awk '{print $1}')
@@ -37,7 +41,6 @@ device=$(grep "${selection2}" /proc/mounts | awk '{print $1}')
                                sync
                                gksudo mkdir /tmp/mnt
                                if gksudo mount $device /tmp/mnt; then
-                                               user=$(cat /tmp/currentuser)
                                                gksudo mkdir /tmp/mnt/pandora
                                                gksudo mkdir /tmp/mnt/pandora/menu
                                                gksudo mkdir /tmp/mnt/pandora/apps
index 7ac4892..a5c0a6b 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /usr/pandora/scripts/op_paths.sh
+. /usr/pandora/scripts/op_common.sh
 
 if [ ! -e "$SYSFS_DSS_GAMMA" ]; then
   echo "Control file is missing, might be incompatible kernel"
index f915cc5..51f5fe7 100644 (file)
@@ -3,7 +3,9 @@
 # Video-Settings, v1.2, written by Michael Mrozek aka EvilDragon 2010. Brightness-Settings-Part written by vimacs.
 # This scripts allows you to create, load and save Gamma-Settings and to change the LCD Brightness.
 
- . /usr/pandora/scripts/op_paths.sh
+. /usr/pandora/scripts/op_common.sh
+user=$(get_user)
+user_home=$(get_user_home)
 
 while mainsel=$(zenity --title="Video Settings" --width="300" --height="370" --list --column "id" --column "Please select" --hide-column=1 --text="Welcome to the Video Settings-Dialogue.\n\nWhat do you want to do?\n" "bright" "Change LCD Brightness" "gammasimple" "Manage Gamma (simple)" "gamma" "Manage Gamma (Advanced)" "filter" "Select current video filter" "filterdef" "Select default video filter" "sblank" "Enable/disable screen blanking" "rightclickmode" "Select Right-Click-Mode for touchscreen" "tvout" "Enable/disable TV Out on Startup" --ok-label="Change Setting" --cancel-label="Exit"); do
 
@@ -89,13 +91,12 @@ case $mainsel in
     fi;;
 
     "sblank")
-     user=$(cat /tmp/currentuser)
      if zenity --question --title="Screen blanking" --text="Do you want to enable or disable the automatic screen blanking?" --ok-label="Enable it" --cancel-label="Disable it"; then 
-       sed -i "s/.*xset.*/# DISPLAY=:0 xset s off/g" /home/${user}/.xinitrc
+       sed -i "s/.*xset.*/# DISPLAY=:0 xset s off/g" $user_home/.xinitrc
         zenity --info --title="Screen blanking" --text "The automatic screen blanking has been enabled." --timeout 6
         DISPLAY=:0 xset s on
        else
-         sed -i "s/.*xset.*/DISPLAY=:0 xset s off/g" /home/${user}/.xinitrc
+         sed -i "s/.*xset.*/DISPLAY=:0 xset s off/g" $user_home/.xinitrc
          zenity --info --title="Screen blanking" --text "The automatic screen blanking has been disabled." --timeout 6
          DISPLAY=:0 xset s off
        fi;;
@@ -110,12 +111,11 @@ case $mainsel in
       done;;
       
       "rightclickmode")
-      user=$(cat /tmp/currentuser)
       if zenity --question --title="Right-Click Mode" --text="Choose how you would like to do a right-click with the touchscreen: You can either use the click-and-hold-method to right click or to use ALT as modifier key." --ok-label="ALT as modifier" --cancel-label="Click-and-Hold"; then 
-         echo 'mode = 1' > /home/$user/Applications/Settings/libgtkstylus.conf
+         echo 'mode = 1' > $user_home/Applications/Settings/libgtkstylus.conf
          zenity --info --title="Right-Click" --text "To do a right-click with the stylus, press and hold the ALT button while clicking.\n\nYou need to restart X to enable this." --timeout 6
        else
-         echo 'mode = 0' > /home/$user/Applications/Settings/libgtkstylus.conf
+         echo 'mode = 0' > $user_home/Applications/Settings/libgtkstylus.conf
          zenity --info --title="Right-Click" --text "To do a right-click with the stylus, press and hold the stylus on the screen.\n\nYou need to restart X to enable this." --timeout 6
        fi;;     
        
index 52f9a07..a1f8fe7 100644 (file)
@@ -2,7 +2,7 @@
 # Released under the GPL
 # LED-Settings, v1.0, written by Michael Mrozek aka EvilDragon 2013.
 
- . /usr/pandora/scripts/op_paths.sh
+ . /usr/pandora/scripts/op_common.sh
 
 while mainsel=$(zenity --title="LED-Settings" --width="400" --height="370" --list --column "id" --column "Please select" --hide-column=1 --text="Welcome to the LED-Settings-Dialogue.\n\nWhat do you want to do?\n" "normal" "Set Power LED Brightness (normal mode)" "power" "Set Power LED Brightness (powersave)" "sd1" "Enable / Disable SD1 LED" "sd2" "Enable / Disable SD2 LED" "wifi" "Enable / Disable WiFi LED" "bt" "Enable / Disable Bluetooth LED"  --ok-label="Change Setting" --cancel-label="Exit"); do
 
index 995d4ec..8c191c6 100644 (file)
@@ -1,6 +1,10 @@
 #!/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
+
+. /usr/pandora/scripts/op_common.sh
+user_home=$(get_user_home)
+
+case "$(cat $user_home/.lidconfig)" in
        "lowpower")
                current="the Pandora goes into low power mode"
        ;;
@@ -14,4 +18,4 @@ esac
 
 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" > $user_home/.lidconfig
index 43e3c41..e8ebf36 100644 (file)
@@ -1,11 +1,14 @@
 #!/bin/bash
-#actions done when the menu button is pressed
-#only argument is the time the button was pressed in  seconds
+# actions done when the menu button is pressed
+# only argument is the time the button was pressed in seconds
 
 if [ -x /usr/pandora/scripts/op_menu_custom.sh ]; then
   exec /usr/pandora/scripts/op_menu_custom.sh "$@"
 fi
 
+. /usr/pandora/scripts/op_common.sh
+xfceuser=$(get_user)
+
 do_kill()
 {
   for PID in "$@"; do
@@ -31,8 +34,6 @@ fi
 xpid=$(pidof xfce4-session)
 if [ $xpid ]; then
   echo "xfce4 is running"
-  # note: max username length ps can output is 19, otherwise it prints uid
-  xfceuser=$(ps -o user:20= -C xfce4-session | tail -n1 | awk '{print $1}')
   if [ $killist ]; then
     echo "displaying kill list"
     pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*-\(.*\)(\([0-9]\+\))/\2\n \1/p' | su -c 'DISPLAY=:0.0 zenity --list --multiple --column "pid" --column "name" --title "kill" --text "which apps should be killed"' - $xfceuser | sed 's/|/\n/')
diff --git a/recipes/pandora-system/pandora-scripts/op_paths.sh b/recipes/pandora-system/pandora-scripts/op_paths.sh
deleted file mode 100644 (file)
index ecc2b6e..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-
-# files changing between kernel versions
-
-if [ -e /sys/class/backlight/pandora-backlight ]; then
-       SYSFS_BACKLIGHT=/sys/class/backlight/pandora-backlight
-elif [ -e /sys/class/backlight/twl4030-pwm0-bl ]; then
-       SYSFS_BACKLIGHT=/sys/class/backlight/twl4030-pwm0-bl
-else
-       echo "ERROR: backlight control not found" >&2
-       SYSFS_BACKLIGHT=/dev/null
-fi
-SYSFS_BACKLIGHT_BRIGHTNESS=${SYSFS_BACKLIGHT}/brightness
-
-if [ -e /sys/devices/omapdss/display0/gamma ]; then
-       SYSFS_GAMMA=/sys/devices/omapdss/display0/gamma
-elif [ -e /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma ]; then
-       SYSFS_GAMMA=/sys/devices/platform/omap2_mcspi.1/spi1.1/gamma
-else
-       echo "ERROR: gamma control not found" >&2
-       SYSFS_GAMMA=/dev/null
-fi
-
-SYSFS_DSS_GAMMA=/sys/devices/platform/omapdss/display0/dss_gamma
index bba0f51..9b0e1b2 100644 (file)
@@ -1,6 +1,8 @@
 #!/bin/bash
 
-. /usr/pandora/scripts/op_paths.sh
+. /usr/pandora/scripts/op_common.sh
+xfceuser=$(get_user)
+xfceuser_home=$(get_user_home)
 
 # XXX: better use lockfile (or something), but it's not in current firmware
 test -e /tmp/op_power.lock && exit 2
@@ -12,9 +14,7 @@ debug(){
        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
-
-#powerbuttonconfig=$(cat $(grep /etc/passwd -e ^$(ps u -C xfce4-session | tail -n1 | awk '{print $1}'): | cut -f 6 -d ":")/.powerbuttonconfig)
+test -e $xfceuser_home/.lidconfig && lidconfig=$(cat $xfceuser_home/.lidconfig) # read lid conf. file if it exists
 
 if [ -e /tmp/powerstate ]; then 
        powerstate="$(cat /tmp/powerstate)"
@@ -138,7 +138,6 @@ display_on_with_checks() {
 
 show_message() {
        # TODO: check if desktop is visible; maybe use layer3?
-       xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
        cmd="DISPLAY=:0.0 zenity --info --text \"$1\" --timeout 10"
        su -c "$cmd" $xfceuser
 }
@@ -254,7 +253,6 @@ resume() {
 }
 
 shutdown(){ # warns the user and shuts the pandora down
-       xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
        time=5
        countdown () {
                for i in $(seq $time); do
index 17e5e71..dafede2 100755 (executable)
@@ -3,6 +3,10 @@
 # Startup-Manager, v1.1, written by Michael Mrozek aka EvilDragon 2010 with some help by vimacs.
 # This scripts allows you to change various settings of the Pandora startup process.
 
+. /usr/pandora/scripts/op_common.sh
+user2=$(get_user)
+user2_home=$(get_user_home)
+
 while mainsel=$(zenity --title="Startup manager" --width="400" --height="310" --list --column "id" --column "Please select" --hide-column=1 --text="Welcome to the Startup Settings\n\nHere you can change the default boot-up behaviour of your Pandora.\n\nWhat do you want to do?\n" "gui" "Change Default GUI for current user" "login" "Enable/Disable auto login" "user" "Select default user" "service" "Enable/Disable services on boot" --ok-label="Change Setting" --cancel-label="Exit"); do
 
 
@@ -10,7 +14,6 @@ case $mainsel in
 
 # Change default GUI
   "gui")
-    user2=$(cat /tmp/currentuser)
     selection=$(cat /etc/pandora/conf/gui.conf | awk -F\; '{print $1 "\n" $2 }' | zenity ---width=500 --height=300 --title="Change the default GUI" --list --column "Name" --column "Description" --text "Please select the GUI you want to run as default startup" )
 
     echo $selection
@@ -18,7 +21,7 @@ case $mainsel in
     gui=$(grep $selection /etc/pandora/conf/gui.conf | awk -F\; '{print $3}')
 
     if [ $gui ]; then 
-      sed -i "s/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=$gui/g" /home/$user2/.xinitrc
+      sed -i "s/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=$gui/g" $user2_home/.xinitrc
       zenity --info --title="Changed session" --text "The default session has been changed to $selection." --timeout 6
     fi;;
 
@@ -66,4 +69,4 @@ case $mainsel in
        done
 ;;
 esac
-done 
\ No newline at end of file
+done 
index 7637cb1..4747771 100755 (executable)
@@ -5,6 +5,9 @@
 # Reworked for the OpenPandora - John Willis/Michael Mrozek
 # This scripts allows you to create and remove users from the Pandora system.
 
+. /usr/pandora/scripts/op_common.sh
+user2=$(get_user)
+
 while selection=$(zenity --title="Usermanager" --list --column "id" --column "Please select" --hide-column=1 --text="What do you want to do?" "add" "Add a user" "remove" "Remove a user" ); do
   if [ ${selection} = "add" ]; then
        echo "Add user"
@@ -43,7 +46,6 @@ EOF
          fi
        fi
   elif [ ${selection} = "remove" ]; then
-        user2=$(cat /tmp/currentuser)
         echo "Remove User"
        amount=$(cat /etc/passwd | grep /home/ | grep -v root | awk -F\: '{print $1 }' | wc -l)
        if [ ${amount} = "1" ]; then
index d5c02d6..7a38bf1 100755 (executable)
@@ -5,7 +5,7 @@ COMPATIBLE_MACHINE = "omap3-pandora"
 
 RDEPENDS = "pandora-scripts"
 
-PR = "r22"
+PR = "r23"
 inherit update-rc.d
 
 INITSCRIPT_NAME = "pandora-state"
index 53d6272..144f1ff 100644 (file)
@@ -11,7 +11,7 @@
 DESC="OpenPandora Save and Restore various settings"
 NAME="pandora-state"
 
-. /usr/pandora/scripts/op_paths.sh
+. /usr/pandora/scripts/op_common.sh
 
 d_stop() {
        echo "Saving Pandora specific settings"