source: tags/confman-1.5.6a/confman @ 180

Revision 180, 27.5 KB checked in by arjun, 5 years ago (diff)

Fixing some issues with locking

  • 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        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
43        unset WCOPY_LOCK_PID
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        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
79        unset WCOPY_LOCK_PID
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        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
98        unset WCOPY_LOCK_PID
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        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
115        unset WCOPY_LOCK_PID
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        echo "The system is locked by confman[$SYSTEM_LOCK_PID] and your working copy is locked by confman[$WCOPY_LOCK_PID]" >&2
132        unset WCOPY_LOCK_PID
133        unset SYSTEM_LOCK_PID
134    elif conf_system_locked?
135    then
136        echo "The system is locked by confman[$SYSTEM_LOCK_PID]." >&2
137        unset SYSTEM_LOCK_PID
138    elif conf_wcopy_locked?
139    then
140        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
141        unset WCOPY_LOCK_PID
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        echo "The system is locked by confman[$SYSTEM_LOCK_PID] and your working copy is locked by confman[$WCOPY_LOCK_PID]" >&2
183        unset WCOPY_LOCK_PID
184        unset SYSTEM_LOCK_PID
185    elif conf_system_locked?
186    then
187        echo "The system is locked by confman[$SYSTEM_LOCK_PID]." >&2
188        unset SYSTEM_LOCK_PID
189    elif conf_wcopy_locked?
190    then
191        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
192        unset WCOPY_LOCK_PID
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        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
237        unset WCOPY_LOCK_PID
238    else
239        if  conf_lock_wcopy
240        then
241            local recursive_lock=1 #allows the lock to be deleted after all recursive calls are made
242        else
243            local recursive_lock=0 #if the lock already exists, this value is set to 0 so that the lock won't be deleted
244        fi
245        # Check for a force
246        local item OPTIND
247        force=0
248        while getopts "f" opt ; do
249            case $opt in
250                f)
251                force=1
252                shift
253                ;;
254                *)
255                conf_unlock_wcopy
256                print_help 1
257                ;;
258            esac
259        done
260
261        local module=$1
262        local response usefile suffix file layer
263        local mode=$DEFAULT_MODE_FILE
264        local owner=$DEFAULT_OWNER
265        local group=$DEFAULT_GROUP
266        local comment=$DEFAULT_COMMENT
267        shift
268        if [ -z $1 ] ; then
269            conf_unlock_wcopy
270            print_usage 1
271        fi
272
273        sudo -v
274        if [ -r $1 ] ; then
275            file=`abspath $1`
276        else
277            # If we can't enter the parent directory, this will help us
278            # get the info we need.
279            file=`sudo abspath $1`
280        fi
281        shift
282
283
284        # See if we're importing a singularity
285        if [[ "$SINGULARITIES" =~ "$file" ]] ; then
286            suffix="-$module"
287        fi
288
289        # Error out when trying to import a symbolic link.
290        if sudo [ -L $file ] ; then
291            echo "$file is a symbolic link!" >&4
292            conf_cleanExit
293        fi
294
295        if [ -f ${WORK_PATH}/${module}${file}${suffix} ] ; then
296            echo "$file already exists in your working copy of $module." \
297                "Skipping." >&4
298            import $module $*
299            return
300        fi
301
302        if [ $force = 0 ] ; then
303            for layer in $LAYERS ; do
304                if [ -f ${WORK_PATH}/${layer}${file}${suffix} ] ; then
305                    echo "$file already exists in the ${layer}" \
306                        "module. Skipping." >&4
307                    echo "Did you mean -f ?" >&4
308                    import $module $*
309                    return
310                fi
311            done
312        fi
313
314        if sudo [ -f $file ] ; then
315            eval `sudo stat -f "mode=%Mp%Lp owner=%Su group=%Sg" $file`
316            # Let's make our best guess on the comment character:
317            local tmpfile=`mktemp -t confman`
318            local biggestcount=0
319            local count
320
321            # Let's see if we can read the file as ourself:
322            usefile=`mktemp -t confman`
323            if [ ! -r $file ] ; then
324                sudo cat $file > $usefile
325            else
326                cat $file > $usefile
327            fi
328
329            # Put all non-alphanumerics into a file
330            awk '{print $1}' $usefile | egrep -o \
331                "^[^-_A-Za-z0-9]" > $tmpfile
332
333            for char in `cat $tmpfile | sort | uniq` ; do
334                count=`egrep -o "\\$char" $tmpfile | wc -l`
335                if [ $count -gt $biggestcount ] ; then
336                    biggestcount=$count
337                    comment="$char"
338                fi
339            done
340            rm $tmpfile
341
342            # Convert mode string to base 10:
343            mode=`echo "obase=10;ibase=8;$mode" | bc`
344            # And use a bitmask to subtract off all write-access
345            # 3949d = 7555o
346            mode=$(($mode & 3949))
347            # And back to an octet:
348            mode=`printf '%04o\n' $mode`
349        elif sudo [ -d "$file" ] ; then
350            import $module $* ${file}/*
351            return
352        else
353            # Prompt for file owner
354            echo "Who should be the file's owner? [ $owner ]"
355            read response
356            if [ ! -z $response ] ; then
357                owner=$response
358            fi
359
360            # And file's group
361            echo "Who should be the file's group? [ $group ]"
362            read response
363            if [ ! -z $response ] ; then
364                group=$response
365            fi
366
367            # now, the permissions
368            echo "What should the file's permissions be? [ $mode ]"
369            read response
370            if [ ! -z $response ] ; then
371                mode=$response
372            fi
373
374            # now, the comment character
375            echo "What string starts comment lines? [ $comment ]"
376            read response
377            if [ ! -z $response ] ; then
378                comment=$response
379            fi
380        fi
381
382        if [ ! -d "${WORK_PATH}/${module}`dirname $file`" ] ; then
383            newdir "${WORK_PATH}/${module}`dirname $file`"
384        fi
385
386        # Time to generate the file
387        conf_gen_file $module "${file}${suffix}" $owner $group \
388            $mode "$comment" $usefile
389
390        # Removing temporary files
391        rm -f $usefile
392
393        # Are there more files to import?
394        if [ ! -z $1 ] ; then
395            import $module $*
396        fi
397        if [ $recursive_lock = 1 ]
398        then
399            conf_unlock_wcopy
400        fi
401    fi
402
403}
404
405function remove {
406    if conf_wcopy_locked?
407    then
408        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
409        unset WCOPY_LOCK_PID
410    else
411        conf_lock_wcopy
412        if [ -z $1 ]
413        then
414            conf_unlock_wcopy
415            print_usage 1
416        fi
417        conf_rm_file $*
418        conf_unlock_wcopy
419    fi
420}
421
422function newdir {
423    if conf_wcopy_locked?
424    then
425        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
426        unset WCOPY_LOCK_PID
427    else
428        conf_lock_wcopy
429        local dir=$1
430        local response module realpath
431        local mode=$DEFAULT_MODE_DIRECTORY
432        local owner=$DEFAULT_OWNER
433        local group=$DEFAULT_GROUP
434        local comment="dir"
435        local workdir=`abspath .`
436        if [ -z $1 ] ; then
437            conf_unlock_wcopy
438            print_usage 1
439        fi
440
441        # Find the "real" directory's path if not already specified
442        if [[ ! $dir =~ ^/ ]] ; then
443            dir="${workdir}/${dir}"
444        fi
445        module=`echo ${dir#$WORK_PATH} | sed -E 's:/([^/]+)/.*:\1:'`
446        realpath=${dir#${WORK_PATH}/${module}}
447
448        local directories=`echo "$realpath" | sed 's:/: :g'`
449        local fulldir=""
450
451        for dir_name in $directories; do
452           fulldir="${fulldir}/${dir_name}"
453
454           # If it exists on the filesystem, get its real attributes
455           if [ -d $fulldir ] ; then
456               eval `sudo stat -f "mode=%Mp%Lp owner=%Su group=%Sg" ${fulldir}`
457               echo "Making directory $fulldir with ${owner}:${group}, $mode"
458               conf_mkdir "$WORK_PATH/$module/$fulldir" $owner $group $mode
459
460           # Otherwise, prompt for attributes
461           else
462               # Prompt for file owner
463               echo "Who should be the directory's owner? [ $owner ]"
464               read response
465               if [ ! -z $response ] ; then
466                   owner=$response
467               fi
468   
469               # And file's group
470               echo "Who should be the directory's group? [ $group ]"
471               read response
472               if [ ! -z $response ] ; then
473                   group=$response
474               fi
475   
476               # now, the permissions
477               echo "What should the directory's permissions be? [ $mode ]"
478               read response
479               if [ ! -z $response ] ; then
480                   mode=$response
481               fi
482               echo "Making directory $fulldir with ${owner}:${group}, $mode"
483               conf_mkdir "$WORK_PATH/$module/$fulldir" $owner $group $mode
484               conf_unlock_wcopy
485
486           fi
487
488       done
489    fi
490}
491
492function list {
493        local file item
494        if [ -z $1 ] ; then
495                file=`abspath .`
496        else
497                file=`abspath $1`
498        fi
499        echo -e "--------------------------------------------------------"
500        echo -e "Mode\tOwner\tGroup\tComment\t\tFilename"
501        echo -e "--------------------------------------------------------"
502        if [ -f "$file" ] ; then
503                conf_list $file
504        elif [ -d "$file" ] ; then
505                for item in `ls $file` ; do
506                        conf_list "$file/$item"
507                done
508        fi
509}
510
511function status {
512        conf_status $*
513}
514
515function chowner {
516    if conf_wcopy_locked?
517    then
518        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
519        unset WCOPY_LOCK_PID
520    else
521        if  conf_lock_wcopy
522        then
523            local recursive_lock=1 #allows the lock to be deleted after all recurisve calls are made
524        else
525            local recursive_lock=0 #if the lock already exists, this value is set to 0 so that the lock won't be deleted
526        fi
527        local recursive item OPTIND
528        while getopts "R" opt ; do
529            case $opt in
530                R)
531                recursive=1
532                shift
533                ;;
534                *)
535                conf_unlock_wcopy
536                print_help 1
537                ;;
538            esac
539        done
540        local owner=$1
541        local file=$2
542        conf_set_prop $file owner $owner
543        if [ ! -z $recursive ] && [ -d $file ] ; then
544            for item in $file/* ; do
545                chowner -R $owner $item
546            done
547        fi
548        if [ $recursive_lock = 1 ]
549        then
550            conf_unlock_wcopy
551        fi
552    fi
553}
554
555function chgroup {
556    if conf_wcopy_locked?
557    then
558        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
559        unset WCOPY_LOCK_PID
560    else
561        if  conf_lock_wcopy
562        then
563            local recursive_lock=1 #allows the lock to be deleted after all recurisve calls are made
564        else
565            local recursive_lock=0 #if the lock already exists, this value is set to 0 so that the lock won't be deleted
566        fi
567        local recursive item OPTIND
568        while getopts "R" opt ; do
569            case $opt in
570                R)
571                recursive=1
572                shift
573                ;;
574                *)
575                conf_unlock_wcopy
576                print_help 1
577                ;;
578            esac
579        done
580        local group=$1
581        local file=$2
582        conf_set_prop $file group $group
583        if [ ! -z $recursive ] && [ -d $file ] ; then
584            for item in $file/* ; do
585                chgroup -R $group $item
586            done
587        fi
588        if [ $recursive_lock = 1 ]
589        then
590            conf_unlock_wcopy
591        fi
592    fi
593}
594
595function chmode {
596    if conf_wcopy_locked?
597    then
598        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
599        unset WCOPY_LOCK_PID
600    else
601        if  conf_lock_wcopy
602        then
603            local recursive_lock=1 #allows the lock to be deleted after all recurisve calls are made
604        else
605            local recursive_lock=0 #if the lock already exists, this value is set to 0 so that the lock won't be deleted
606        fi
607        local recursive item OPTIND
608        while getopts "R" opt ; do
609            case $opt in
610                R)
611                recursive=1
612                shift
613                ;;
614                *)
615                conf_unlock_wcopy
616                print_help 1
617                ;;
618            esac
619        done
620        local mode=$1
621        local file=$2
622        conf_set_prop $file mode $mode
623        if [ ! -z $recursive ] && [ -d $file ] ; then
624            for item in $file/* ; do
625                chmode -R $mode $item
626            done
627        fi
628        if [ $recursive_lock = 1 ]
629        then
630            conf_unlock_wcopy
631        fi
632    fi
633}
634
635function chcom {
636    if conf_wcopy_locked?
637    then
638        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
639        unset WCOPY_LOCK_PID
640    else
641        conf_lock_wcopy
642        local comment="$1"
643        local file=$2
644        conf_set_prop $file comment "$comment"
645        conf_unlock_copy
646    fi
647}
648
649function checklook {
650        local module=$1
651        local chkdir=${WORK_PATH}/${REPO_CHECKPTS}/${module}
652        if [ -z $1 ] ; then
653                print_usage 1
654        elif [ -d $chkdir ] ; then
655                ls $chkdir
656        else
657                echo "There are no checkpoints for ${module}."
658        fi
659}
660
661function checknew {
662    if conf_wcopy_locked?
663    then
664        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
665        unset WCOPY_LOCK_PID
666    else
667        conf_lock_wcopy
668        local module=$1
669        local checkpoint=$2
670        if [ -z $2 ] ; then
671            conf_unlock_wcopy
672            print_usage 1
673        else     
674            conf_new_checkpoint $module $checkpoint
675            conf_unlock_wcopy
676        fi
677    fi
678}
679
680function checkclear {
681    if conf_wcopy_locked?
682    then
683        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
684        unset WCOPY_LOCK_PID
685    else
686        conf_lock_wcopy
687        local module=$1
688        local checkpoint=$2
689        if [ -z $2 ] ; then
690            conf_unlock_wcopy
691            print_usage 1
692        else
693            conf_rm_checkpoint $module $checkpoint
694            conf_unlock_wcopy
695        fi
696    fi
697}
698
699function rollback {
700    if conf_system_locked?  && conf_wcopy_locked?
701    then
702        echo "The system is locked by confman[$SYSTEM_LOCK_PID] and your working copy is locked by confman[$WCOPY_LOCK_PID]" >&2
703        unset WCOPY_LOCK_PID
704        unset SYSTEM_LOCK_PID
705    elif conf_system_locked?
706    then
707        echo "The system is locked by confman[$SYSTEM_LOCK_PID]." >&2
708        unset SYSTEM_LOCK_PID
709    elif conf_wcopy_locked?
710    then
711        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
712        unset WCOPY_LOCK_PID
713    else
714        conf_lock_wcopy
715        conf_lock_system
716        local module=$1
717        local checkpoint=$2
718        local clock=$3
719        if [ -z $2 ] ; then
720            conf_unlock_wcopy
721            conf_unlock_system
722            print_usage 1
723        else
724            echo "Rolling $module back to $checkpoint $clock" >&2
725            conf_rollback $module $checkpoint $clock || conf_cleanExit
726            for layer in $LAYERS ; do
727                echo "Rolling on $layer..."
728                conf_rollout $layer || conf_cleanExit
729            done
730
731            for file in $SINGULARITIES ; do
732                conf_assemble_sing $file || conf_cleanExit
733            done
734            echo "Rollback succeeded." >&2
735            conf_unlock_wcopy
736            conf_unlock_system
737        fi
738    fi
739}
740
741function rmmod {
742    if conf_wcopy_locked?
743    then
744        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
745        unset WCOPY_LOCK_PID
746    else
747        conf_lock_wcopy
748        local module=$1
749        if [ -z $module ] ; then
750            conf_unlock_wcopy
751            print_usage 1
752        fi
753        conf_rmmod $module
754        conf_unlock_wcopy
755    fi
756}
757
758function rename {
759    if conf_wcopy_locked?
760    then
761        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
762        unset WCOPY_LOCK_PID
763    else
764        conf_lock_wcopy
765        local oldmod=$1
766        local newmod=$2
767        if [ -z $newmod ] ; then
768            conf_unlock_wcopy
769            print_usage 1
770        fi
771        if [ ! -d "${WORK_PATH}/${oldmod}" ] ; then
772            echo "${MYNAME}: Error: ${WORK_PATH}/${oldmod} doesn't exist" >&4
773            conf_cleanExit
774        fi
775        if [ -e "${WORK_PATH}/${newmod}" ] ; then
776            echo "${MYNAME}: Error: ${WORK_PATH}/${newmod}: file exists" >&4
777            conf_cleanExit
778        fi
779        conf_rename $oldmod $newmod
780        conf_unlock_wcopy
781    fi
782}
783
784function diff {
785        conf_diff $*
786}
787
788function log {
789        conf_log $*
790}
791
792function copy {
793    if conf_wcopy_locked?
794    then
795        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
796        unset WCOPY_LOCK_PID
797    else
798        conf_lock_wcopy
799        local src=$1
800        local dest=$2
801        if [ -z $2 ]
802        then
803            conf_unlock_wcopy
804            print_usage 1   
805        fi
806        conf_cp $src $dest
807        conf_unlock_wcopy
808    fi
809}
810
811function move {
812    if conf_wcopy_locked?
813    then
814        echo "Your working copy is locked by confman[$WCOPY_LOCK_PID]." >&2
815        unset WCOPY_LOCK_PID
816    else
817        conf_lock_wcopy
818        local src=$1
819        local dest=$2
820        if [ -z $2 ]
821        then
822            conf_unlock_wcopy
823            print_usage 1
824        fi
825        conf_mv $src $dest
826        conf_unlock_wcopy
827    fi
828}
829
830function lsattr {
831    if [ -z "$1" ] ; then
832        conf_lsattr *
833    else
834        conf_lsattr "$@"
835    fi
836}
837
838function chattr {
839    local attr="$1"
840    shift
841    local value="${1:-true}"
842    shift
843    if [ -z "$1" ] ; then print_usage 1 ; fi
844
845    conf_chattr "$attr" "$value" "$@"
846}
847
848function rmattr {
849    local attr="$1"
850    shift
851    if [ -z "$1" ] ; then print_usage 1 ; fi
852
853    conf_rmattr "$attr" "$@"
854}
855
856function state {
857    if conf_isclean ; then
858        echo "This host is clean."
859    else
860        echo "This host may be dirty. Consider running a 'commit' operation"
861    fi
862}
863
864function audit {
865    tarball=$(conf_fetch)
866    if ! [ -s $tarball ]
867    then
868        echo "Could not fetch the tarball." >&2
869        exit 1
870    fi
871
872    tmpcopy=$(mktemp -d -t confman)
873    tmproot=$(mktemp -d -t confman)
874
875    tar -xzf $tarball -C $tmpcopy
876    rm -rf $tarball
877   
878    for layer in $LAYERS
879    do
880        local module="${layer}"
881        local moduledir="$tmpcopy/$module"
882
883        for directory in `find $moduledir -type d -mindepth 1| grep -v "\.svn"`; do
884            local tmpdir=`echo $directory | sed "s:$moduledir::"`
885            tmpdir="$tmproot${tmpdir}"
886            local owner=`conf_get_prop ${directory} owner`
887            local group=`conf_get_prop ${directory} group`
888            local mode=`conf_get_prop ${directory} mode`
889            local opts="-d -o $owner -g $group -m $mode"
890            local cmd="sudo install $opts $tmpdir"
891            $cmd
892        done
893        for file in `find $moduledir -type f | grep -v "\.svn"` ; do
894            local tmpfile=`echo "$file" | sed "s:$moduledir::"`
895            local owner=`conf_get_prop ${file} owner`
896            local group=`conf_get_prop ${file} group`
897            local mode=`conf_get_prop ${file} mode`
898            local opts="-Sp -o $owner -g $group -m $mode"
899            local cmd="sudo install $opts $file $tmproot$tmpfile"
900            $cmd
901        done
902    done
903
904    for file in $SINGULARITIES
905    do
906        local livefile="$tmproot${file}"
907        local tmpfile=`mktemp -t confman` || exit 1
908        local owner group mode flag livepart msg
909        for layer in $LAYERS ; do
910            livepart="$tmproot${file}-${layer}"
911            myfile="$tmpcopy/${layer}/${file}-${layer}"
912            if [ -f $myfile -a -f $livepart ] ; then
913                    owner=`conf_get_prop ${myfile} owner`
914                    group=`conf_get_prop ${myfile} group`
915                    mode=`conf_get_prop ${myfile} mode`
916                    comment=`conf_get_prop      ${myfile} comment`
917                cat $livepart >> $tmpfile
918                sudo rm $livepart
919                flag=1
920            fi
921        done
922        if [ ! -z $flag ] ; then
923            local opts="-Sp -o $owner -g $group -m $mode"
924            local cmd="sudo install $opts $tmpfile $livefile"
925            $cmd
926        fi
927        rm -f $tmpfile
928    done
929    rm -rf $tmpcopy
930    sudo /usr/bin/diff -rPu / $tmproot | grep -v "^Only in"
931    sudo rm -rf $tmproot
932   
933}
934
935function tester {
936local asd="asddsa"
937    local output=`echo $asd | grep -v "qw"`
938echo $output
939}
940
941# Debug mode?
942while getopts "d" opt ; do
943        case $opt in
944                d)
945                DEBUG="true"
946                shift
947                ;;
948                *)
949                print_help 1
950                ;;
951        esac
952done
953
954
955# Dispatch the subcommand. This must happen last and in the global context.
956subcommand=$1
957shift
958case $subcommand in
959    help )                          print_help "$@" ; exit 0 ;;
960    setup|se* )                     setup "$@" ;;
961    status )                        status "$@" ;;
962    state )                         state ;;
963    create|cr* )                    create "$@" ;;
964    update|u* )                     update "$@" ;;
965    commit|com* )                   commit "$@" ;;
966    import|im* )                    import "$@" ;;
967    install|in* )                   inst "$@" ;;
968    remove|rem*|rm )                remove "$@" ;;
969    rev* )                          revert "$@" ;;
970    ren* )                          rename "$@" ;;
971    rmmod )                         rmmod "$@" ;;
972    mkdir|mkd* )                    newdir "$@" ;;
973    list|ls )                       list "$@" ;;
974    lsattr )                        lsattr "$@" ;;
975    chattr )                        chattr "$@" ;;
976    rmattr )                        rmattr "$@" ;;
977    move|mv )                       move "$@" ;;
978    copy|cp )                       copy "$@" ;;
979    diff )                          diff "$@" ;;
980    log )                           log "$@" ;;
981    chmod )                         chmode "$@" ;;
982    chown )                         chowner "$@" ;;
983    chcom )                         chcom "$@" ;;
984    chgrp )                         chgroup "$@" ;;
985    checklook|checklist|chls|chlk ) checklook "$@" ;;
986    checknew|chnw )                 checknew "$@" ;;
987    checkclear|chcl|chrm )          checkclear "$@" ;;
988    rollback|ro* )                  rollback "$@" ;;
989    audit )                         audit "$@" ;;
990    tester )                        tester "$@" ;;
991    * )                             print_usage 1 ;;
992esac
993
994exit
995
996# vim:ts=4
997
Note: See TracBrowser for help on using the repository browser.