Changeset 177 for tags/confman-1.5.5a


Ignore:
Timestamp:
10/08/2007 17:12:27 (4 years ago)
Author:
arjun
Message:

Commiting 1.5.5a

Location:
tags/confman-1.5.5a
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • tags/confman-1.5.5a/ChangeLog

    r124 r177  
    88         must now be defined. 
    99 
    10 $Id: ChangeLog,v 1.3887 2005/09/01 09:10:48 djm Exp $ 
     10$Id: ChangeLog 507 2007-01-26 02:07:36Z ccowart $ 
  • tags/confman-1.5.5a/Makefile

    r138 r177  
    88BINFILES                =       abspath 
    99SBINFILES               =       confman 
    10 LIBEXECFILES    =       export.sh confsync.sh 
     10LIBEXECFILES    =       export.sh confsync.sh confaudit.sh 
    1111LIBFILES                =       confmanlib.sh confmandoc.sh confmancommon.sh 
    1212ENVFILES                =       confman_completions 
  • tags/confman-1.5.5a/confman

    r145 r177  
    1 #! /bin/bash 
     1#! /bin/bash   
    22# 
    33# confman provides a command-line interface to Rescomp's server configuration  
     
    1212# $Id$ 
    1313 
    14 . /usr/local/rescomp/lib/confmancommon.sh 
     14# Try loading a development library first 
     15if [ -r ./confmancommon.sh ] ; then 
     16    echo "Loading development library from current working directory." >&2 
     17    . ./confmancommon.sh 
     18elif [ -r /usr/local/rescomp/lib/confmancommon.sh ] ; then 
     19    . /usr/local/rescomp/lib/confmancommon.sh 
     20else 
     21    echo "Can't find confmancommon.sh. Exiting." >&2 
     22fi 
    1523 
    1624# Set a default editor 
     
    3038# with no arguments, and will error if that's not the case. 
    3139function setup { 
    32         local response 
    33         $DEBUG && echo "Running setup" >&4 
    34         if [ ! -z $* ] ; then 
    35                 print_usage 1 
    36         elif [ -d ${WORK_PATH} ] ; then 
    37                 echo "Looks like ${WORK_PATH} already exists."  
    38                 echo "Start over by removing it? (y/N)" 
    39                 read response 
    40                 if [[ $response =~ '^[yY]([es]|[ES])?' ]] ; then 
    41                         rm -rf ${WORK_PATH} 
    42                         setup 
    43                 else 
    44                         echo "Setup failed." >&4 
    45                         exit 1 
    46                 fi 
    47         else 
    48                 conf_checkout_tree 
    49         fi 
     40    if conf_wcopy_locked? 
     41    then 
     42        local lock_pid=`cat ${WORK_PATH}/confman.lock` #gets the PID of the confman instance that created the lock 
     43        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     44    else 
     45        if [ -d ${WORK_PATH} ]  
     46        then 
     47        conf_setup_lock 
     48        fi 
     49        local response 
     50        $DEBUG && echo "Running setup" >&4 
     51        if [ ! -z $* ] ; then 
     52            conf_unlock_wcopy 
     53            print_usage 1 
     54        elif [ -d ${WORK_PATH} ] ; then 
     55            echo "Looks like ${WORK_PATH} already exists."  
     56            echo "Start over by removing it? (y/N)" 
     57            read response 
     58            if [[ $response =~ '^[yY]([es]|[ES])?' ]] ; then 
     59                rm -rf ${WORK_PATH} 
     60                setup 
     61            else 
     62                echo "Setup failed." >&4 
     63                conf_unlock_wcopy 
     64                exit 1 
     65            fi 
     66        else 
     67            mkdir -p ${WORK_PATH}  
     68            conf_setup_lock 
     69            conf_checkout_tree 
     70            conf_unlock_wcopy 
     71        fi 
     72    fi 
    5073} 
    5174 
    5275function create { 
    53         local module=$1 
    54         shift 
    55         if [ -z $* ] ; then 
    56                 conf_create_module $module 
    57         else 
    58                 print_usage 1 
    59         fi 
     76    if conf_wcopy_locked? 
     77    then 
     78        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     79        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     80    else 
     81        conf_lock_wcopy 
     82        local module=$1 
     83        shift 
     84        if [ -z $* ] ; then 
     85            conf_create_module $module 
     86        else 
     87            conf_unlock_wcopy 
     88            print_usage 1 
     89        fi 
     90        conf_unlock_wcopy 
     91    fi 
    6092} 
    6193 
    6294function update { 
    63         if [ -z $* ] ; then 
    64                 conf_update_tree || conf_cleanexit 
    65         else 
    66                 print_usage 1 
    67         fi 
     95    if conf_wcopy_locked? 
     96    then 
     97        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     98        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     99    else 
     100        conf_lock_wcopy 
     101            if [ -z $* ] ; then 
     102                    conf_update_tree || conf_cleanExit 
     103            else 
     104            conf_unlock_wcopy 
     105                    print_usage 1 
     106            fi 
     107        conf_unlock_wcopy 
     108    fi 
    68109} 
    69110 
    70111function revert { 
    71         if [ -z $* ] ; then 
    72                 print_usage 1 
    73         else 
    74                 conf_revert $* 
    75         fi 
     112    if conf_wcopy_locked? 
     113    then 
     114        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     115        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     116    else 
     117        conf_lock_wcopy 
     118        if [ -z $* ] ; then 
     119            conf_unlock_wcopy 
     120            print_usage 1 
     121        else 
     122            conf_revert $* 
     123        fi 
     124        conf_unlock_wcopy 
     125    fi 
    76126} 
    77127 
    78128function commit { 
    79         if [ -z $* ] ; then 
    80                 local msg=`mktemp -t confman` 
    81                 # Moved up per Ian's request. 
    82                 echo "Change this file to your log message." > $msg 
    83                 echo "BugId: " >> $msg 
    84                 ${EDITOR} $msg 
    85                 sudo -v 
    86                 update || conf_cleanexit 
    87  
    88                 echo "Commit operation started" >&2 
    89         conf_commit "$LAYERS" $msg || return $? 
    90                 for layer in $LAYERS ; do 
    91                         echo "Rolling on $layer..." 
    92                         conf_rollout $layer || return $? 
    93                 done 
    94                 for file in $SINGULARITIES ; do 
    95                         conf_assemble_sing $file || return $? 
    96                 done 
    97         conf_recordAction commit 
    98         conf_markclean 
    99                 echo "Commit operation finished successfully" >&2 
    100                 rm -f $msg 
    101         else 
    102                 print_usage 1 
    103         fi 
     129    if conf_system_locked?  && conf_wcopy_locked? 
     130    then 
     131        local wcopy_pid=`cat ${WORK_PATH}/confman.lock`  
     132        local system_pid=`cat /var/run/confman.lock` 
     133        echo "The system is locked by confman[$system_pid] and your working copy is locked by confman[$wcopy_pid]" >&2 
     134    elif conf_system_locked?  
     135    then 
     136        local lock_pid=`cat /var/run/confman.lock`  
     137        echo "The system is locked by confman[$lock_pid]." >&2 
     138    elif conf_wcopy_locked? 
     139    then 
     140        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     141        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     142    else 
     143        conf_lock_wcopy 
     144        conf_lock_system 
     145        if [ -z $* ] ; then 
     146            local msg=`mktemp -t confman` 
     147            # Moved up per Ian's request. 
     148            echo "Change this file to your log message." > $msg 
     149            echo "BugId: " >> $msg 
     150            ${EDITOR} $msg 
     151            sudo -v 
     152            #Changed this from just update to fix locking issue - arjun 
     153            conf_update_tree || conf_cleanExit 
     154 
     155            echo "Commit operation started" >&2 
     156            conf_commit "$LAYERS" $msg || return $? 
     157            for layer in $LAYERS ; do 
     158                echo "Rolling on $layer..." 
     159                conf_rollout $layer || return $? 
     160            done 
     161            for file in $SINGULARITIES ; do 
     162                conf_assemble_sing $file || return $? 
     163            done 
     164            conf_recordAction commit 
     165            conf_markclean 
     166            echo "Commit operation finished successfully" >&2 
     167            rm -f $msg 
     168        else 
     169            conf_unlock_wcopy 
     170            conf_unlock_system 
     171            print_usage 1 
     172        fi 
     173        conf_unlock_wcopy 
     174        conf_unlock_system 
     175    fi 
    104176} 
    105177 
    106178# Short name intentional, don't want collision with real install. 
    107179function inst { 
    108         local file livefile 
    109  
    110         if [ -z "$*" ] ; then 
    111                 print_usage 1 
    112         else 
    113                 local msg=`mktemp -t confman` 
    114                 # Moved up per Ian's request. 
    115                 echo "Change this file to your log message." > $msg 
    116                 echo "BugId: " >> $msg 
    117                 ${EDITOR} $msg 
    118                 sudo -v 
    119                 update || conf_cleanexit 
    120  
    121                 echo "Installation operation started." >&2 
    122         conf_commit "$LAYERS" $msg || return $? 
    123                 for layer in $LAYERS ; do 
    124                         conf_install $layer "$@" 
    125                 done 
    126                 for file in $SINGULARITIES ; do 
    127                         conf_assemble_sing $file || conf_cleanexit 
    128                 done 
    129         conf_recordAction install 
    130         if ! conf_isclean ; then 
    131             echo "WARNING: Recent 'install' operations prevented a 'sync'" >&2 
    132             echo "Running a 'commit' is highly recommended." >&2 
    133         fi 
    134                 echo "Installation operation succeeded." >&2 
    135         fi 
     180    if conf_system_locked?  && conf_wcopy_locked? 
     181    then 
     182        local wcopy_pid=`cat ${WORK_PATH}/confman.lock`  
     183        local system_pid=`cat /var/run/confman.lock` 
     184        echo "The system is locked by confman[$system_pid] and your working copy is locked by confman[$wcopy_pid]" >&2 
     185    elif conf_system_locked?  
     186    then 
     187        local lock_pid=`cat /var/run/confman.lock`  
     188        echo "The system is locked by confman[$lock_pid]." >&2 
     189    elif conf_wcopy_locked? 
     190    then 
     191        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     192        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     193    else 
     194        conf_lock_wcopy 
     195        conf_lock_system 
     196        local file livefile 
     197 
     198        if [ -z "$*" ] ; then 
     199            conf_unlock_system 
     200            conf_unlock_wcopy 
     201            print_usage 1 
     202        else 
     203            local msg=`mktemp -t confman` 
     204            # Moved up per Ian's request. 
     205            echo "Change this file to your log message." > $msg 
     206            echo "BugId: " >> $msg 
     207            ${EDITOR} $msg 
     208            sudo -v 
     209            #changed from update to conf_update_tree to implement locking - arjun 
     210            conf_update_tree || conf_cleanExit 
     211 
     212            echo "Installation operation started." >&2 
     213            conf_commit "$LAYERS" $msg || return $? 
     214            for layer in $LAYERS ; do 
     215                conf_install $layer "$@" 
     216            done 
     217            for file in $SINGULARITIES ; do 
     218                conf_assemble_sing $file || conf_cleanExit 
     219            done 
     220            conf_recordAction install 
     221            if ! conf_isclean ; then 
     222                echo "WARNING: Recent 'install' operations prevented a 'sync'" >&2 
     223                echo "Running a 'commit' is highly recommended." >&2 
     224            fi 
     225            echo "Installation operation succeeded." >&2 
     226            conf_unlock_wcopy 
     227            conf_unlock_system 
     228        fi 
     229    fi 
    136230} 
    137231         
    138232 
    139233function import { 
    140          
    141         # Check for a force 
    142         local item OPTIND 
    143         force=0 
    144         while getopts "f" opt ; do 
    145                 case $opt in  
    146                         f) 
    147                         force=1 
    148                         shift 
    149                         ;; 
    150                         *) 
    151                         print_help 1 
    152                         ;; 
    153                 esac 
    154         done 
    155  
    156         local module=$1 
    157         local response usefile suffix file layer 
    158         local mode=$DEFAULT_MODE_FILE 
    159         local owner=$DEFAULT_OWNER 
    160         local group=$DEFAULT_GROUP 
    161         local comment=$DEFAULT_COMMENT 
    162         shift 
    163         if [ -z $1 ] ; then 
    164                 print_usage 1 
    165         fi 
    166  
    167         sudo -v 
    168         if [ -r $1 ] ; then 
    169                 file=`abspath $1` 
    170         else 
    171                 # If we can't enter the parent directory, this will help us 
    172                 # get the info we need. 
    173                 file=`sudo abspath $1` 
    174         fi 
    175         shift 
    176  
    177  
    178         # See if we're importing a singularity 
    179         if [[ "$SINGULARITIES" =~ "$file" ]] ; then 
    180                 suffix="-$module" 
    181         fi 
    182  
    183         # Error out when trying to import a symbolic link. 
    184         if sudo [ -L $file ] ; then 
    185                 echo "$file is a symbolic link!" >&4 
    186                 conf_cleanexit 
    187         fi 
    188  
    189         if [ -f ${WORK_PATH}/${module}${file}${suffix} ] ; then 
    190                 echo "$file already exists in your working copy of $module." \ 
    191                         "Skipping." >&4 
    192                 import $module $* 
    193                 return 
    194         fi 
    195  
    196         if [ $force = 0 ] ; then 
    197                 for layer in $LAYERS ; do 
    198                         if [ -f ${WORK_PATH}/${layer}${file}${suffix} ] ; then 
    199                                 echo "$file already exists in the ${layer}" \ 
    200                                      "module. Skipping." >&4 
    201                                 echo "Did you mean -f ?" >&4 
    202                                 import $module $* 
    203                                 return 
    204                         fi 
    205                 done 
    206         fi 
    207  
    208         if sudo [ -f $file ] ; then 
    209                 eval `sudo stat -f "mode=%Mp%Lp owner=%Su group=%Sg" $file` 
    210                 # Let's make our best guess on the comment character: 
    211                 local tmpfile=`mktemp -t confman` 
    212                 local biggestcount=0 
    213                 local count 
    214  
    215                 # Let's see if we can read the file as ourself: 
    216                 usefile=`mktemp -t confman` 
    217                 if [ ! -r $file ] ; then 
    218                         sudo cat $file > $usefile 
    219                 else 
    220                         cat $file > $usefile 
    221                 fi 
    222  
    223                 # Put all non-alphanumerics into a file 
    224                 awk '{print $1}' $usefile | egrep -o \ 
    225                         "^[^-_A-Za-z0-9]" > $tmpfile 
    226  
    227                 for char in `cat $tmpfile | sort | uniq` ; do 
    228                         count=`egrep -o "\\$char" $tmpfile | wc -l` 
    229                         if [ $count -gt $biggestcount ] ; then 
    230                                 biggestcount=$count 
    231                                 comment="$char" 
    232                         fi 
    233                 done 
    234                 rm $tmpfile 
    235  
    236                 # Convert mode string to base 10: 
    237                 mode=`echo "obase=10;ibase=8;$mode" | bc` 
    238                 # And use a bitmask to subtract off all write-access 
    239                 # 3949d = 7555o 
    240                 mode=$(($mode & 3949)) 
    241                 # And back to an octet: 
    242                 mode=`printf '%04o\n' $mode` 
    243         elif sudo [ -d "$file" ] ; then 
    244                 import $module $* ${file}/* 
    245                 return 
    246         else 
    247                 # Prompt for file owner 
    248                 echo "Who should be the file's owner? [ $owner ]" 
    249                 read response 
    250                 if [ ! -z $response ] ; then 
    251                         owner=$response 
    252                 fi 
    253  
    254                 # And file's group 
    255                 echo "Who should be the file's group? [ $group ]" 
    256                 read response 
    257                 if [ ! -z $response ] ; then 
    258                         group=$response 
    259                 fi 
    260  
    261                 # now, the permissions 
    262                 echo "What should the file's permissions be? [ $mode ]" 
    263                 read response 
    264                 if [ ! -z $response ] ; then 
    265                         mode=$response 
    266                 fi 
    267  
    268                 # now, the comment character 
    269                 echo "What string starts comment lines? [ $comment ]" 
    270                 read response 
    271                 if [ ! -z $response ] ; then 
    272                         comment=$response 
    273                 fi 
    274         fi 
    275  
    276         if [ ! -d "${WORK_PATH}/${module}`dirname $file`" ] ; then 
    277                 newdir "${WORK_PATH}/${module}`dirname $file`" 
    278         fi 
    279  
    280         # Time to generate the file 
    281         conf_gen_file $module "${file}${suffix}" $owner $group \ 
    282                 $mode "$comment" $usefile 
    283  
    284         # Removing temporary files 
    285         rm -f $usefile 
    286  
    287         # Are there more files to import? 
    288         if [ ! -z $1 ] ; then 
    289                 import $module $* 
    290         fi 
     234    if conf_wcopy_locked? 
     235    then 
     236        local lock_pid=`cat ${WORK_PATH}/confman.lock` #gets the PID of the confman instance that created the lock 
     237    fi 
     238    if conf_wcopy_locked? && [ !  $lock_pid = $$ ] #checks to see if the wcopy is locked; if so, checks to see if the current instance created the lock 
     239        then 
     240            echo "Your working copy is locked by confman[$lock_pid]" >&2 
     241        else 
     242        if  conf_lock_wcopy 
     243        then 
     244            local recursive_lock=1 #allows the lock to be deleted after all recursive calls are made 
     245        else 
     246            local recursive_lock=0 #if the lock already exists, this value is set to 0 so that the lock won't be deleted 
     247        fi 
     248        # Check for a force 
     249        local item OPTIND 
     250        force=0 
     251        while getopts "f" opt ; do 
     252            case $opt in  
     253                f) 
     254                force=1 
     255                shift 
     256                ;; 
     257                *) 
     258                conf_unlock_wcopy 
     259                print_help 1 
     260                ;; 
     261            esac 
     262        done 
     263 
     264        local module=$1 
     265        local response usefile suffix file layer 
     266        local mode=$DEFAULT_MODE_FILE 
     267        local owner=$DEFAULT_OWNER 
     268        local group=$DEFAULT_GROUP 
     269        local comment=$DEFAULT_COMMENT 
     270        shift 
     271        if [ -z $1 ] ; then 
     272            conf_unlock_wcopy 
     273            print_usage 1 
     274        fi 
     275 
     276        sudo -v 
     277        if [ -r $1 ] ; then 
     278            file=`abspath $1` 
     279        else 
     280            # If we can't enter the parent directory, this will help us 
     281            # get the info we need. 
     282            file=`sudo abspath $1` 
     283        fi 
     284        shift 
     285 
     286 
     287        # See if we're importing a singularity 
     288        if [[ "$SINGULARITIES" =~ "$file" ]] ; then 
     289            suffix="-$module" 
     290        fi 
     291 
     292        # Error out when trying to import a symbolic link. 
     293        if sudo [ -L $file ] ; then 
     294            echo "$file is a symbolic link!" >&4 
     295            conf_cleanExit 
     296        fi 
     297 
     298        if [ -f ${WORK_PATH}/${module}${file}${suffix} ] ; then 
     299            echo "$file already exists in your working copy of $module." \ 
     300                "Skipping." >&4 
     301            import $module $* 
     302            return 
     303        fi 
     304 
     305        if [ $force = 0 ] ; then 
     306            for layer in $LAYERS ; do 
     307                if [ -f ${WORK_PATH}/${layer}${file}${suffix} ] ; then 
     308                    echo "$file already exists in the ${layer}" \ 
     309                        "module. Skipping." >&4 
     310                    echo "Did you mean -f ?" >&4 
     311                    import $module $* 
     312                    return 
     313                fi 
     314            done 
     315        fi 
     316 
     317        if sudo [ -f $file ] ; then 
     318            eval `sudo stat -f "mode=%Mp%Lp owner=%Su group=%Sg" $file` 
     319            # Let's make our best guess on the comment character: 
     320            local tmpfile=`mktemp -t confman` 
     321            local biggestcount=0 
     322            local count 
     323 
     324            # Let's see if we can read the file as ourself: 
     325            usefile=`mktemp -t confman` 
     326            if [ ! -r $file ] ; then 
     327                sudo cat $file > $usefile 
     328            else 
     329                cat $file > $usefile 
     330            fi 
     331 
     332            # Put all non-alphanumerics into a file 
     333            awk '{print $1}' $usefile | egrep -o \ 
     334                "^[^-_A-Za-z0-9]" > $tmpfile 
     335 
     336            for char in `cat $tmpfile | sort | uniq` ; do 
     337                count=`egrep -o "\\$char" $tmpfile | wc -l` 
     338                if [ $count -gt $biggestcount ] ; then 
     339                    biggestcount=$count 
     340                    comment="$char" 
     341                fi 
     342            done 
     343            rm $tmpfile 
     344 
     345            # Convert mode string to base 10: 
     346            mode=`echo "obase=10;ibase=8;$mode" | bc` 
     347            # And use a bitmask to subtract off all write-access 
     348            # 3949d = 7555o 
     349            mode=$(($mode & 3949)) 
     350            # And back to an octet: 
     351            mode=`printf '%04o\n' $mode` 
     352        elif sudo [ -d "$file" ] ; then 
     353            import $module $* ${file}/* 
     354            return 
     355        else 
     356            # Prompt for file owner 
     357            echo "Who should be the file's owner? [ $owner ]" 
     358            read response 
     359            if [ ! -z $response ] ; then 
     360                owner=$response 
     361            fi 
     362 
     363            # And file's group 
     364            echo "Who should be the file's group? [ $group ]" 
     365            read response 
     366            if [ ! -z $response ] ; then 
     367                group=$response 
     368            fi 
     369 
     370            # now, the permissions 
     371            echo "What should the file's permissions be? [ $mode ]" 
     372            read response 
     373            if [ ! -z $response ] ; then 
     374                mode=$response 
     375            fi 
     376 
     377            # now, the comment character 
     378            echo "What string starts comment lines? [ $comment ]" 
     379            read response 
     380            if [ ! -z $response ] ; then 
     381                comment=$response 
     382            fi 
     383        fi 
     384 
     385        if [ ! -d "${WORK_PATH}/${module}`dirname $file`" ] ; then 
     386            newdir "${WORK_PATH}/${module}`dirname $file`" 
     387        fi 
     388 
     389        # Time to generate the file 
     390        conf_gen_file $module "${file}${suffix}" $owner $group \ 
     391            $mode "$comment" $usefile 
     392 
     393        # Removing temporary files 
     394        rm -f $usefile 
     395 
     396        # Are there more files to import? 
     397        if [ ! -z $1 ] ; then 
     398            import $module $* 
     399        fi 
     400        if [ $recursive_lock = 1 ] 
     401        then 
     402            conf_unlock_wcopy 
     403        fi 
     404    fi 
    291405 
    292406} 
    293407 
    294408function remove { 
    295         if [ -z $1 ] ; then print_usage 1 ; fi 
    296         conf_rm_file $* 
     409    if conf_wcopy_locked? 
     410    then 
     411        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     412        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     413    else 
     414        conf_lock_wcopy 
     415        if [ -z $1 ]  
     416        then 
     417            conf_unlock_wcopy 
     418            print_usage 1  
     419        fi 
     420        conf_rm_file $* 
     421        conf_unlock_wcopy 
     422    fi 
    297423} 
    298424 
    299425function newdir { 
    300         local dir=$1 
    301         local response module realpath 
    302         local mode=$DEFAULT_MODE_DIRECTORY 
    303         local owner=$DEFAULT_OWNER 
    304         local group=$DEFAULT_GROUP 
    305         local comment="dir" 
    306         local workdir=`abspath .` 
    307         if [ -z $1 ] ; then 
    308                 print_usage 1 
    309         fi 
    310  
    311         # Find the "real" directory's path 
    312         if [[ ! $dir =~ "^\/" ]] ; then 
    313                 dir="${workdir}/${dir}" 
    314         fi 
    315         module=`echo ${dir#$WORK_PATH} | sed -E 's:/([^/]+)/.*:\1:'` 
    316         realpath=${dir#${WORK_PATH}/${module}} 
    317  
    318         if [ -d $realpath ] ; then 
    319                 eval `sudo stat -f "mode=%Mp%Lp owner=%Su group=%Sg" $realpath` 
    320  
    321                 # Convert mode string to base 10: 
    322                 mode=`echo "obase=10;ibase=8;$mode" | bc` 
    323                 # And use a bitmask to subtract off all write-access 
    324                 # 3949d = 7555o 
    325                 mode=$(($mode & 3949)) 
    326                 # And back to an octet: 
    327                 mode=`printf '%04o\n' $mode` 
    328         else 
    329                 # Prompt for file owner 
    330                 echo "Who should be the directory's owner? [ $owner ]" 
    331                 read response 
    332                 if [ ! -z $response ] ; then 
    333                         owner=$response 
    334                 fi 
    335  
    336                 # And file's group 
    337                 echo "Who should be the directory's group? [ $group ]" 
    338                 read response 
    339                 if [ ! -z $response ] ; then 
    340                         group=$response 
    341                 fi 
    342  
    343                 # now, the permissions 
    344                 echo "What should the directory's permissions be? [ $mode ]" 
    345                 read response 
    346                 if [ ! -z $response ] ; then 
    347                         mode=$response 
    348                 fi 
    349         fi 
    350  
    351         # Time to create the directory. 
    352         echo "Making directory $dir with ${owner}:${group}, $mode" 
    353         conf_mkdir $dir $owner $group $mode  
     426    if conf_wcopy_locked? 
     427    then 
     428        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     429        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     430    else 
     431        conf_lock_wcopy 
     432        local dir=$1 
     433        local response module realpath 
     434        local mode=$DEFAULT_MODE_DIRECTORY 
     435        local owner=$DEFAULT_OWNER 
     436        local group=$DEFAULT_GROUP 
     437        local comment="dir" 
     438        local workdir=`abspath .` 
     439        if [ -z $1 ] ; then 
     440            conf_unlock_wcopy 
     441            print_usage 1 
     442        fi 
     443 
     444        # Find the "real" directory's path if not already specified 
     445        if [[ ! $dir =~ ^/ ]] ; then 
     446            dir="${workdir}/${dir}" 
     447        fi 
     448        module=`echo ${dir#$WORK_PATH} | sed -E 's:/([^/]+)/.*:\1:'` 
     449        realpath=${dir#${WORK_PATH}/${module}} 
     450 
     451        local directories=`echo "$realpath" | sed 's:/: :g'` 
     452        local fulldir="" 
     453 
     454        for dir_name in $directories; do 
     455           fulldir="${fulldir}/${dir_name}" 
     456 
     457           # If it exists on the filesystem, get its real attributes 
     458           if [ -d $fulldir ] ; then 
     459               eval `sudo stat -f "mode=%Mp%Lp owner=%Su group=%Sg" ${fulldir}` 
     460               echo "Making directory $fulldir with ${owner}:${group}, $mode" 
     461               conf_mkdir "$WORK_PATH/$module/$fulldir" $owner $group $mode 
     462 
     463           # Otherwise, prompt for attributes 
     464           else 
     465               # Prompt for file owner 
     466               echo "Who should be the directory's owner? [ $owner ]" 
     467               read response 
     468               if [ ! -z $response ] ; then 
     469                   owner=$response 
     470               fi 
     471    
     472               # And file's group 
     473               echo "Who should be the directory's group? [ $group ]" 
     474               read response 
     475               if [ ! -z $response ] ; then 
     476                   group=$response 
     477               fi 
     478    
     479               # now, the permissions 
     480               echo "What should the directory's permissions be? [ $mode ]" 
     481               read response 
     482               if [ ! -z $response ] ; then 
     483                   mode=$response 
     484               fi 
     485               echo "Making directory $fulldir with ${owner}:${group}, $mode" 
     486               conf_mkdir "$WORK_PATH/$module/$fulldir" $owner $group $mode 
     487               conf_unlock_wcopy 
     488 
     489           fi 
     490 
     491       done 
     492    fi 
    354493} 
    355494 
     
    378517 
    379518function chowner { 
    380         local recursive item OPTIND 
    381         while getopts "R" opt ; do 
    382                 case $opt in 
    383                         R) 
    384                         recursive=1 
    385                         shift 
    386                         ;; 
    387                         *) 
    388                         print_help 1 
    389                         ;; 
    390                 esac 
    391         done 
    392         local owner=$1 
    393         local file=$2 
    394         conf_set_prop $file owner $owner 
    395         if [ ! -z $recursive ] && [ -d $file ] ; then 
    396                 for item in $file/* ; do 
    397                         chowner -R $owner $item 
    398                 done 
    399         fi 
     519    if conf_wcopy_locked? 
     520    then 
     521        local lock_pid=`cat ${WORK_PATH}/confman.lock` #gets the PID of the confman instance that created the lock 
     522    fi 
     523    if conf_wcopy_locked? && [ !  $lock_pid = $$ ] #checks to see if the wcopy is locked; if so, checks to see if the current instance created the lock 
     524        then 
     525            echo "Your working copy is locked by confman[$lock_pid]" >&2 
     526        else 
     527        if  conf_lock_wcopy 
     528        then 
     529            local recursive_lock=1 #allows the lock to be deleted after all recurisve calls are made 
     530        else 
     531            local recursive_lock=0 #if the lock already exists, this value is set to 0 so that the lock won't be deleted 
     532        fi 
     533        local recursive item OPTIND 
     534        while getopts "R" opt ; do 
     535            case $opt in 
     536                R) 
     537                recursive=1 
     538                shift 
     539                ;; 
     540                *) 
     541                conf_unlock_wcopy 
     542                print_help 1 
     543                ;; 
     544            esac 
     545        done 
     546        local owner=$1 
     547        local file=$2 
     548        conf_set_prop $file owner $owner 
     549        if [ ! -z $recursive ] && [ -d $file ] ; then 
     550            for item in $file/* ; do 
     551                chowner -R $owner $item 
     552            done 
     553        fi 
     554        if [ $recursive_lock = 1 ] 
     555        then 
     556            conf_unlock_wcopy 
     557        fi 
     558    fi 
    400559} 
    401560 
    402561function chgroup { 
    403         local recursive item OPTIND 
    404         while getopts "R" opt ; do 
    405                 case $opt in 
    406                         R) 
    407                         recursive=1 
    408                         shift 
    409                         ;; 
    410                         *) 
    411                         print_help 1 
    412                         ;; 
    413                 esac 
    414         done 
    415         local group=$1 
    416         local file=$2 
    417         conf_set_prop $file group $group 
    418         if [ ! -z $recursive ] && [ -d $file ] ; then 
    419                 for item in $file/* ; do 
    420                         chgroup -R $group $item 
    421                 done 
    422         fi 
     562    if conf_wcopy_locked? 
     563    then 
     564        local lock_pid=`cat ${WORK_PATH}/confman.lock` #gets the PID of the confman instance that created the lock 
     565    fi 
     566    if conf_wcopy_locked? && [ !  $lock_pid = $$ ] #checks to see if the wcopy is locked; if so, checks to see if the current instance created the lock 
     567        then 
     568            echo "Your working copy is locked by confman[$lock_pid]" >&2 
     569        else 
     570        if  conf_lock_wcopy 
     571        then 
     572            local recursive_lock=1 #allows the lock to be deleted after all recurisve calls are made 
     573        else 
     574            local recursive_lock=0 #if the lock already exists, this value is set to 0 so that the lock won't be deleted 
     575        fi 
     576        local recursive item OPTIND 
     577        while getopts "R" opt ; do 
     578            case $opt in 
     579                R) 
     580                recursive=1 
     581                shift 
     582                ;; 
     583                *) 
     584                conf_unlock_wcopy 
     585                print_help 1 
     586                ;; 
     587            esac 
     588        done 
     589        local group=$1 
     590        local file=$2 
     591        conf_set_prop $file group $group 
     592        if [ ! -z $recursive ] && [ -d $file ] ; then 
     593            for item in $file/* ; do 
     594                chgroup -R $group $item 
     595            done 
     596        fi 
     597        if [ $recursive_lock = 1 ] 
     598        then 
     599            conf_unlock_wcopy 
     600        fi 
     601    fi 
    423602} 
    424603 
    425604function chmode { 
    426         local recursive item OPTIND 
    427         while getopts "R" opt ; do 
    428                 case $opt in 
    429                         R) 
    430                         recursive=1 
    431                         shift 
    432                         ;; 
    433                         *) 
    434                         print_help 1 
    435                         ;; 
    436                 esac 
    437         done 
    438         local mode=$1 
    439         local file=$2 
    440         conf_set_prop $file mode $mode 
    441         if [ ! -z $recursive ] && [ -d $file ] ; then 
    442                 for item in $file/* ; do 
    443                         chmode -R $mode $item 
    444                 done 
    445         fi 
     605    if conf_wcopy_locked? 
     606    then 
     607        local lock_pid=`cat ${WORK_PATH}/confman.lock` #gets the PID of the confman instance that created the lock 
     608    fi 
     609    if conf_wcopy_locked? && [ !  $lock_pid = $$ ] #checks to see if the wcopy is locked; if so, checks to see if the current instance created the lock 
     610        then 
     611            echo "Your working copy is locked by confman[$lock_pid]" >&2 
     612        else 
     613        if  conf_lock_wcopy 
     614        then 
     615            local recursive_lock=1 #allows the lock to be deleted after all recurisve calls are made 
     616        else 
     617            local recursive_lock=0 #if the lock already exists, this value is set to 0 so that the lock won't be deleted 
     618        fi 
     619        local recursive item OPTIND 
     620        while getopts "R" opt ; do 
     621            case $opt in 
     622                R) 
     623                recursive=1 
     624                shift 
     625                ;; 
     626                *) 
     627                conf_unlock_wcopy 
     628                print_help 1 
     629                ;; 
     630            esac 
     631        done 
     632        local mode=$1 
     633        local file=$2 
     634        conf_set_prop $file mode $mode 
     635        if [ ! -z $recursive ] && [ -d $file ] ; then 
     636            for item in $file/* ; do 
     637                chmode -R $mode $item 
     638            done 
     639        fi 
     640        if [ $recursive_lock = 1 ] 
     641        then 
     642            conf_unlock_wcopy 
     643        fi 
     644    fi 
    446645} 
    447646 
    448647function chcom { 
    449         local comment="$1" 
    450         local file=$2 
    451         conf_set_prop $file comment "$comment" 
     648    if conf_wcopy_locked? 
     649    then 
     650        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     651        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     652    else 
     653        conf_lock_wcopy 
     654        local comment="$1" 
     655        local file=$2 
     656        conf_set_prop $file comment "$comment" 
     657        conf_unlock_copy 
     658    fi 
    452659} 
    453660 
     
    465672 
    466673function checknew { 
    467         local module=$1 
    468         local checkpoint=$2 
    469         if [ -z $2 ] ; then 
    470                 print_usage 1 
    471         else 
    472                 conf_new_checkpoint $module $checkpoint 
    473         fi 
     674    if conf_wcopy_locked? 
     675    then 
     676        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     677        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     678    else 
     679        conf_lock_wcopy 
     680        local module=$1 
     681        local checkpoint=$2 
     682        if [ -z $2 ] ; then 
     683            conf_unlock_wcopy 
     684            print_usage 1 
     685        else       
     686            conf_new_checkpoint $module $checkpoint 
     687            conf_unlock_wcopy 
     688        fi 
     689    fi 
    474690} 
    475691 
    476692function checkclear { 
    477         local module=$1 
    478         local checkpoint=$2 
    479         if [ -z $2 ] ; then 
    480                 print_usage 1 
    481         else 
    482                 conf_rm_checkpoint $module $checkpoint 
    483         fi 
     693    if conf_wcopy_locked? 
     694    then 
     695        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     696        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     697    else 
     698        conf_lock_wcopy 
     699        local module=$1 
     700        local checkpoint=$2 
     701        if [ -z $2 ] ; then 
     702            conf_unlock_wcopy 
     703            print_usage 1 
     704        else 
     705            conf_rm_checkpoint $module $checkpoint 
     706            conf_unlock_wcopy 
     707        fi 
     708    fi 
    484709} 
    485710 
    486711function rollback { 
    487         local module=$1 
    488         local checkpoint=$2 
    489         local clock=$3 
    490         if [ -z $2 ] ; then 
    491                 print_usage 1 
    492         else 
    493                 echo "Rolling $module back to $checkpoint $clock" >&2 
    494                 conf_rollback $module $checkpoint $clock || conf_cleanexit 
    495                 for layer in $LAYERS ; do 
    496                         echo "Rolling on $layer..." 
    497                         conf_rollout $layer || conf_cleanexit 
    498                 done 
    499  
    500                 for file in $SINGULARITIES ; do 
    501                         conf_assemble_sing $file || conf_cleanexit 
    502                 done 
    503                 echo "Rollback succeeded." >&2 
    504         fi 
     712    if conf_system_locked?  && conf_wcopy_locked? 
     713    then 
     714        local wcopy_pid=`cat ${WORK_PATH}/confman.lock`  
     715        local system_pid=`cat /var/run/confman.lock` 
     716        echo "The system is locked by confman[$system_pid] and your working copy is locked by confman[$wcopy_pid]" >&2 
     717    elif conf_system_locked?  
     718    then 
     719        local lock_pid=`cat /var/run/confman.lock`  
     720        echo "The system is locked by confman[$lock_pid]." >&2 
     721    elif conf_wcopy_locked? 
     722    then 
     723        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     724        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     725    else 
     726        conf_lock_wcopy 
     727        conf_lock_system 
     728        local module=$1 
     729        local checkpoint=$2 
     730        local clock=$3 
     731        if [ -z $2 ] ; then 
     732            conf_unlock_wcopy 
     733            conf_unlock_system 
     734            print_usage 1 
     735        else 
     736            echo "Rolling $module back to $checkpoint $clock" >&2 
     737            conf_rollback $module $checkpoint $clock || conf_cleanExit 
     738            for layer in $LAYERS ; do 
     739                echo "Rolling on $layer..." 
     740                conf_rollout $layer || conf_cleanExit 
     741            done 
     742 
     743            for file in $SINGULARITIES ; do 
     744                conf_assemble_sing $file || conf_cleanExit 
     745            done 
     746            echo "Rollback succeeded." >&2 
     747            conf_unlock_wcopy 
     748            conf_unlock_system 
     749        fi 
     750    fi 
    505751} 
    506752 
    507753function rmmod { 
    508         local module=$1 
    509         if [ -z $module ] ; then 
    510                 print_usage 1 
    511         fi 
    512         conf_rmmod $module 
     754    if conf_wcopy_locked? 
     755    then 
     756        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     757        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     758    else 
     759        conf_lock_wcopy 
     760        local module=$1 
     761        if [ -z $module ] ; then 
     762            conf_unlock_wcopy 
     763            print_usage 1 
     764        fi 
     765        conf_rmmod $module 
     766        conf_unlock_wcopy 
     767    fi 
    513768} 
    514769 
    515770function rename { 
    516         local oldmod=$1 
    517         local newmod=$2 
    518         if [ -z $newmod ] ; then 
    519                 print_usage 1 
    520         fi 
    521         if [ ! -d "${WORK_PATH}/${oldmod}" ] ; then 
    522                 echo "${MYNAME}: Error: ${WORK_PATH}/${oldmod} doesn't exist" >&4 
    523                 conf_cleanexit 
    524         fi 
    525         if [ -e "${WORK_PATH}/${newmod}" ] ; then 
    526                 echo "${MYNAME}: Error: ${WORK_PATH}/${newmod}: file exists" >&4 
    527                 conf_cleanexit 
    528         fi 
    529         conf_rename $oldmod $newmod 
     771    if conf_wcopy_locked? 
     772    then 
     773        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     774        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     775    else 
     776        conf_lock_wcopy 
     777        local oldmod=$1 
     778        local newmod=$2 
     779        if [ -z $newmod ] ; then 
     780            conf_unlock_wcopy 
     781            print_usage 1 
     782        fi 
     783        if [ ! -d "${WORK_PATH}/${oldmod}" ] ; then 
     784            echo "${MYNAME}: Error: ${WORK_PATH}/${oldmod} doesn't exist" >&4 
     785            conf_cleanExit 
     786        fi 
     787        if [ -e "${WORK_PATH}/${newmod}" ] ; then 
     788            echo "${MYNAME}: Error: ${WORK_PATH}/${newmod}: file exists" >&4 
     789            conf_cleanExit 
     790        fi 
     791        conf_rename $oldmod $newmod 
     792        conf_unlock_wcopy 
     793    fi 
    530794} 
    531795 
     
    539803 
    540804function copy { 
    541         local src=$1 
    542         local dest=$2 
    543  
    544         if [ -z $2 ] ; then print_usage 1 ; fi 
    545  
    546         conf_cp $src $dest 
     805    if conf_wcopy_locked? 
     806    then 
     807        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     808        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     809    else 
     810        conf_lock_wcopy 
     811        local src=$1 
     812        local dest=$2 
     813        if [ -z $2 ]  
     814        then  
     815            conf_unlock_wcopy 
     816            print_usage 1    
     817        fi 
     818        conf_cp $src $dest 
     819        conf_unlock_wcopy 
     820    fi 
    547821} 
    548822 
    549823function move { 
    550         local src=$1 
    551         local dest=$2 
    552  
    553         if [ -z $2 ] ; then print_usage 1 ; fi 
    554  
    555         conf_mv $src $dest 
     824    if conf_wcopy_locked? 
     825    then 
     826        local lock_pid=`cat ${WORK_PATH}/confman.lock`  
     827        echo "Your working copy is locked by confman[$lock_pid]." >&2 
     828    else 
     829        conf_lock_wcopy 
     830        local src=$1 
     831        local dest=$2 
     832        if [ -z $2 ]  
     833        then 
     834            conf_unlock_wcopy 
     835            print_usage 1  
     836        fi 
     837        conf_mv $src $dest 
     838        conf_unlock_wcopy 
     839    fi 
    556840} 
    557841 
     
    590874} 
    591875 
    592 # Dubug mode? 
     876function audit { 
     877    tarball=$(conf_fetch) 
     878    if ! [ -s $tarball ]  
     879    then 
     880        echo "Could not fetch the tarball." >&2 
     881        exit 1 
     882    fi 
     883 
     884    tmpcopy=$(mktemp -d -t confman) 
     885    tmproot=$(mktemp -d -t confman) 
     886 
     887    tar -xzf $tarball -C $tmpcopy 
     888    rm -rf $tarball 
     889     
     890    for layer in $LAYERS 
     891    do 
     892        local module="${layer}" 
     893        local moduledir="$tmpcopy/$module" 
     894 
     895        for directory in `find $moduledir -type d -mindepth 1| grep -v "\.svn"`; do 
     896            local tmpdir=`echo $directory | sed "s:$moduledir::"` 
     897            tmpdir="$tmproot${tmpdir}" 
     898            local owner=`conf_get_prop ${directory} owner` 
     899            local group=`conf_get_prop ${directory} group` 
     900            local mode=`conf_get_prop ${directory} mode` 
     901            local opts="-d -o $owner -g $group -m $mode" 
     902            local cmd="sudo install $opts $tmpdir" 
     903            $cmd 
     904        done 
     905        for file in `find $moduledir -type f | grep -v "\.svn"` ; do 
     906            local tmpfile=`echo "$file" | sed "s:$moduledir::"` 
     907            local owner=`conf_get_prop ${file} owner` 
     908            local group=`conf_get_prop ${file} group` 
     909            local mode=`conf_get_prop ${file} mode` 
     910            local opts="-Sp -o $owner -g $group -m $mode" 
     911            local cmd="sudo install $opts $file $tmproot$tmpfile" 
     912            $cmd 
     913        done 
     914    done 
     915 
     916    for file in $SINGULARITIES 
     917    do 
     918        local livefile="$tmproot${file}" 
     919        local tmpfile=`mktemp -t confman` || exit 1 
     920        local owner group mode flag livepart msg 
     921        for layer in $LAYERS ; do 
     922            livepart="$tmproot${file}-${layer}" 
     923            myfile="$tmpcopy/${layer}/${file}-${layer}" 
     924            if [ -f $myfile -a -f $livepart ] ; then 
     925                    owner=`conf_get_prop ${myfile} owner` 
     926                    group=`conf_get_prop ${myfile} group` 
     927                    mode=`conf_get_prop ${myfile} mode` 
     928                    comment=`conf_get_prop      ${myfile} comment` 
     929                cat $livepart >> $tmpfile 
     930                sudo rm $livepart 
     931                flag=1 
     932            fi 
     933        done 
     934        if [ ! -z $flag ] ; then 
     935            local opts="-Sp -o $owner -g $group -m $mode" 
     936            local cmd="sudo install $opts $tmpfile $livefile" 
     937            $cmd 
     938        fi 
     939        rm -f $tmpfile 
     940    done 
     941    rm -rf $tmpcopy 
     942    sudo /usr/bin/diff -rPu / $tmproot | grep -v "^Only in" 
     943    sudo rm -rf $tmproot 
     944     
     945} 
     946 
     947function tester { 
     948local asd="asddsa" 
     949    local output=`echo $asd | grep -v "qw"` 
     950echo $output 
     951} 
     952 
     953# Debug mode? 
    593954while getopts "d" opt ; do 
    594955        case $opt in 
     
    638999    checkclear|chcl|chrm )          checkclear "$@" ;; 
    6391000    rollback|ro* )                  rollback "$@" ;; 
     1001    audit )                         audit "$@" ;; 
     1002    tester )                        tester "$@" ;; 
    6401003    * )                             print_usage 1 ;; 
    6411004esac  
  • tags/confman-1.5.5a/confmancommon.sh

    r142 r177  
    5151fi 
    5252 
     53# Test if the specified group exists before setting folder groups 
    5354if ! [ -d "$REPO_DB" ] ; then 
    54     sudo install -d -o root -g $CONF_GROUP -m 770 "$REPO_DB" 
    55     sudo chmod g+s "$REPO_DB" 
     55        if ! [ conf_checkgroup ]; then 
     56                sudo install -d -o root -m 770 "$REPO_DB" 
     57        else 
     58                sudo install -d -o root -g $CONF_GROUP -m 770 "$REPO_DB" 
     59        fi 
     60        sudo chmod g+s "$REPO_DB" 
    5661fi 
    5762 
     
    8186 
    8287# And we'll set a trap: 
    83 trap "conf_cleanexit" SIGINT SIGTERM SIGHUP 
     88trap "conf_cleanExit" SIGINT SIGTERM SIGHUP 
    8489 
  • tags/confman-1.5.5a/confmanlib.sh

    r172 r177  
    1515# Checks out the conf tree if we don't already have it. Updates it if we do. 
    1616function conf_checkout_tree { 
    17         if [ ! -d ${WORK_PATH} ] ; then 
     17        if [ ! -d ${WORK_PATH}/.svn ] ; then 
    1818                        local path=`echo ${WORK_PATH} | sed -E 's:/[^/]+$::'` 
    1919                        mkdir -p ${WORK_PATH} 
     
    3939function conf_update_tree { 
    4040        svn update ${WORK_PATH} 
     41} 
     42 
     43function conf_setup_lock { 
     44    if [ -f ${WORK_PATH}/confman.lock ] 
     45    then 
     46        return 1 
     47    else 
     48        touch ${WORK_PATH}/confman.lock 
     49        echo $$ > "${WORK_PATH}/confman.lock" #Send PID to the lock to allow for recursive calls 
     50        return 0 
     51    fi 
     52} 
     53 
     54function conf_lock_wcopy { 
     55    if [ ! -d ${WORK_PATH}/.svn ] 
     56    then 
     57        echo "${WORK_PATH} is not a valid svn working copy or does not exist." >&4 
     58        exit 1 
     59    fi 
     60    if [ -f ${WORK_PATH}/confman.lock ] 
     61    then 
     62        return 1 
     63    else 
     64        touch ${WORK_PATH}/confman.lock 
     65        echo $$ > "${WORK_PATH}/confman.lock" #Send PID to the lock to allow for recursive calls 
     66        return 0 
     67    fi 
     68} 
     69 
     70function conf_unlock_wcopy { 
     71    if [ -f ${WORK_PATH}/confman.lock ] 
     72    then 
     73        rm ${WORK_PATH}/confman.lock 
     74    fi 
     75} 
     76 
     77function conf_lock_system { 
     78    if [ -f /var/run/confman.lock ] 
     79    then 
     80        return 1 
     81    else 
     82        sudo touch /var/run/confman.lock 
     83        sudo chmod 666 /var/run/confman.lock 
     84        sudo echo $$ > "/var/run/confman.lock"  
     85        return 1 
     86    fi 
     87} 
     88 
     89function conf_unlock_system { 
     90    if [ -f /var/run/confman.lock ] 
     91    then 
     92        sudo rm /var/run/confman.lock 
     93    fi 
     94} 
     95 
     96function conf_wcopy_locked? { 
     97    if [ -f ${WORK_PATH}/confman.lock ] 
     98    then 
     99        return 0 
     100    else 
     101        return 1 
     102    fi 
     103} 
     104 
     105function conf_system_locked? { 
     106    if [ -f /var/run/confman.lock ] 
     107    then 
     108        return 0 
     109    else 
     110        return 1 
     111    fi 
    41112} 
    42113 
     
    377448        svn mv ${WORK_PATH}/${oldmod} ${WORK_PATH}/${newmod} || \ 
    378449                {       echo "There was a problem renaming the modules." >&4 ; \ 
    379                         conf_clean_exit 1  
     450                        conf_cleanExit 1  
    380451                } 
    381452        svn mv ${WORK_PATH}/${REPO_CHECKPTS}/${oldmod} \ 
    382453                        ${WORK_PATH}/${REPO_CHECKPTS}/${newmod} || \ 
    383454                {       echo "There was a problem renaming the checkpts." >&4 ; \ 
    384                         conf_clean_exit 1  
     455                        conf_cleanExit 1  
    385456                } 
    386457 
    387458        svn update ${WORK_PATH} || \ 
    388459                {       echo "Your working copy didn't update correctly." >&4 ; \ 
    389                         conf_clean_exit 1  
     460                        conf_cleanExit 1  
    390461                } 
    391462        svn commit -m "Renaming ${oldmod} to ${newmod}, phase 1." \ 
    392463                ${WORK_PATH}/{,${REPO_CHECKPTS}}/{${oldmod},${newmod}} || \ 
    393                 {       echo "Committing the changes failed." >&4 ; conf_clean_exit 1  
     464                {       echo "Committing the changes failed." >&4 ; conf_cleanExit 1  
    394465                } 
    395466 
     
    404475        svn update ${WORK_PATH} || \ 
    405476                {       echo "Your working copy didn't update correctly." >&4 ; \ 
    406                         conf_clean_exit 1  
     477                        conf_cleanExit 1  
    407478                } 
    408479        svn commit -m "Renaming ${oldmod} to ${newmod}, phase 2." \ 
    409480                ${WORK_PATH}/${newmod} || \ 
    410                 {       echo "Committing the changes failed." >&4 ; conf_clean_exit 1  
     481                {       echo "Committing the changes failed." >&4 ; conf_cleanExit 1  
    411482                } 
    412483 
     
    418489        svn update ${WORK_PATH} || \ 
    419490                {       echo "Your working copy didn't update correctly." >&4 ; \ 
    420                         conf_clean_exit 1  
     491                        conf_cleanExit 1  
    421492                } 
    422493        svn commit -m "Renaming ${oldmod} to ${newmod}, complete." \ 
    423494                ${WORK_PATH}/${newmod} || \ 
    424                 {       echo "Committing the changes failed." >&4 ; conf_clean_exit 1  
     495                {       echo "Committing the changes failed." >&4 ; conf_cleanExit 1  
    425496                } 
    426497} 
     
    536607# The SIGNAL seems to kill the logger process spawned by the parent  
    537608# process, which is receiving its input from our fd 2. 
    538 function conf_cleanexit { 
     609function conf_cleanExit { 
    539610    echo "Received a signal. Exiting cleanly." | conf_logger 
    540611        echo "Abort, Abort! Patience is a virtue." >&4 
     
    544615        # permissions here to be in a consistent state. 
    545616        chmod 700 ${WORK_PATH} 
    546  
    547617        echo "Removing leftover temp files..." >&4 
    548618        find /tmp/confman* -maxdepth 0 -user `whoami` -exec rm -rf {} \; 
     
    551621        echo "Undoing damage to your working copy..." >&4 
    552622        [ -d "${WORK_PATH}" ] && svn cleanup ${WORK_PATH} 
    553         echo "All clean. Terminating." >&4 
     623 
     624    echo "Removing any system or working copy locks..." >&4 
     625    conf_unlock_wcopy 
     626    conf_unlock_system 
     627         
     628    echo "All clean. Terminating." >&4 
    554629 
    555630        exit ${1:-1} 
    556631}        
    557632 
     633function conf_checkgroup { 
     634        GROUP_FILE=$(mktemp -t confman) 
     635    GROUP_STAT=$(chgrp staff $GROUP_FILE 2>&1) 
     636        rm $GROUP_FILE 
     637        if [ -n "$GROUP_STAT" ] ; then 
     638       return 2 
     639    else 
     640       return 0 
     641    fi 
     642} 
     643 
    558644# vim:ts=4 
    559645 
  • tags/confman-1.5.5a/confsync.sh

    r157 r177  
    1212## 
    1313 
    14 . /usr/local/rescomp/lib/confmancommon.sh 
     14# Try loading a development library first 
     15if [ -r ./confmancommon.sh ] ; then 
     16    echo "Loading development library from current working directory." >&2 
     17    . ./confmancommon.sh 
     18elif [ -r /usr/local/rescomp/lib/confmancommon.sh ] ; then 
     19    . /usr/local/rescomp/lib/confmancommon.sh 
     20else 
     21    echo "Can't find confmancommon.sh. Exiting." >&2 
     22fi 
    1523 
    1624# If we're in debug mode, we should log stderr messages to the logger 
     
    5866for layer in $LAYERS ; do 
    5967        echo "Rolling on $layer..." 
    60         conf_rollout $layer || conf_cleanexit 
     68        conf_rollout $layer || conf_cleanExit 
    6169done 
    6270for file in $SINGULARITIES ; do 
    6371    echo "Assembing singularity $file..." 
    64         conf_assemble_sing $file || conf_cleanexit 
     72        conf_assemble_sing $file || conf_cleanExit 
    6573done 
    6674conf_markclean 
  • tags/confman-1.5.5a/export.sh

    r150 r177  
    1414## 
    1515 
    16 . /usr/local/rescomp/lib/confmancommon.sh 
     16# Try loading a development library first 
     17if [ -r ./confmancommon.sh ] ; then 
     18    echo "Loading development library from current working directory." >&2 
     19    . ./confmancommon.sh 
     20elif [ -r /usr/local/rescomp/lib/confmancommon.sh ] ; then 
     21    . /usr/local/rescomp/lib/confmancommon.sh 
     22else 
     23    echo "Can't find confmancommon.sh. Exiting." >&2 
     24fi 
    1725 
    1826# If we're in debug mode, we should log stderr messages to the logger 
Note: See TracChangeset for help on using the changeset viewer.