Changeset 75


Ignore:
Timestamp:
04/14/2006 18:15:57 (6 years ago)
Author:
ccowart
Message:

Separated out the command-line help. Added some sanity checks to import.

Location:
confman
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • confman/Makefile

    r72 r75  
    1111        install -Sp -o root -g staff -m 0444 confmanlib.sh \ 
    1212                $(PREFIX)/lib/confmanlib.sh 
     13        install -Sp -o root -g staff -m 0444 confmandoc.sh \ 
     14                $(PREFIX)/lib/confmandoc.sh 
    1315        install -Sp -o root -g staff -m 0444 bash_completions \ 
    1416                $(PREFIX)/etc/env.d/confman_completions 
  • confman/confman

    r72 r75  
    4040fi 
    4141 
     42# And the documentation library 
     43if [ -f $REPO_DOCS ] ; then 
     44        . $REPO_DOCS 
     45else 
     46        echo "Error: Couldn't source the confman shell library" >&2 
     47        exit 1 
     48fi 
     49 
    4250# And we read in the layers that make this host 
    4351if [ -f $RECIPE_PATH ] ; then 
     
    5058# Set a default editor 
    5159if [ -z ${EDITOR} ] ; then 
    52         EDITOR="vi" 
     60        if `which vim 2>/dev/null` ; then 
     61                EDITOR="vim" 
     62        else 
     63                EDITOR="vi" 
     64        fi 
    5365fi 
    5466 
     
    5971# And we'll set a trap: 
    6072trap "cleanexit" SIGINT SIGTERM 
    61  
    62 function print_usage { 
    63 cat <<EOF 
    64 $MYNAME provides a command-line interface to Rescomp's server 
    65 configuration management system. 
    66  
    67 Usage: 
    68   $MYNAME [ help | -h | --help ] [ command ] 
    69   $MYNAME setup 
    70   $MYNAME update 
    71   $MYNAME commit 
    72   $MYNAME diff [ working_copy ] 
    73   $MYNAME log [ working_copy ] 
    74   $MYNAME create module 
    75   $MYNAME rmmod module 
    76   $MYNAME import module livefile 
    77   $MYNAME rm workingfile 
    78   $MYNAME cp src_working_copy dest_working_copy 
    79   $MYNAME mv src_working_copy dest_working_copy 
    80   $MYNAME mkdir workingdirectory 
    81   $MYNAME ls [ workingfile | workingdirectory ] 
    82   $MYNAME chown owner [ workingfile | workingdirectory ]  
    83   $MYNAME chgrp group [ workingfile | workingdirectory ]  
    84   $MYNAME chmod mode  [ workingfile | workingdirectory ]  
    85   $MYNAME chcom comment-character [ workingfile | workingdirectory ]  
    86   $MYNAME checklook module 
    87   $MYNAME checknew module name 
    88   $MYNAME checkclear module name 
    89   $MYNAME rollback module [ checkpoint | YYYYMMDD [HHMM] ] 
    90  
    91 For specific information on a particular $MYNAME subcommand, please run 
    92   $MYNAME help subcommand 
    93  
    94 eg: $MYNAME help rollback 
    95  
    96 EOF 
    97  
    98 exit $1 
    99 } 
    100  
    101 function print_help { 
    102   case $1 in 
    103           se* ) 
    104 cat <<EOF 
    105 $MYNAME provides a command-line interface to Rescomp's server 
    106 configuration management system. 
    107  
    108 Usage: 
    109   $MYNAME setup 
    110  
    111 The setup command is intended to be run the first time you use $MYNAME. 
    112 It will generate your working copy. setup takes no additional arguments. 
    113  
    114 EOF 
    115 ;; 
    116           cr* ) 
    117 cat <<EOF 
    118 $MYNAME provides a command-line interface to Rescomp's server 
    119 configuration management system. 
    120  
    121 Usage: 
    122   $MYNAME create module 
    123  
    124 The create command will cause a new module, named module, to appear as a 
    125 top-level-directory in your working copy. This change will also be made to 
    126 the repositry at the same time.  
    127  
    128 EOF 
    129 ;; 
    130           rmm* ) 
    131 cat <<EOF 
    132 $MYNAME provides a command-line interface to Rescomp's server 
    133 configuration management system. 
    134  
    135 Usage: 
    136   $MYNAME rmmod module 
    137 This command will delete the specified module from your working copy. Use with 
    138 care. 
    139 EOF 
    140 ;; 
    141           u* ) 
    142 cat <<EOF 
    143 $MYNAME provides a command-line interface to Rescomp's server 
    144 configuration management system. 
    145  
    146 Usage: 
    147   $MYNAME update 
    148  
    149 The update command will update your working copy of all the modules 
    150 appearing in the current host's recipe file. This command does not alter 
    151 the repository. 
    152  
    153 EOF 
    154 ;; 
    155           d* ) 
    156 cat <<EOF 
    157 $MYNAME provides a command-line interface to Rescomp's server 
    158 configuration management system. 
    159  
    160 Usage: 
    161   $MYNAME diff [ working_copy ] 
    162  
    163 Look at the changes you've made to your working copy of a file or directory. 
    164 EOF 
    165 ;; 
    166           lo* ) 
    167 cat <<EOF 
    168 $MYNAME provides a command-line interface to Rescomp's server 
    169 configuration management system. 
    170  
    171 Usage: 
    172   $MYNAME log [ working_copy ] 
    173  
    174 Look at the log entries for the file or directory specified by working_copy. 
    175 EOF 
    176 ;; 
    177           st* ) 
    178 cat <<EOF 
    179 $MYNAME provides a command-line interface to Rescomp's server 
    180 configuration management system. 
    181  
    182 Usage: 
    183   $MYNAME status [ working_copy ] 
    184  
    185 Look at the status entries for the file or directory specified by working_copy. 
    186 EOF 
    187 ;; 
    188           cp ) 
    189 cat <<EOF 
    190 $MYNAME provides a command-line interface to Rescomp's server 
    191 configuration management system. 
    192  
    193 Usage: 
    194   $MYNAME cp src_working_copy dest_working_copy 
    195  
    196 Copy source to destination. Arguments must be working copies. 
    197 EOF 
    198 ;; 
    199           mv ) 
    200 cat <<EOF 
    201 $MYNAME provides a command-line interface to Rescomp's server 
    202 configuration management system. 
    203  
    204 Usage: 
    205   $MYNAME mv src_working_copy dest_working_copy 
    206  
    207 Move source to destination. Arguments must be working copies. 
    208 EOF 
    209 ;; 
    210           co* ) 
    211 cat <<EOF 
    212 $MYNAME provides a command-line interface to Rescomp's server 
    213 configuration management system. 
    214  
    215 Usage: 
    216   $MYNAME commit 
    217  
    218 The commit command causes your changes to take effect. This means that 
    219 first, your working copy of all of the modules in the current host's  
    220 recipe will be committed to the repository. This happens after we've run 
    221 a $MYNAME update to prevent out-of-date conflicts. If there are any  
    222 conflicts that require human intervention, the command will fail and exit  
    223 non-zero.  
    224  
    225 Once $MYNAME is satisfied that all of your changes have been propogated to 
    226 the repository, we will roll-out your working copy to the live filesystem. 
    227 Every module appearing in the host's recipe file will be rolled out IN THE 
    228 ORDER OF APPEARANCE. 
    229  
    230 EOF 
    231 ;; 
    232           i* ) 
    233 cat <<EOF 
    234 $MYNAME provides a command-line interface to Rescomp's server 
    235 configuration management system. 
    236  
    237 Usage: 
    238   $MYNAME import module livefile 
    239  
    240 The import subcommand adds the specified file to your working copy of the 
    241 repository.  
    242  
    243 EOF 
    244 ;; 
    245           rm ) 
    246 cat <<EOF 
    247 $MYNAME provides a command-line interface to Rescomp's server configuration 
    248 management system. 
    249  
    250 Usage: 
    251   $MYNAME rm file 
    252  
    253 The remove subcommand removes a file from version control It will NOT remove  
    254 the file from the live filesystem.  
    255  
    256 EOF 
    257 ;; 
    258           mk* ) 
    259 cat <<EOF 
    260 $MYNAME provides a command-line interface to Rescomp's server configuration 
    261 management system. 
    262  
    263 Usage: 
    264   $MYNAME mkdir directory  
    265  
    266 This command will create a new version-controlled directory in your working 
    267 copy.  Parent directories do not have to exist; they will be created  
    268 automagically. This command only affects your working copy. It does not commit  
    269 the change. 
    270  
    271 EOF 
    272 ;; 
    273           ls ) 
    274 cat<<EOF 
    275 $MYNAME provides a command-line interface to Rescomp's server configuration 
    276 management system. 
    277  
    278 Usage: 
    279   $MYNAME ls [ file | directory ] 
    280  
    281 The ls subcommand lists out the contents, in modified long form, of the 
    282 current working directory. If a file or directory is specified, it will list 
    283 that instead. 
    284  
    285 EOF 
    286 ;; 
    287           cho* ) 
    288 cat <<EOF 
    289 $MYNAME provides a command-line interface to Rescomp's server configuration 
    290 management system. 
    291  
    292 Usage: 
    293   $MYNAME chown [ -R ] owner [ file | directory ]  
    294  
    295 The chown command works like it's unix equivalent. It does not support 
    296 user:group notation. The only option it will take is -R for recursive. 
    297  
    298 EOF 
    299 ;; 
    300           chg* ) 
    301 cat <<EOF 
    302 $MYNAME provides a command-line interface to Rescomp's server configuration 
    303 management system. 
    304  
    305 Usage: 
    306   $MYNAME chgrp group [ file | directory ]  
    307  
    308 The chgrp command works like it's unix equivalent. The only option it will take 
    309 is -R for recursive. 
    310  
    311 EOF 
    312 ;; 
    313           chm* ) 
    314 cat <<EOF 
    315 $MYNAME provides a command-line interface to Rescomp's server configuration 
    316 management system. 
    317  
    318 Usage: 
    319   $MYNAME chmod mode [ file | directory ]  
    320  
    321 The chmod command works like it's unix equivalent. Note that it will only 
    322 accept octets as permissions -- it will not interpret symbolic permissions 
    323 correctly. The only option it will take is -R for recursive. 
    324  
    325 EOF 
    326 ;; 
    327           chc* ) 
    328 cat <<EOF 
    329 $MYNAME provides a command-line interface to Rescomp's server configuration 
    330 management system. 
    331  
    332 Usage: 
    333   $MYNAME chcom comment-character [ file | directory ]  
    334  
    335 The chcom subcommand takes a file or directory as an argument and changes the 
    336 comment string associated with it. This will typically only be useful when 
    337 confman has guessed the comment character of your file incorrectly. 
    338  
    339 EOF 
    340 ;; 
    341           checkl* ) 
    342 cat <<EOF 
    343 $MYNAME provides a command-line interface to Rescomp's server 
    344 configuration management system. 
    345  
    346 Usage: 
    347   $MYNAME checklook module 
    348  
    349 The checklook command peeks into the checkpoints for the specified module 
    350 and gives you a listing of current checkpoints with some other cool info. 
    351 This command does not alter the repository. 
    352  
    353 EOF 
    354 ;; 
    355           checkn* ) 
    356 cat <<EOF 
    357 $MYNAME provides a command-line interface to Rescomp's server 
    358 configuration management system. 
    359  
    360 Usage: 
    361   $MYNAME checknew module name 
    362  
    363 The newcheck command creates a named checkpoint for the specified module. 
    364 This change is committed to the repository immediately. 
    365  
    366 EOF 
    367 ;; 
    368           checkc* ) 
    369 cat <<EOF 
    370 $MYNAME provides a command-line interface to Rescomp's server 
    371 configuration management system. 
    372  
    373 Usage: 
    374   $MYNAME checkclear module name 
    375  
    376 The rmcheck command clears a named checkpoint from the specified module.  
    377 This change is committed to the repository immediately. 
    378  
    379 EOF 
    380 ;; 
    381           ro* ) 
    382 cat <<EOF 
    383 $MYNAME provides a command-line interface to Rescomp's server 
    384 configuration management system. 
    385  
    386 Usage: 
    387   $MYNAME rollback module [ checkpoint | YYYYMMDD [HHMM] ] 
    388  
    389 The rollback command first rolls your working copy of module back to the 
    390 named checkpoint. You can optionally roll-back to a specific point in time 
    391 using a date (and optionally time) as specified in the usage statement.  
    392 This change is immediately committed to the repository. 
    393  
    394 After the rollback is complete, we perform the equivalent of a: 
    395   $MYNAME commit 
    396  
    397 EOF 
    398 ;; 
    399           * ) 
    400 print_usage 1 
    401 ;; 
    402 esac 
    403 exit $2 
    404 } 
    40573 
    40674 
     
    472140 
    473141function import { 
     142         
     143        # Check for a force 
     144        local item OPTIND 
     145        force=0 
     146        while getopts "f" opt ; do 
     147                case $opt in  
     148                        f) 
     149                        force=1 
     150                        shift 
     151                        ;; 
     152                        *) 
     153                        print_help 1 
     154                        ;; 
     155                esac 
     156        done 
     157 
    474158        local module=$1 
    475         local response usefile suffix file 
     159        local response usefile suffix file layer 
    476160        local mode=$DEFAULT_MODE_FILE 
    477161        local owner=$DEFAULT_OWNER 
     
    508192                     "copy of $module." 
    509193                cleanexit 
     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 "$MYNAME: Error: $file already exists in" \ 
     200                                     "the ${layer} module." >&2 
     201                                echo "Did you mean -f ?" >&2 
     202                                cleanexit 
     203                        fi 
     204                done 
    510205        fi 
    511206 
Note: See TracChangeset for help on using the changeset viewer.