version 1.3, 2009/08/20 22:38:37 |
version 1.10, 2011/01/24 21:36:09 |
|
|
#!/bin/sh |
#!/bin/sh |
# $Id$ |
# $AFresh1: manage_pre,v 1.9 2010/07/12 17:37:52 andrew Exp $ |
|
|
local _pre_id='Palm, Pre, 0316' |
# Copyright (c) 2010 Andrew Fresh <andrew@afresh1.com> |
#local _pre_label='Pre' |
# |
#local _ipod_label='iPod' |
# Permission to use, copy, modify, and distribute this software for any |
local _mount_dir='/mnt/pre' |
# purpose with or without fee is hereby granted, provided that the above |
local _name=`basename $0` |
# copyright notice and this permission notice appear in all copies. |
local _unison_config='vogonpa' |
# |
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
|
|
local _pre_id='Palm, Pre, 0000' |
|
local _mount_point='/mnt/pre' |
|
local _unison_config='palm_pre' |
|
|
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() { |
find_pre() { |
local _dev=`dmesg | grep 'Palm, Pre' | tail -1 | cut -d' ' -f 1` |
local _dev=`dmesg | grep 'Palm, Pre' | tail -1 | cut -d' ' -f 1` |
if [ X"$_dev" == X"" ]; then |
if [ X"$_dev" == X"" ]; then |
echo Pre not found! >&2 |
echo Pre not found! >&2 |
exit 1 |
exit 1 |
fi |
fi |
|
|
local _id=`dmesg | grep "^$_dev at " | tail -1 | sed -e 's/.*<//' -e 's/>.*$//'` |
local _id=`dmesg | grep "^$_dev at " | tail -1 | sed -e 's/.*<//' -e 's/>.*$//'` |
if [ X"$_id" != X"$_pre_id" ]; then |
if [ X"$_id" != X"$_pre_id" ]; then |
echo "Pre [$_dev] not correct id [$_id]" >&2 |
echo "Pre [$_dev] not correct id [$_id]" >&2 |
exit 2 |
exit 2 |
fi |
fi |
|
|
echo /dev/${_dev}i |
echo /dev/${_dev}i |
|
|
local _mounted=`is_mounted $_dev` |
local _mounted=`is_mounted $_dev` |
if [ X"" != X"$_mounted" ]; then |
if [ X"" != X"$_mounted" ]; then |
/bin/sync |
/bin/sync |
/sbin/umount $_dev && echo Unmounted Pre |
$SUDO /sbin/umount $_dev && echo Unmounted Pre |
else |
else |
echo Not mounted |
echo Not mounted |
fi |
fi |
/bin/eject $_dev 2> /dev/null && echo Ejected Pre |
$SUDO /bin/eject $_dev 2> /dev/null && echo Ejected Pre |
rmdir $_mount_dir 2> /dev/null |
$SUDO rmdir $_mount_point 2> /dev/null |
} |
} |
|
|
mount() { |
mount() { |
|
|
echo Already mounted: ${_mounted%% type*} |
echo Already mounted: ${_mounted%% type*} |
return |
return |
fi |
fi |
mkdir -p $_mount_dir |
$SUDO mkdir -p $_mount_point |
chgrp users $_mount_dir |
$SUDO chgrp users $_mount_point |
chmod g+w $_mount_dir |
$SUDO chmod g+w $_mount_point |
/sbin/mount $_dev $_mount_dir && echo Mounted Pre on $_mount_dir |
|
|
$SUDO /sbin/mount $_dev $_mount_point 2> /dev/null |
|
local _status=$? |
|
|
|
if [ "$_status" != 0 ]; then |
|
echo -n "Waiting for $_dev to be ready " |
|
while [ "$_status" != 0 ]; do |
|
echo -n . |
|
sleep 1 |
|
$SUDO /sbin/mount $_dev $_mount_point 2> /dev/null |
|
_status=$? |
|
done |
|
echo |
|
fi |
|
echo Mounted Pre on $_mount_point |
} |
} |
|
|
synchronize() { |
synchronize() { |
local _mounted=`is_mounted $_dev` |
local _mounted=`is_mounted $_dev` |
|
local _did_mount="" |
if [ X"" == X"$_mounted" ]; then |
if [ X"" == X"$_mounted" ]; then |
echo Not mounted |
mount || exit 255 |
return 1 |
_did_mount=1 |
fi |
fi |
|
|
echo Synchronizing Pre |
echo Synchronizing Pre |
|
|
#if [ -e /usr/local/bin/rsync ]; then |
#if [ -e /usr/local/bin/rsync ]; then |
#rsync -rv --delete --size-only --exclude '*.pid' \ |
# rsync -rv --delete --size-only --exclude '*.pid' |
#.backgrounds/vogonpa/ /mnt/pre/wallpapers_mine/ |
|
#fi |
#fi |
|
|
if [ -e /usr/local/bin/unison ]; then |
if [ -e /usr/local/bin/unison ]; then |
/usr/local/bin/unison $_unison_config -auto -batch -ui text |
/usr/local/bin/unison $_unison_config -auto -batch -ui text |
fi |
fi |
|
|
|
if [ ! -z "$_did_mount" ]; then |
|
eject |
|
fi |
} |
} |
|
|
|
local _action="$*" |
|
case `basename $0` in |
|
mount*) |
|
_action=mount |
|
;; |
|
sync*) |
|
_action=sync |
|
;; |
|
eject*) |
|
_action=eject |
|
;; |
|
esac |
|
|
|
if [ -z "$_action" ]; then |
|
echo "manage_pre mount|sync|eject" |
|
exit 255 |
|
fi |
|
|
local _dev=`find_pre` |
local _dev=`find_pre` |
if [ X"${_dev}" == X"" -o ! -e $_dev ]; then |
if [ X"${_dev}" == X"" -o ! -e $_dev ]; then |