I wanted to transfer multiple files from my Toppy to my pc overnight. The kids complain if I use turbo mode as they lose the use of the remote.
As puppy only accepts a single file, it seemed a good idea to wrap puppy in a script.
Here are 2 scripts that I use: Copy them to a directory that is is your path when you log into the slug.
Please understand that my scripting abilities are limited: feel free to offer suggestions. You should also study them as you may want to delete some of the code.
Both scripts understand -h as an option. It displays help.
Files on the toppy are in ProgramFiles, DataFiles or MP3 so I called these AREAS and gave them shortcuts: p, d & m.
A directory listing with a difference:
pdir [-a area] [-d] [-f] dir[/dir...]
-a allows you to enter an AREA. Use d, p or m for the areas listed above (-a d is the default). If you have created another high level directory then use its (case sensitive) name.
-d will list only directories in sorted order
-f will list only filenames in sorted order
dir[/dir...]There are also sub-directories and they can have sub-directories: So you can specify movie or drama/AllSaints.
Note: You can specify -d & -f but I dont know why you would want to.
If no options are specified, then the output from puppy is not modified.
#!/bin/sh
#
area=d
ld=0
lf=0
while [ $# != 0 ]
do
case $1 in
-a) area=$2; shift;;
-a*) area=`echo $1|sed -e 's/-a//'`;;
-d) ld=1;;
-f) lf=1;;
-h) echo Usage: pdir [-a [area]] [-d] [-f] [-h] [path]
echo -e "-a\tMain area [D]ataFiles (default) [P]rogramFiles [M]P3"
echo -e "-d\tList directories only"
echo -e "-f\tList files only"
echo -e "-h\tDisplay this help"
echo -e "path\tDirectory path to list (case sensitive) use / to separate dirs"
exit;;
*) path=$1;;
esac
shift
done
case $area in
d|D) area=DataFiles;;
p|P) area=ProgramFiles;;
m|M) area=MP3;;
esac
path=`echo $path | tr / \\`
if [ $ld -eq 1 ]
then
puppy -c dir "$area\\$path" | sed -e '/^f/d' | cut -b49- | sort
fi
if [ $lf -eq 1 ]
then
puppy -c dir "$area\\$path" | sed -e '/^d/d' | cut -b49- | sort
fi
if [ $ld -eq 0 -a $lf -eq 0 ]
then
puppy -c dir "$area\\$path" | sort
fi
exit
|
To retrieve multiple files:
pget [-t] [-a area] [-s sdir[/sdir...]] [-n name] target
-t turbo mode off
-a allows you to enter an AREA. Use d, p, m for the areas listed above. If you have created another high level directory then use its (case sensitive) name.
-s sub directory path (case sensitive) eg drama/AllSaints.
-n partial name (case insensitive)
target The directory to receive the toppy's files.
If no options are specified, then all files in the DataFiles area are transferred to the target directory.
#!/bin/sh # # Copy files from Toppy to somewhere # area=d sdir= nme= tgt= fst=1 tmp=/tmp/names
while [ $# != 0 ]
do
case $1 in
-a) area=$2; shift;;
-a*) area=`echo $1|sed -e 's/-a//`;;
-s) sdir=$2; shift;;
-s*) sdir=`echo $1|sed -e 's/-s//'`;;
-n) nme="$2"; shift;;
-n*) nme=`echo $1|sed -e 's/-n//'`;;
-t) fst=;;
-h) echo "Usage: pget [-a area] [-p path] [-n partial name] target"
echo "-a Specify area [D]ataFiles (def), [P]rogramFiles, [M]P3 or top level dir"
echo "-s Specify sub directory or sub-dir path (in full using / and case sensitive)"
echo "-n specify part of a file name (case insensitive) \* for all files"
echo "-t Turbo mode off"
echo "-h Display this help"
echo target is destination directory for files
exit;;
*) tgt=$1;;
esac
shift
done
# I dont want to fill my flash drive if I forgot to mount a smb fs.
if [ "$tgt" != "" ] && [ -d $tgt ]
then
lne=`mount | grep smbfs | grep smbfs`
if [ "$lne" = "" ]
then
echo Warning: No smb file systems mounted
echo -e "Continue? \c"
read ANS
if [ "$ANS" = "y" -o "$ANS" = "Y" ]
then
:
else
echo Aborting
exit
fi
fi
else
if [ -e $tgt ]
then
echo Target must be a directory.
exit
else
echo -e "Create target directory $tgt? \c"
read ANS
if [ "$ANS" = "y" -o "$ANS" = "Y" ]
then
mkdir -p $tgt
else
echo Aborting
exit
fi
fi
fi
if [ "$nme" = "" ]
then
echo -e "No file name specified!"
echo -e "Copy all files from area $area, dir $sdir? \c"
read ANS
if [ "$ANS" = "y" -o "$ANS" = "Y" ]
then
:
else
echo Aborting
exit
fi
elif [ "$nme" = "*" ]
then
nme=
fi
case $area in
d|D) area=DataFiles;;
p|P) area=ProgramFiles;;
m|M) area=MP3;;
esac
trap "rm -f $tmp" 0 1 2 3
cmd="pdir -a $area -f \"$sdir\" ${nme:+| grep -i \"$nme\"} > $tmp"
#echo $cmd
eval $cmd
if [ ! -s $tmp ]
then
echo "No files to copy - check Directory and/or name (use -n \* or -n* for all files)"
exit
fi
3<$tmp
while
read file <&3
do
# cmd="puppy ${fst:--t} -c get \"$area\\$sdir\\$file\" \"$tgt/$file\""
cmd="puppy -t -c get \"$area\\$sdir\\$file\" \"$tgt/$file\""
echo $cmd
eval $cmd
if [ $? -ne 0 ]
then
puppy -c cancel
puppy -c cancel
fi
done
exit
|
Because I use a flash drive, I must transfer any files to another pc. So, there is some code to check if I have mounted target as a samba share (mounts are lost on reboot).
If the target does not exist, it will offer to create it.
I normally use pdir a few times to work out where things are and then use pget to copy them.
The shell allows you to combine multiple statements on one line. Separate the statements by a semi-colon.
eg pget -n kate /gw; pget -s movie -n red /gw transferred kate & leopold and red october to my gateway pc.
My thanks to Peteru for this neat program.
Malcolm
Bugs: Sometimes I am not sure if a message is from puppy or a problem with the script.