[BACK]Return to manage_pre CVS log [TXT][DIR] Up to [local] / palm / manage_pre

Annotation of palm/manage_pre/manage_pre, Revision 1.8

1.1       andrew      1: #!/bin/sh
1.8     ! andrew      2: # $AFresh1$
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
        !            63:     $SUDO /sbin/mount $_dev $_mount_point && echo Mounted Pre on $_mount_point
1.1       andrew     64: }
                     65:
                     66: synchronize() {
                     67:     local _mounted=`is_mounted $_dev`
1.6       andrew     68:     local _did_mount=""
1.1       andrew     69:     if [ X"" == X"$_mounted" ]; then
1.6       andrew     70:         mount || exit 255
                     71:         _did_mount=1
1.1       andrew     72:     fi
                     73:
1.2       andrew     74:     echo Synchronizing Pre
1.1       andrew     75:
                     76:     #if [ -e /usr/local/bin/rsync ]; then
1.8     ! andrew     77:     #   rsync -rv --delete --size-only --exclude '*.pid'
1.1       andrew     78:     #fi
1.2       andrew     79:
                     80:     if [ -e /usr/local/bin/unison ]; then
1.3       andrew     81:         /usr/local/bin/unison $_unison_config -auto -batch -ui text
1.6       andrew     82:     fi
                     83:
                     84:     if [ ! -z "$_did_mount" ]; then
                     85:         eject
1.2       andrew     86:     fi
1.1       andrew     87: }
1.8     ! andrew     88:
        !            89: local _action="$*"
        !            90: local _name=`basename $0`
        !            91: case "$_name" in
        !            92:     eject_pre)
        !            93:         _action=eject
        !            94:         ;;
        !            95:     sync_pre)
        !            96:         _action=sync
        !            97:         ;;
        !            98:     mount_pre)
        !            99:         _action=mount
        !           100:         ;;
        !           101: esac
        !           102:
        !           103: if [ -z "$_action" ]; then
        !           104:     echo "manage_pre mount|sync|eject"
        !           105:     exit 255
        !           106: fi
1.1       andrew    107:
                    108: local _dev=`find_pre`
                    109: if [ X"${_dev}" == X"" -o ! -e $_dev ]; then
                    110:     echo "Unable to find Pre!"
                    111:     exit 3
                    112: fi
                    113:
                    114: local _a
                    115: for _a in $_action; do
                    116:     case "$_a" in
                    117:         mount)
                    118:             mount
                    119:             ;;
                    120:         sync)
                    121:             synchronize
                    122:             ;;
                    123:         eject)
                    124:             eject
                    125:             ;;
                    126:         *)
                    127:             echo "Unrecognized action [$_a]"
                    128:             ;;
                    129:     esac
                    130: done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>