Changeset 33


Ignore:
Timestamp:
03/28/2006 21:12:09 (6 years ago)
Author:
ccowart
Message:

Sensible defaults --ccowart

Location:
confman
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • confman/confman

    r32 r33  
    2828else 
    2929        echo "Error: Couldn't source the confman shell library" >&2 
     30        exit 1 
     31fi 
     32 
     33# And we read in the layers that make this host 
     34if [ -f $RECIPE_PATH ] ; then 
     35        LAYERS=`cat $RECIPE_PATH` 
     36else 
     37        echo "Error: Couldn't read the host's recipe!" >&2 
    3038        exit 1 
    3139fi 
     
    5664  $MYNAME chgrp module [ file | directory ] group 
    5765  $MYNAME chmod module [ file | directory ] mode 
     66  $MYNAME chcom module [ file | directory ] comment-character 
    5867  $MYNAME checklook module 
    5968  $MYNAME checknew module name 
     
    240249The chmod subcommand takes a directory and an mode relative to the system 
    241250root and changes ownership. 
     251 
     252EOF 
     253;; 
     254          chcom ) 
     255cat <<EOF 
     256$MYNAME provides a command-line interface to Rescomp's server configuration 
     257management system. 
     258 
     259Usage: 
     260  $MYNAME chcom module [ file | directory ] comment-character 
     261 
     262The chcom subcommand takes a file or directory as an argument and changes the 
     263comment string associated with it. This will typically only be useful when 
     264confman has guessed the comment character of your file incorrectly. 
    242265 
    243266EOF 
     
    379402 
    380403        if [ -f $file ] ; then 
    381                 echo "The file $file exists in your live filesystem."  
    382                 echo "Would you like to use that one? [ Y/n ]" 
    383                 while read response ; do 
    384                         if [ -z $reponse ] ; then usefile=1 ; break ; fi 
    385                         case $response in 
    386                                 y|Y|yes ) 
    387                                         usefile=1 
    388                                         break 
    389                                         ;; 
    390                                 n|N|no ) 
    391                                         unset usefile 
    392                                         break 
    393                                         ;; 
    394                                 * ) 
    395                                         echo "Please answer yes or no." 
    396                                         continue 
    397                                         ;; 
    398                         esac 
    399                 done 
     404                usefile=1 
    400405        fi 
    401406 
    402407        if [ ! -z $usefile ] ; then 
    403408                eval `stat -f "mode=%Mp%Lp owner=%Su group=%Sg" $file` 
    404         fi 
    405  
    406         # Prompt for file owner 
    407         echo "Who should be the file's owner? [ $owner ]" 
    408         read response 
    409         if [ ! -z $response ] ; then 
    410                 owner=$response 
    411         fi 
    412  
    413         # And file's group 
    414         echo "Who should be the file's group? [ $group ]" 
    415         read response 
    416         if [ ! -z $response ] ; then 
    417                 group=$response 
    418         fi 
    419  
    420         # now, the permissions 
    421         echo "What should the file's permissions be? [ $mode ]" 
    422         read response 
    423         if [ ! -z $response ] ; then 
    424                 mode=$response 
    425         fi 
    426  
    427         # now, the permissions 
    428         echo "What string starts comment lines? [ $comment ]" 
    429         read response 
    430         if [ ! -z $response ] ; then 
    431                 comment=$response 
     409                # Let's make our best guess on the comment character: 
     410                local tmpfile=`mktemp -t confman` 
     411                local biggestcount=0 
     412                local count 
     413 
     414                # Put all non-alphanumerics into a file 
     415                awk '{print $1}' $file | egrep -o "^[^-_A-Za-z0-9]" > $tmpfile 
     416                for char in `cat $file | sort | uniq` ; do 
     417                        count=`egrep -o "\\$char" $tmpfile | wc -l` 
     418                        if [ $count -gt $biggestcount ] ; then 
     419                                biggestcount=$count 
     420                                comment="$char" 
     421                        fi 
     422                done 
     423                rm $tmpfile 
     424 
     425                # Convert mode string to base 10: 
     426                mode=`echo "obase=10;ibase=8;$mode" | bc` 
     427                # And use a bitmask to subtract off all write-access 
     428                # 3949d = 7555o 
     429                mode=$(($mode & 3949)) 
     430                # And back to an octet: 
     431                mode=`printf '%04o\n' $mode` 
     432        else 
     433                # Prompt for file owner 
     434                echo "Who should be the file's owner? [ $owner ]" 
     435                read response 
     436                if [ ! -z $response ] ; then 
     437                        owner=$response 
     438                fi 
     439 
     440                # And file's group 
     441                echo "Who should be the file's group? [ $group ]" 
     442                read response 
     443                if [ ! -z $response ] ; then 
     444                        group=$response 
     445                fi 
     446 
     447                # now, the permissions 
     448                echo "What should the file's permissions be? [ $mode ]" 
     449                read response 
     450                if [ ! -z $response ] ; then 
     451                        mode=$response 
     452                fi 
     453 
     454                # now, the comment character 
     455                echo "What string starts comment lines? [ $comment ]" 
     456                read response 
     457                if [ ! -z $response ] ; then 
     458                        comment=$response 
     459                fi 
    432460        fi 
    433461 
     
    472500        local owner=$DEFAULT_OWNER 
    473501        local group=$DEFAULT_GROUP 
     502        local comment="dir" 
    474503        if [ -z $2 ] ; then 
    475504                print_usage 1 
     
    480509        echo 
    481510 
    482         # Prompt for file owner 
    483         echo "Who should be the directory's owner? [ $owner ]" 
    484         read response 
    485         if [ ! -z $response ] ; then 
    486                 owner=$response 
    487         fi 
    488  
    489         # And file's group 
    490         echo "Who should be the directory's group? [ $group ]" 
    491         read response 
    492         if [ ! -z $response ] ; then 
    493                 group=$response 
    494         fi 
    495  
    496         # now, the permissions 
    497         echo "What should the directory's permissions be? [ $mode ]" 
    498         read response 
    499         if [ ! -z $response ] ; then 
    500                 mode=$response 
     511        if [ -d $dir ] ; then 
     512                eval `stat -f "mode=%Mp%Lp owner=%Su group=%Sg" $dir` 
     513 
     514                # Convert mode string to base 10: 
     515                mode=`echo "obase=10;ibase=8;$mode" | bc` 
     516                # And use a bitmask to subtract off all write-access 
     517                # 3949d = 7555o 
     518                mode=$(($mode & 3949)) 
     519                # And back to an octet: 
     520                mode=`printf '%04o\n' $mode` 
     521        else 
     522                # Prompt for file owner 
     523                echo "Who should be the directory's owner? [ $owner ]" 
     524                read response 
     525                if [ ! -z $response ] ; then 
     526                        owner=$response 
     527                fi 
     528 
     529                # And file's group 
     530                echo "Who should be the directory's group? [ $group ]" 
     531                read response 
     532                if [ ! -z $response ] ; then 
     533                        group=$response 
     534                fi 
     535 
     536                # now, the permissions 
     537                echo "What should the directory's permissions be? [ $mode ]" 
     538                read response 
     539                if [ ! -z $response ] ; then 
     540                        mode=$response 
     541                fi 
    501542        fi 
    502543 
    503544        # Time to create the directory. 
     545        echo "Making $dir in $module with ${owner}:${group}, $mode" 
    504546        conf_mkdir $module $dir $owner $group $mode  
    505547} 
     
    512554                file=`abspath $1` 
    513555        fi 
    514         echo $file >&2 
    515556        echo -e "--------------------------------------------------------" 
    516557        echo -e "Mode\tOwner\tGroup\tComment\t\tFilename" 
     
    544585        local mode=$3 
    545586        conf_set_prop $module $file mode $mode 
     587} 
     588 
     589function chcom { 
     590        local module=$1 
     591        local file=$2 
     592        local comment="$3" 
     593        conf_set_prop $module $file comment "$comment" 
    546594} 
    547595 
     
    669717                chowner $* 
    670718                ;; 
     719        chcom ) 
     720                chcom $* 
     721                ;; 
    671722        chgrp ) 
    672723                chgroup $* 
  • confman/confman.conf

    r30 r33  
    3131# The path to our current host's recipe file 
    3232# RECIPE_PATH="/usr/local/rescomp/etc/recipe" 
    33 # RECIPE_PATH="/usr/local/rescomp/etc/recipe" 
    34 LAYERS="core kermit" 
     33RECIPE_PATH="/usr/local/rescomp/etc/recipe" 
    3534 
    3635# The list of singularities on this host 
Note: See TracChangeset for help on using the changeset viewer.