| 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 | . /usr/local/rescomp/lib/confmancommon.sh |
|---|
| 15 | |
|---|
| 16 | # Set a default editor |
|---|
| 17 | if [ -z ${EDITOR} ] ; then |
|---|
| 18 | if which vim >/dev/null 2>&1 ; then |
|---|
| 19 | EDITOR="vim" |
|---|
| 20 | else |
|---|
| 21 | EDITOR="vi" |
|---|
| 22 | fi |
|---|
| 23 | fi |
|---|
| 24 | |
|---|
| 25 | # Let's make sure that only you can read your working copy |
|---|
| 26 | # Have to make this less restrictive due to NFS home dirs. |
|---|
| 27 | umask 022 |
|---|
| 28 | |
|---|
| 29 | # This function implements the setup subcommand. It is intended to be called |
|---|
| 30 | # with no arguments, and will error if that's not the case. |
|---|
| 31 | function 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 |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | function create { |
|---|
| 53 | local module=$1 |
|---|
| 54 | shift |
|---|
| 55 | if [ -z $* ] ; then |
|---|
| 56 | conf_create_module $module |
|---|
| 57 | else |
|---|
| 58 | print_usage 1 |
|---|
| 59 | fi |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | function update { |
|---|
| 63 | if [ -z $* ] ; then |
|---|
| 64 | conf_update_tree || conf_cleanexit |
|---|
| 65 | else |
|---|
| 66 | print_usage 1 |
|---|
| 67 | fi |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | function revert { |
|---|
| 71 | if [ -z $* ] ; then |
|---|
| 72 | print_usage 1 |
|---|
| 73 | else |
|---|
| 74 | conf_revert $* |
|---|
| 75 | fi |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | function 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 |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | # Short name intentional, don't want collision with real install. |
|---|
| 107 | function 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 |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | function 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 |
|---|
| 291 | |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | function remove { |
|---|
| 295 | if [ -z $1 ] ; then print_usage 1 ; fi |
|---|
| 296 | conf_rm_file $* |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | function 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 |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | function list { |
|---|
| 357 | local file item |
|---|
| 358 | if [ -z $1 ] ; then |
|---|
| 359 | file=`abspath .` |
|---|
| 360 | else |
|---|
| 361 | file=`abspath $1` |
|---|
| 362 | fi |
|---|
| 363 | echo -e "--------------------------------------------------------" |
|---|
| 364 | echo -e "Mode\tOwner\tGroup\tComment\t\tFilename" |
|---|
| 365 | echo -e "--------------------------------------------------------" |
|---|
| 366 | if [ -f "$file" ] ; then |
|---|
| 367 | conf_list $file |
|---|
| 368 | elif [ -d "$file" ] ; then |
|---|
| 369 | for item in `ls $file` ; do |
|---|
| 370 | conf_list "$file/$item" |
|---|
| 371 | done |
|---|
| 372 | fi |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | function status { |
|---|
| 376 | conf_status $* |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | function 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 |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | function 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 |
|---|
| 423 | } |
|---|
| 424 | |
|---|
| 425 | function 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 |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | function chcom { |
|---|
| 449 | local comment="$1" |
|---|
| 450 | local file=$2 |
|---|
| 451 | conf_set_prop $file comment "$comment" |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 454 | function checklook { |
|---|
| 455 | local module=$1 |
|---|
| 456 | local chkdir=${WORK_PATH}/${REPO_CHECKPTS}/${module} |
|---|
| 457 | if [ -z $1 ] ; then |
|---|
| 458 | print_usage 1 |
|---|
| 459 | elif [ -d $chkdir ] ; then |
|---|
| 460 | ls $chkdir |
|---|
| 461 | else |
|---|
| 462 | echo "There are no checkpoints for ${module}." |
|---|
| 463 | fi |
|---|
| 464 | } |
|---|
| 465 | |
|---|
| 466 | function 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 |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | function 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 |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | function 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 |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | function rmmod { |
|---|
| 508 | local module=$1 |
|---|
| 509 | if [ -z $module ] ; then |
|---|
| 510 | print_usage 1 |
|---|
| 511 | fi |
|---|
| 512 | conf_rmmod $module |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | function 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 |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | function diff { |
|---|
| 533 | conf_diff $* |
|---|
| 534 | } |
|---|
| 535 | |
|---|
| 536 | function log { |
|---|
| 537 | conf_log $* |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | function 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 |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | function 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 |
|---|
| 556 | } |
|---|
| 557 | |
|---|
| 558 | function lsattr { |
|---|
| 559 | if [ -z "$1" ] ; then |
|---|
| 560 | conf_lsattr * |
|---|
| 561 | else |
|---|
| 562 | conf_lsattr "$@" |
|---|
| 563 | fi |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | function chattr { |
|---|
| 567 | local attr="$1" |
|---|
| 568 | shift |
|---|
| 569 | local value="${1:-true}" |
|---|
| 570 | shift |
|---|
| 571 | if [ -z "$1" ] ; then print_usage 1 ; fi |
|---|
| 572 | |
|---|
| 573 | conf_chattr "$attr" "$value" "$@" |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | function rmattr { |
|---|
| 577 | local attr="$1" |
|---|
| 578 | shift |
|---|
| 579 | if [ -z "$1" ] ; then print_usage 1 ; fi |
|---|
| 580 | |
|---|
| 581 | conf_rmattr "$attr" "$@" |
|---|
| 582 | } |
|---|
| 583 | |
|---|
| 584 | function state { |
|---|
| 585 | if conf_isclean ; then |
|---|
| 586 | echo "This host is clean." |
|---|
| 587 | else |
|---|
| 588 | echo "This host may be dirty. Consider running a 'commit' operation" |
|---|
| 589 | fi |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | # Dubug mode? |
|---|
| 593 | while getopts "d" opt ; do |
|---|
| 594 | case $opt in |
|---|
| 595 | d) |
|---|
| 596 | DEBUG="true" |
|---|
| 597 | shift |
|---|
| 598 | ;; |
|---|
| 599 | *) |
|---|
| 600 | print_help 1 |
|---|
| 601 | ;; |
|---|
| 602 | esac |
|---|
| 603 | done |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | # Dispatch the subcommand. This must happen last and in the global context. |
|---|
| 607 | subcommand=$1 |
|---|
| 608 | shift |
|---|
| 609 | case $subcommand in |
|---|
| 610 | help ) print_help "$@" ; exit 0 ;; |
|---|
| 611 | setup|se* ) setup "$@" ;; |
|---|
| 612 | status ) status "$@" ;; |
|---|
| 613 | state ) state ;; |
|---|
| 614 | create|cr* ) create "$@" ;; |
|---|
| 615 | update|u* ) update "$@" ;; |
|---|
| 616 | commit|com* ) commit "$@" ;; |
|---|
| 617 | import|im* ) import "$@" ;; |
|---|
| 618 | install|in* ) inst "$@" ;; |
|---|
| 619 | remove|rem*|rm ) remove "$@" ;; |
|---|
| 620 | rev* ) revert "$@" ;; |
|---|
| 621 | ren* ) rename "$@" ;; |
|---|
| 622 | rmmod ) rmmod "$@" ;; |
|---|
| 623 | mkdir|mkd* ) newdir "$@" ;; |
|---|
| 624 | list|ls ) list "$@" ;; |
|---|
| 625 | lsattr ) lsattr "$@" ;; |
|---|
| 626 | chattr ) chattr "$@" ;; |
|---|
| 627 | rmattr ) rmattr "$@" ;; |
|---|
| 628 | move|mv ) move "$@" ;; |
|---|
| 629 | copy|cp ) copy "$@" ;; |
|---|
| 630 | diff ) diff "$@" ;; |
|---|
| 631 | log ) log "$@" ;; |
|---|
| 632 | chmod ) chmode "$@" ;; |
|---|
| 633 | chown ) chowner "$@" ;; |
|---|
| 634 | chcom ) chcom "$@" ;; |
|---|
| 635 | chgrp ) chgroup "$@" ;; |
|---|
| 636 | checklook|checklist|chls|chlk ) checklook "$@" ;; |
|---|
| 637 | checknew|chnw ) checknew "$@" ;; |
|---|
| 638 | checkclear|chcl|chrm ) checkclear "$@" ;; |
|---|
| 639 | rollback|ro* ) rollback "$@" ;; |
|---|
| 640 | * ) print_usage 1 ;; |
|---|
| 641 | esac |
|---|
| 642 | |
|---|
| 643 | exit |
|---|
| 644 | |
|---|
| 645 | # vim:ts=4 |
|---|
| 646 | |
|---|