Pandora pnd_mount script


may88

Well-Known Member
Joined
Dec 17, 2007
Messages
1,178
Location
Bury St. Edmunds, UK
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)

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
 
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.
that's a pnd_run.sh bug spoted (cant remember who :( ) and fixed. in the lastest release (be it my installer or lastest HF6a)


Beside mounting/umounting PND can be done using -p/-u argument for pnd_run.sh.


If you still have that problem with the lastest version let me know, but it should be fixed.
 
Last edited by a moderator:
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.
that's a pnd_run.sh bug spoted (cant remember who :( ) and fixed. in the lastest release (be it my installer or lastest HF6a)


Beside mounting/umounting PND can be done using -p/-u argument for pnd_run.sh.


If you still have that problem with the lastest version let me know, but it should be fixed.
good to know there´s a fix.


all the scirpt is, is a gui wrapper for the -m and -u flags. ultimately if it hits the menu it could be useful for those that think "terminal" is too scary to run. :p
 
all the scirpt is, is a gui wrapper for the -m and -u flags. ultimately if it hits the menu it could be useful for those that think "terminal" is too scary to run. :p
I've to say I did not look at it at first :D


Now that I 've a look at it I can see all these zenity calls.


There are a few flaw in your code like :


"pnds=$(ls /mnt/utmp/*/PXML.xml 2>/dev/null)"


Not all the PND does include the PXML.xml file inside the PND, while this is recommanded, it is not mandatory, and I know for sure that some doesnt do this.


or "sdcards="/dev/mmcblk0p1|/dev/mmcblk1p1""


you cannot say that either : some might have more than 1 partition on his card. I even saw some cards without a partition table and using all for the fat.


So /dev/mmcblk0 could be a sdcard "drive" and /dev/mmcblk0p3 could exist (and contain PNDs)
 
thanks sebt that´s exactlly the feedback I´m looking for.


I´d made all sorts of assumptions.


I need to add mmemu as a valid location too.
 
Back
Top