may88
Well-Known Member
I´ve only just got my Pandora and at the week-end I was looking at the /usr/pandora/scripts scripts and was thus introduced to zenity.  I was also reading many of the mali/gruso tricks, one of which was the mounting up of PND.
I wrote this script to put a gui front-end to the process. It´s a bit simple but I´ve found it useful to spot the odd duff PND download.
not sure I understand how pnd_run behaves. It may have been caused by running out of memory but I ended up with DOSBOX linked to deadbeef in /mnt/utmp. deadbeef was working happily but the mount showed dosbox´s contents.
okay, I need to PND it but for now I just made a bin directory in my homedir and added this to the PATH variable in my .profile and then ran it from the command line. (detailed instructions on request if any linux newbies are reading this)
	
	
		
			
	
	
	
		
		
	
				
			I wrote this script to put a gui front-end to the process. It´s a bit simple but I´ve found it useful to spot the odd duff PND download.
not sure I understand how pnd_run behaves. It may have been caused by running out of memory but I ended up with DOSBOX linked to deadbeef in /mnt/utmp. deadbeef was working happily but the mount showed dosbox´s contents.
okay, I need to PND it but for now I just made a bin directory in my homedir and added this to the PATH variable in my .profile and then ran it from the command line. (detailed instructions on request if any linux newbies are reading this)
		Code:
	
	#!/bin/bash
#@(#)pnd_mount - PND mounting actions.
# 1.0  09/07/11  Simon May  initial version
#
# Usage: PND_mount <name of pnd>
#
doInit(){
  SCRIPT=$(basename $0)
  work=/tmp/$SCRIPT.$$
  PND_RUN=/usr/pandora/scripts/pnd_run.sh
  dirs="menu apps desktop"
  sdcards="/dev/mmcblk0p1|/dev/mmcblk1p1"
  initdir=$(getDir)
}
#---
# getDir - Find the inital directory for fileselector
getDir(){
  for i in $(mount | egrep "$sdcards" | awk '{print $3}')
  do 
    for j in $dirs
    do
      dir=$i/pandora/$j
      [ -d $dir ] && {
        echo "$dir/"
        return
      }
    done
  done 
  echo "/"  # root it is then. 
}
#---
pndMount(){
  fullPND=$(zGetPND) 	# full pathname of PND
  [ -z "$fullPND" ] && return
#
  pnd=$(basename $fullPND .pnd) 
  pnd=$(basename $pnd .PND) 
  out=$(mount | grep "/mnt/utmp/$pnd " 2>&1)
  [ -z "$out" ] || {
    zInfo "$pnd is already mounted"
    return
  }
#
  $PND_RUN -p $fullPND -m > $work 2>&1 
  out=$(mount | grep "/mnt/utmp/$pnd " 2>&1)
  if [ -z "$out" ] 
  then
    zenity --text-info --title="Looks like the mount failed." \
      --filename=$work
  else
    zQuestion "Mount Success. Do you want to explore?" "Yes" "No" && thunar /mnt/utmp/$pnd
  fi
  rm -f $work
}
#---
pndUnmount(){
  pnd=$(getPND unmount)
  [ -z "$pnd" ] &&  return
  fullPND=$(getFullPND $pnd)
  [ -z "$fullPND" ] &&  return
#
  $PND_RUN -p $fullPND -u > $work 2>&1 
  out=$(mount | grep "/mnt/utmp/$pnd " 2>/dev/null)
  if [ -z "$out" ]
  then
    zInfo "$pnd has been unmounted"
  else 
    zenity --text-info --title="Looks like the unmount failed." \
      --filename=$work
  fi
  rm -f $work
}
#---
pndList(){
  pnd=$(getPND explore)
  [ $pnd ] && thunar /mnt/utmp/$pnd
}
#---
# getFullPND - Find the full pnd name
#   $1 - short pnd name.   Greyout not Greyout.PND
getFullPND(){
  pnd=$1
  for i in $(mount | egrep "$sdcards" | awk '{print $3}')  # get mountpoint names
  do 
    for j in $dirs	
    do
      for ext in pnd PND
      do 
        file=$i/pandora/$j/$pnd.$ext
        [ -f $file ] && {
          echo "$file"
          return
        }
      done
    done
  done 
  zInfo "Unable to find full path to $pnd. Click ok and select manually." 
  zGetPND 	# full pathname of PND
}
#---
# getPND - gets a PND from a list of mounted PNDs.
#   $1 - "action"  	e.g. explore or unmount
#   echoes a short pnd for capture.
getPND(){
  action="$1"
  pnds=$(ls /mnt/utmp/*/PXML.xml 2>/dev/null)
  [ -z "$pnds" ] && {
    zInfo "No PNDs mounted"
    return
  }
  for i in $pnds
  do
    basename $(dirname $i)
  done | zenity --list --title "$SCRIPT: List of mounted PNDs" --width=500 --height=230 \
           --column "PND" --text "Select a PND to $action or Cancel to return to the menu."
}
#---
# zQuestion - zenity question dialogue 
#  $1 text, optional $2 ok text, $3 cancel text
#  returns rc
zQuestion(){
  text="$1"
  [ -z "$2" ] && okay="" || okay="--ok-label=$2"
  [ -z "$3" ] && cancel="" || cancel="--cancel-label=$3"
  zenity --question --text="$text" $okay $cancel
  status=$?
  return $status     # over kill as zenity is the last action but makes code more maintainable.
}
#---
zError(){
  zenity --error --text "$1"
  exit 1
}
#---
zInfo(){
  zenity --info --text "$1"
}
#---
zGetPND(){
  zenity --file-selection --title="$SCRIPT: Select a PND" --filename=$initdir --file-filter="*.pnd" "*.*"
}
#---
zMenu(){
  command=$(zenity --list --title "$SCRIPT: Select a option" --width=500 --height=230 \
    --hide-column=1 --text "Please select an action from the list below." \
    --column "command" --column "Action" \
    pndMount    "Mount a PND for inspection." \
    pndUnmount  "Unmount a previously mounted PND" \
    pndList     "List a mounted PNDs" \
    "exit 0"    "Quit." )
  [ -z "$command" ] && exit 0
  eval $command
}
#===
  doInit $@
  while :; do zMenu; done
###fin 
	
 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		