![]() ![]() | ![]() |
File: [local] / palm / manage_pre / manage_pre (download)
Revision 1.3, Thu Aug 20 21:38:37 2009 UTC (14 years, 10 months ago) by andrew
check that the last device we see in dmesg has the correct id. Don't try for the volume label cuZ we need root to get that. |
#!/bin/sh # $Id: manage_pre,v 1.3 2009/08/20 21:38:37 andrew Exp $ local _pre_id='Palm, Pre, 0316' #local _pre_label='Pre' #local _ipod_label='iPod' local _mount_dir='/mnt/pre' local _name=`basename $0` local _unison_config='vogonpa' local _action="$*" case "$_name" in eject_pre) _action=eject ;; sync_pre) _action=sync ;; mount_pre) _action=mount ;; esac if [ -z "$_action" ]; then echo "manage_pre mount|sync|eject" exit 255 fi find_pre() { local _dev=`dmesg | grep 'Palm, Pre' | tail -1 | cut -d' ' -f 1` if [ X"$_dev" == X"" ]; then echo Pre not found! >&2 exit 1 fi local _id=`dmesg | grep "^$_dev at " | tail -1 | sed -e 's/.*<//' -e 's/>.*$//'` if [ X"$_id" != X"$_pre_id" ]; then echo "Pre [$_dev] not correct id [$_id]" >&2 exit 2 fi echo /dev/${_dev}i } is_mounted() { /sbin/mount | grep "^${_dev} " } eject() { local _mounted=`is_mounted $_dev` if [ X"" != X"$_mounted" ]; then /bin/sync /sbin/umount $_dev && echo Unmounted Pre else echo Not mounted fi /bin/eject $_dev 2> /dev/null && echo Ejected Pre rmdir $_mount_dir 2> /dev/null } mount() { local _mounted=`is_mounted $_dev` if [ X"" != X"$_mounted" ]; then echo Already mounted: ${_mounted%% type*} return fi mkdir -p $_mount_dir chgrp users $_mount_dir chmod g+w $_mount_dir /sbin/mount $_dev $_mount_dir && echo Mounted Pre on $_mount_dir } synchronize() { local _mounted=`is_mounted $_dev` if [ X"" == X"$_mounted" ]; then echo Not mounted return 1 fi echo Synchronizing Pre #if [ -e /usr/local/bin/rsync ]; then #rsync -rv --delete --size-only --exclude '*.pid' \ #.backgrounds/vogonpa/ /mnt/pre/wallpapers_mine/ #fi if [ -e /usr/local/bin/unison ]; then /usr/local/bin/unison $_unison_config -auto -batch -ui text fi } local _dev=`find_pre` if [ X"${_dev}" == X"" -o ! -e $_dev ]; then echo "Unable to find Pre!" exit 3 fi local _a for _a in $_action; do case "$_a" in mount) mount ;; sync) synchronize ;; eject) eject ;; *) echo "Unrecognized action [$_a]" ;; esac done