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

Annotation of palm/manage_pre/manage_pre, Revision 1.2

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

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