Annotation of palm/manage_pre/manage_pre, Revision 1.9
1.1 andrew 1: #!/bin/sh
1.9 ! andrew 2: # $AFresh1: manage_pre,v 1.8 2010/03/10 19:35:40 andrew Exp $
1.1 andrew 3:
1.8 andrew 4: # Copyright (c) 2010 Andrew Fresh <andrew@afresh1.com>
5: #
6: # Permission to use, copy, modify, and distribute this software for any
7: # purpose with or without fee is hereby granted, provided that the above
8: # copyright notice and this permission notice appear in all copies.
9: #
10: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17:
1.7 andrew 18: local _pre_id='Palm, Pre, 0000'
1.8 andrew 19: local _mount_point='/mnt/pre'
20: local _unison_config='palm_pre'
1.1 andrew 21:
22: find_pre() {
23: local _dev=`dmesg | grep 'Palm, Pre' | tail -1 | cut -d' ' -f 1`
24: if [ X"$_dev" == X"" ]; then
1.5 andrew 25: echo Pre not found! >&2
26: exit 1
1.1 andrew 27: fi
28:
1.3 andrew 29: local _id=`dmesg | grep "^$_dev at " | tail -1 | sed -e 's/.*<//' -e 's/>.*$//'`
30: if [ X"$_id" != X"$_pre_id" ]; then
1.5 andrew 31: echo "Pre [$_dev] not correct id [$_id]" >&2
32: exit 2
1.1 andrew 33: fi
34:
35: echo /dev/${_dev}i
36: }
37:
38: is_mounted() {
39: /sbin/mount | grep "^${_dev} "
40: }
41:
42: eject() {
43: local _mounted=`is_mounted $_dev`
44: if [ X"" != X"$_mounted" ]; then
45: /bin/sync
1.4 andrew 46: $SUDO /sbin/umount $_dev && echo Unmounted Pre
1.1 andrew 47: else
48: echo Not mounted
49: fi
1.4 andrew 50: $SUDO /bin/eject $_dev 2> /dev/null && echo Ejected Pre
1.8 andrew 51: $SUDO rmdir $_mount_point 2> /dev/null
1.1 andrew 52: }
53:
54: mount() {
55: local _mounted=`is_mounted $_dev`
56: if [ X"" != X"$_mounted" ]; then
57: echo Already mounted: ${_mounted%% type*}
58: return
59: fi
1.8 andrew 60: $SUDO mkdir -p $_mount_point
61: $SUDO chgrp users $_mount_point
62: $SUDO chmod g+w $_mount_point
1.9 ! andrew 63:
! 64: $SUDO /sbin/mount $_dev $_mount_point 2> /dev/null
! 65: local _status=$?
! 66:
! 67: if [ "$_status" != 0 ]; then
! 68: echo -n "Waiting for $_dev to be ready "
! 69: while [ "$_status" != 0 ]; do
! 70: echo -n .
! 71: sleep 1
! 72: $SUDO /sbin/mount $_dev $_mount_point 2> /dev/null
! 73: _status=$?
! 74: done
! 75: echo
! 76: fi
! 77: echo Mounted Pre on $_mount_point
1.1 andrew 78: }
79:
80: synchronize() {
81: local _mounted=`is_mounted $_dev`
1.6 andrew 82: local _did_mount=""
1.1 andrew 83: if [ X"" == X"$_mounted" ]; then
1.6 andrew 84: mount || exit 255
85: _did_mount=1
1.1 andrew 86: fi
87:
1.2 andrew 88: echo Synchronizing Pre
1.1 andrew 89:
90: #if [ -e /usr/local/bin/rsync ]; then
1.8 andrew 91: # rsync -rv --delete --size-only --exclude '*.pid'
1.1 andrew 92: #fi
1.2 andrew 93:
94: if [ -e /usr/local/bin/unison ]; then
1.3 andrew 95: /usr/local/bin/unison $_unison_config -auto -batch -ui text
1.6 andrew 96: fi
97:
98: if [ ! -z "$_did_mount" ]; then
99: eject
1.2 andrew 100: fi
1.1 andrew 101: }
1.8 andrew 102:
103: local _action="$*"
104: local _name=`basename $0`
105: case "$_name" in
106: eject_pre)
107: _action=eject
108: ;;
109: sync_pre)
110: _action=sync
111: ;;
112: mount_pre)
113: _action=mount
114: ;;
115: esac
116:
117: if [ -z "$_action" ]; then
118: echo "manage_pre mount|sync|eject"
119: exit 255
120: fi
1.1 andrew 121:
122: local _dev=`find_pre`
123: if [ X"${_dev}" == X"" -o ! -e $_dev ]; then
124: echo "Unable to find Pre!"
125: exit 3
126: fi
127:
128: local _a
129: for _a in $_action; do
130: case "$_a" in
131: mount)
132: mount
133: ;;
134: sync)
135: synchronize
136: ;;
137: eject)
138: eject
139: ;;
140: *)
141: echo "Unrecognized action [$_a]"
142: ;;
143: esac
144: done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>