Annotation of palm/manage_pre/manage_pre, Revision 1.10
1.1 andrew 1: #!/bin/sh
1.10 ! andrew 2: # $AFresh1: manage_pre,v 1.9 2010/07/12 17:37:52 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="$*"
1.10 ! andrew 104: case `basename $0` in
! 105: mount*)
! 106: _action=mount
1.8 andrew 107: ;;
1.10 ! andrew 108: sync*)
1.8 andrew 109: _action=sync
110: ;;
1.10 ! andrew 111: eject*)
! 112: _action=eject
1.8 andrew 113: ;;
114: esac
115:
116: if [ -z "$_action" ]; then
117: echo "manage_pre mount|sync|eject"
118: exit 255
119: fi
1.1 andrew 120:
121: local _dev=`find_pre`
122: if [ X"${_dev}" == X"" -o ! -e $_dev ]; then
123: echo "Unable to find Pre!"
124: exit 3
125: fi
126:
127: local _a
128: for _a in $_action; do
129: case "$_a" in
130: mount)
131: mount
132: ;;
133: sync)
134: synchronize
135: ;;
136: eject)
137: eject
138: ;;
139: *)
140: echo "Unrecognized action [$_a]"
141: ;;
142: esac
143: done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>