source: tags/confman-1.5.6a1/confman @ 174

Revision 174, 29.1 KB checked in by arjun, 4 years ago (diff)

Fixed the import bug.

  • Property rc:mode set to 0555
  • Property svn:executable set to *
  • Property svn:keywords set to Id
Line 
1#! /bin/bash 
2#
3# confman provides a command-line interface to Rescomp's server configuration
4# management system.
5#
6# confman help
7#       Print help and usage information
8#
9# Author: Chris Cowart <ccowart@rescomp.berkeley.edu>
10# Date: 30 March 2006
11#
12# $Id$
13
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
23
24# Set a default editor
25if [ -z ${EDITOR} ] ; then
26        if which vim >/dev/null 2>&1 ; then
27                EDITOR="vim"
28        else
29                EDITOR="vi"
30        fi
31fi
32
33# Let's make sure that only you can read your working copy
34# Have to make this less restrictive due to NFS home dirs.
35umask 022
36
37# This function implements the setup subcommand. It is intended to be called
38# with no arguments, and will error if that's not the case.
39function setup {
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
73}
74
75function create {
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
92}
93
94function update {
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
109}
110
111function revert {
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
126}
127
128function commit {
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
176}
177
178# Short name intentional, don't want collision with real install.
179function inst {
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
230}
231       
232
233function import {
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
405
406}
407
408function remove {
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
423}
424
425function newdir {
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
493}
494
495function list {
496        local file item
497        if [ -z $1 ] ; then
498                file=`abspath .`
499        else
500                file=`abspath $1`
501        fi
502        echo -e "--------------------------------------------------------"
503        echo -e "Mode\tOwner\tGroup\tComment\t\tFilename"
504        echo -e "--------------------------------------------------------"
505        if [ -f "$file" ] ; then
506                conf_list $file
507        elif [ -d "$file" ] ; then
508                for item in `ls $file` ; do
509                        conf_list "$file/$item"
510                done
511        fi
512}
513
514function status {
515        conf_status $*
516}
517
518function chowner {
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
559}
560
561function chgroup {
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
602}
603
604function chmode {
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
645}
646
647function chcom {
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
659}
660
661function checklook {
662        local module=$1
663        local chkdir=${WORK_PATH}/${REPO_CHECKPTS}/${module}
664        if [ -z $1 ] ; then
665                print_usage 1
666        elif [ -d $chkdir ] ; then
667                ls $chkdir
668        else
669                echo "There are no checkpoints for ${module}."
670        fi
671}
672
673function checknew {
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
690}
691
692function checkclear {
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
709}
710
711function rollback {
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
751}
752
753function rmmod {
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
768}
769
770function rename {
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
794}
795
796function diff {
797        conf_diff $*
798}
799
800function log {
801        conf_log $*
802}
803
804function copy {
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
821}
822
823function move {
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
840}
841
842function lsattr {
843    if [ -z "$1" ] ; then
844        conf_lsattr *
845    else
846        conf_lsattr "$@"
847    fi
848}
849
850function chattr {
851    local attr="$1"
852    shift
853    local value="${1:-true}"
854    shift
855    if [ -z "$1" ] ; then print_usage 1 ; fi
856
857    conf_chattr "$attr" "$value" "$@"
858}
859
860function rmattr {
861    local attr="$1"
862    shift
863    if [ -z "$1" ] ; then print_usage 1 ; fi
864
865    conf_rmattr "$attr" "$@"
866}
867
868function state {
869    if conf_isclean ; then
870        echo "This host is clean."
871    else
872        echo "This host may be dirty. Consider running a 'commit' operation"
873    fi
874}
875
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?
954while getopts "d" opt ; do
955        case $opt in
956                d)
957                DEBUG="true"
958                shift
959                ;;
960                *)
961                print_help 1
962                ;;
963        esac
964done
965
966
967# Dispatch the subcommand. This must happen last and in the global context.
968subcommand=$1
969shift
970case $subcommand in
971    help )                          print_help "$@" ; exit 0 ;;
972    setup|se* )                     setup "$@" ;;
973    status )                        status "$@" ;;
974    state )                         state ;;
975    create|cr* )                    create "$@" ;;
976    update|u* )                     update "$@" ;;
977    commit|com* )                   commit "$@" ;;
978    import|im* )                    import "$@" ;;
979    install|in* )                   inst "$@" ;;
980    remove|rem*|rm )                remove "$@" ;;
981    rev* )                          revert "$@" ;;
982    ren* )                          rename "$@" ;;
983    rmmod )                         rmmod "$@" ;;
984    mkdir|mkd* )                    newdir "$@" ;;
985    list|ls )                       list "$@" ;;
986    lsattr )                        lsattr "$@" ;;
987    chattr )                        chattr "$@" ;;
988    rmattr )                        rmattr "$@" ;;
989    move|mv )                       move "$@" ;;
990    copy|cp )                       copy "$@" ;;
991    diff )                          diff "$@" ;;
992    log )                           log "$@" ;;
993    chmod )                         chmode "$@" ;;
994    chown )                         chowner "$@" ;;
995    chcom )                         chcom "$@" ;;
996    chgrp )                         chgroup "$@" ;;
997    checklook|checklist|chls|chlk ) checklook "$@" ;;
998    checknew|chnw )                 checknew "$@" ;;
999    checkclear|chcl|chrm )          checkclear "$@" ;;
1000    rollback|ro* )                  rollback "$@" ;;
1001    audit )                         audit "$@" ;;
1002    tester )                        tester "$@" ;;
1003    * )                             print_usage 1 ;;
1004esac
1005
1006exit
1007
1008# vim:ts=4
1009
Note: See TracBrowser for help on using the repository browser.