Annotation of palm/manage_pre/manage_pre, Revision 1.6
1.1 andrew 1: #!/bin/sh
1.6 ! andrew 2: # $Id: manage_pre,v 1.5 2009/08/20 21:41:24 andrew Exp $
1.1 andrew 3:
1.3 andrew 4: local _pre_id='Palm, Pre, 0316'
5: #local _pre_label='Pre'
6: #local _ipod_label='iPod'
1.1 andrew 7: local _mount_dir='/mnt/pre'
8: local _name=`basename $0`
1.2 andrew 9: local _unison_config='vogonpa'
1.1 andrew 10:
11: local _action="$*"
12: case "$_name" in
13: eject_pre)
14: _action=eject
15: ;;
16: sync_pre)
17: _action=sync
18: ;;
19: mount_pre)
20: _action=mount
21: ;;
22: esac
23:
24: if [ -z "$_action" ]; then
25: echo "manage_pre mount|sync|eject"
26: exit 255
27: fi
28:
29: find_pre() {
30: local _dev=`dmesg | grep 'Palm, Pre' | tail -1 | cut -d' ' -f 1`
31: if [ X"$_dev" == X"" ]; then
1.5 andrew 32: echo Pre not found! >&2
33: exit 1
1.1 andrew 34: fi
35:
1.3 andrew 36: local _id=`dmesg | grep "^$_dev at " | tail -1 | sed -e 's/.*<//' -e 's/>.*$//'`
37: if [ X"$_id" != X"$_pre_id" ]; then
1.5 andrew 38: echo "Pre [$_dev] not correct id [$_id]" >&2
39: exit 2
1.1 andrew 40: fi
41:
42: echo /dev/${_dev}i
43: }
44:
45: is_mounted() {
46: /sbin/mount | grep "^${_dev} "
47: }
48:
49: eject() {
50: local _mounted=`is_mounted $_dev`
51: if [ X"" != X"$_mounted" ]; then
52: /bin/sync
1.4 andrew 53: $SUDO /sbin/umount $_dev && echo Unmounted Pre
1.1 andrew 54: else
55: echo Not mounted
56: fi
1.4 andrew 57: $SUDO /bin/eject $_dev 2> /dev/null && echo Ejected Pre
58: $SUDO rmdir $_mount_dir 2> /dev/null
1.1 andrew 59: }
60:
61: mount() {
62: local _mounted=`is_mounted $_dev`
63: if [ X"" != X"$_mounted" ]; then
64: echo Already mounted: ${_mounted%% type*}
65: return
66: fi
1.4 andrew 67: $SUDO mkdir -p $_mount_dir
1.5 andrew 68: $SUDO chgrp users $_mount_dir
69: $SUDO chmod g+w $_mount_dir
1.4 andrew 70: $SUDO /sbin/mount $_dev $_mount_dir && echo Mounted Pre on $_mount_dir
1.1 andrew 71: }
72:
73: synchronize() {
74: local _mounted=`is_mounted $_dev`
1.6 ! andrew 75: local _did_mount=""
1.1 andrew 76: if [ X"" == X"$_mounted" ]; then
1.6 ! andrew 77: mount || exit 255
! 78: _did_mount=1
1.1 andrew 79: fi
80:
1.2 andrew 81: echo Synchronizing Pre
1.1 andrew 82:
83: #if [ -e /usr/local/bin/rsync ]; then
84: #rsync -rv --delete --size-only --exclude '*.pid' \
85: #.backgrounds/vogonpa/ /mnt/pre/wallpapers_mine/
86: #fi
1.2 andrew 87:
88: if [ -e /usr/local/bin/unison ]; then
1.3 andrew 89: /usr/local/bin/unison $_unison_config -auto -batch -ui text
1.6 ! andrew 90: fi
! 91:
! 92: if [ ! -z "$_did_mount" ]; then
! 93: eject
1.2 andrew 94: fi
1.1 andrew 95: }
96:
97: local _dev=`find_pre`
98: if [ X"${_dev}" == X"" -o ! -e $_dev ]; then
99: echo "Unable to find Pre!"
100: exit 3
101: fi
102:
103: local _a
104: for _a in $_action; do
105: case "$_a" in
106: mount)
107: mount
108: ;;
109: sync)
110: synchronize
111: ;;
112: eject)
113: eject
114: ;;
115: *)
116: echo "Unrecognized action [$_a]"
117: ;;
118: esac
119: done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>