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

Annotation of palm/manage_pre/manage_pre, Revision 1.4

1.1       andrew      1: #!/bin/sh
1.4     ! andrew      2: # $Id: manage_pre,v 1.3 2009/08/20 21:38:37 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
                     32:            echo Pre not found! >&2
                     33:            exit 1
                     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
                     38:            echo "Pre [$_dev] not correct id [$_id]" >&2
1.1       andrew     39:            exit 2
                     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
        !            68:        $SUDO chgrp users $_mount_dir
        !            69:        $SUDO chmod g+w   $_mount_dir
        !            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`
                     75:     if [ X"" == X"$_mounted" ]; then
                     76:         echo Not mounted
                     77:         return 1
                     78:     fi
                     79:
1.2       andrew     80:     echo Synchronizing Pre
1.1       andrew     81:
                     82:     #if [ -e /usr/local/bin/rsync ]; then
                     83:         #rsync -rv --delete --size-only --exclude '*.pid' \
                     84:             #.backgrounds/vogonpa/ /mnt/pre/wallpapers_mine/
                     85:     #fi
1.2       andrew     86:
                     87:     if [ -e /usr/local/bin/unison ]; then
1.3       andrew     88:         /usr/local/bin/unison $_unison_config -auto -batch -ui text
1.2       andrew     89:     fi
1.1       andrew     90: }
                     91:
                     92: local _dev=`find_pre`
                     93: if [ X"${_dev}" == X"" -o ! -e $_dev ]; then
                     94:     echo "Unable to find Pre!"
                     95:     exit 3
                     96: fi
                     97:
                     98: local _a
                     99: for _a in $_action; do
                    100:     case "$_a" in
                    101:         mount)
                    102:             mount
                    103:             ;;
                    104:         sync)
                    105:             synchronize
                    106:             ;;
                    107:         eject)
                    108:             eject
                    109:             ;;
                    110:         *)
                    111:             echo "Unrecognized action [$_a]"
                    112:             ;;
                    113:     esac
                    114: done

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