From c2c7d34973a97c3efb76cf91cce81ffffe131985 Mon Sep 17 00:00:00 2001 From: Mike Burns Date: Fri, 28 Mar 2014 15:12:03 +0100 Subject: Discover a POSIX shell for Solaris Under Solaris, use ksh instead of `/bin/sh`. This uses `$SHELL` as a POSIX shell, coupled with a `configure` check that sets it correctly. Note that the POSIX shell might end up being bash, so this actually introduces more fragmentation than it reduces. Taken from https://github.com/freedreno/mesa/blob/master/configure.ac --- bin/lsrc | 328 ------------------------------------------------------------ bin/lsrc.in | 328 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/mkrc | 88 ---------------- bin/mkrc.in | 88 ++++++++++++++++ bin/rcdn | 107 -------------------- bin/rcdn.in | 107 ++++++++++++++++++++ bin/rcup | 188 ---------------------------------- bin/rcup.in | 188 ++++++++++++++++++++++++++++++++++ 8 files changed, 711 insertions(+), 711 deletions(-) delete mode 100755 bin/lsrc create mode 100755 bin/lsrc.in delete mode 100755 bin/mkrc create mode 100755 bin/mkrc.in delete mode 100755 bin/rcdn create mode 100755 bin/rcdn.in delete mode 100755 bin/rcup create mode 100755 bin/rcup.in (limited to 'bin') diff --git a/bin/lsrc b/bin/lsrc deleted file mode 100755 index 9055eec..0000000 --- a/bin/lsrc +++ /dev/null @@ -1,328 +0,0 @@ -#!/bin/sh - -: ${RCM_LIB:=$(dirname "$0")/../share/rcm} -. "$RCM_LIB/rcm.sh" - -pushdir() { - DIR_STACK="$DIR_STACK:$PWD/$1" - $DEBUG "cd'ing to $1 from $PWD with stack $DIR_STACK" - cd "$1" -} - -popdir() { - current="$(echo "$DIR_STACK" | sed -e 's/.*://g')" - prior="$(echo "$DIR_STACK" | sed -e "s|:$current$||" | sed -e 's/.*://g')" - DIR_STACK="$(echo "$DIR_STACK" | sed -e 's/:[^:]*$//')" - $DEBUG "cd'ing to $prior from $PWD with stack $DIR_STACK" - cd "$prior" -} - -build_path() { - local dest="$1" - local file="$2" - local dotted=$3 - - if [ $dotted -eq 1 ]; then - echo "$dest/$file" - else - echo "$dest/.$file" - fi -} - -file_join() { - local result= - - for file; do - if [ "x$file" != "x." ]; then - if [ "x$result" = "x" ]; then - result="$file" - else - result="$result/$file" - fi - fi - done - - echo "$result" -} - -show_dir() { - local dir="$1" - local dest_dir="$2" - local dotfiles_dir="$3" - local dotfiles_subdir="$4" - local dotted=$5 - local exclude_file_globs="$6" - local include_file_globs="$7" - local symlink_dirs_file_globs="$8" - local dest_path="$(build_path "$dest_dir" "$dir" $dotted)" - - $DEBUG "show_dir $1 $2 $3 $4 $5 $6 $7 $8" - - $VERBOSE "recurring on $dest_path" - - pushdir "$dir" - for f in *; do - $DEBUG "handling the file $f" - next_dir="$(file_join "$dotfiles_subdir" "$dir")" - handle_file "$f" "$dest_path" "$dotfiles_dir" "$next_dir" 1 "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" - done - popdir -} - -sigil_for() { - local file="$1" - local symlink_dirs_file_globs="$2" - local copy_always=0 - local symlink_dirs=0 - - for copy_file in $COPY_ALWAYS; do - $DEBUG "copy_file: $copy_file" - $DEBUG "file: $file" - - case "$file" in - $copy_file) - copy_always=1 - break - ;; - esac - done - - if [ -n "$symlink_dirs_file_globs" ]; then - symlink_dirs=1 - fi - - if [ $copy_always -eq 1 ]; then - echo 'X' - elif [ $symlink_dirs -eq 1 ]; then - echo '$' - else - echo '@' - fi -} - -show_file() { - local file="$1" - local dest_dir="$2" - local dotfiles_dir="$3" - local dotfiles_subdir="$4" - local dotted=$5 - local symlink_dirs_file_globs="$6" - local dest_file="$(build_path "$dest_dir" "$file" $dotted)" - - if echo "$DEST_STACK" | grep -vq ":$dest_file"; then - DEST_STACK="$DEST_STACK:$dest_file" - - src_file="$(file_join "$dotfiles_subdir" "$file")" - abs_src_file="$(file_join "$dotfiles_dir" "$src_file")" - output="$dest_file:$abs_src_file" - - if [ $SHOW_SIGILS -eq 1 ]; then - sigil="$(sigil_for "$src_file" "$symlink_dirs_file_globs")" - output="$output:$sigil" - fi - - $PRINT "$output" - fi -} - -handle_file() { - local file="$1" - local dest_dir="$2" - local dotfiles_dir="$3" - local dotfiles_subdir="$4" - local dotted=$5 - local exclude_file_globs="$6" - local include_file_globs="$7" - local symlink_dirs_file_globs="$8" - - $DEBUG "handle_file $1 $2 $3 $4 $5 $6 $7 $8" - - if [ ! -e "$file" ]; then - $VERBOSE "skipping non-existent file $file" - elif is_excluded "$file" "$exclude_file_globs" "$include_file_globs"; then - $VERBOSE "skipping excluded file $file" - elif [ -d "$file" ] && is_excluded $file "$symlink_dirs_file_globs"; then - show_file "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted "$symlink_dirs_file_globs" - elif [ -d "$file" ]; then - show_dir "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" - else - show_file "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted - fi -} - -is_metafile() { - host_portion="$(echo "$1" | sed -e 's/host-.*/host-/')" - tag_portion="$(echo "$1" | sed -e 's/tag-.*/tag-/')" - - [ "x$host_portion" = 'xhost-' -o "x$tag_portion" = 'xtag-' -o "x$1" = "xhooks" ] -} - -dotfiles_dir_excludes() { - local dotfiles_dir="$1" - local excludes="$2" - - $DEBUG "dotfiles_dir_excludes $dotfiles_dir" - $DEBUG " with excludes: $excludes" - - for exclude in $excludes; do - if echo "$exclude" | grep -q ':'; then - dotfiles_dir_pat="$(echo "$exclude" | sed 's/:.*//')" - file_glob="$(echo "$exclude" | sed 's/.*://')" - - if [ "x$dotfiles_dir_pat" != "x*" ] && is_relative "$dotfiles_dir_pat"; then - dotfiles_dir_pat="$PWD/$dotfiles_dir_pat" - fi - - if [ "x$dotfiles_dir_pat" = "x*" -o "x$dotfiles_dir_pat" = "x$dotfiles_dir" ]; then - echo "$file_glob" - fi - else - echo "$exclude" - fi - done -} - -is_excluded() { - local file="$1" - local exclude_file_globs="$2" - local include_file_globs="$3" - - $DEBUG "is_excluded $file $exclude_file_globs $include_file_globs" - - for exclude_file_glob in $exclude_file_globs; do - $DEBUG "file: $file" - $DEBUG "exclude_file_glob: $exclude_file_glob" - - case "$file" in - $exclude_file_glob) - for include_file_glob in $include_file_globs; do - case "$file" in - $include_file_glob) return 1;; - esac - done - - return 0 - ;; - esac - done - - return 1 -} - -show_help() { - local exit_code=${1:-0} - - $PRINT "Usage: lsrc [-FVqvh] [-I EXCL_PAT] [-x EXCL_PAT] [-N EXCL_PAT ] [-t TAG] [-d DOT_DIR]" - $PRINT "see lsrc(1) and rcm(5) for more details" - - exit $exit_code -} - -handle_command_line() { - local arg_tags= - local verbosity=0 - local version=0 - local show_sigils=0 - local dotfiles_dirs= - local excludes= - local includes= - local symlink_dirs= - - while getopts FVqvhI:x:S:t:d: opt; do - case "$opt" in - F) show_sigils=1;; - h) show_help ;; - I) includes="$includes $OPTARG";; - t) arg_tags="$arg_tags $OPTARG";; - v) verbosity=$(($verbosity + 1));; - q) verbosity=$(($verbosity - 1));; - d) dotfiles_dirs="$dotfiles_dirs $OPTARG";; - V) version=1;; - x) excludes="$excludes $OPTARG";; - S) symlink_dirs="$symlink_dirs $OPTARG";; - esac - done - shift $(($OPTIND-1)) - - handle_common_flags lsrc $version $verbosity - SHOW_SIGILS=$show_sigils - TAGS="${arg_tags:-$TAGS}" - DOTFILES_DIRS="${dotfiles_dirs:-$DOTFILES_DIRS}" - EXCLUDES="${excludes:-$EXCLUDES}" - INCLUDES="${includes:-$INCLUDES}" - SYMLINK_DIRS="${symlink_dirs:-$SYMLINK_DIRS}" - FILES="$@" - - $DEBUG "TAGS: $TAGS" - $DEBUG "DOTFILES_DIRS: $DOTFILES_DIRS" -} - -DEST_STACK= - -handle_command_line "$@" - -: ${DOTFILES_DIRS:=$DOTFILES_DIRS $DEFAULT_DOTFILES_DIR} -$DEBUG "DOTFILES_DIRS: $DOTFILES_DIRS" - -: ${COPY_ALWAYS:=""} -$DEBUG "COPY_ALWAYS: $COPY_ALWAYS" - -: ${SYMLINK_DIRS:=""} -$DEBUG "SYMLINK_DIRS: $SYMLINK_DIRS" - -relative_root_dir="$PWD" - -for DOTFILES_DIR in $DOTFILES_DIRS; do - cd "$relative_root_dir" - - if is_relative $DOTFILES_DIR; then - DOTFILES_DIR="$PWD/$DOTFILES_DIR" - fi - - if [ ! -d "$DOTFILES_DIR" ]; then - $VERBOSE "skipping non-existent directory: $DOTFILES_DIR" - continue - fi - - exclude_file_globs="$(dotfiles_dir_excludes "$DOTFILES_DIR" "$EXCLUDES")" - $DEBUG "exclude_file_globs: $exclude_file_globs" - include_file_globs="$(dotfiles_dir_excludes "$DOTFILES_DIR" "$INCLUDES")" - symlink_dirs_file_globs="$(dotfiles_dir_excludes "$DOTFILES_DIR" "$SYMLINK_DIRS")" - $DEBUG "symlink_dirs_file_globs: $symlink_dirs_file_globs" - - cd "$DOTFILES_DIR" - DIR_STACK=":$DOTFILES_DIR" - - for file in ${FILES:-*}; do - if is_metafile "$file"; then - continue - fi - - handle_file "$file" "$DEST_DIR" "$DOTFILES_DIR" . 0 "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" - done - - cd "$DOTFILES_DIR" - - host_files="$DOTFILES_DIR/host-$HOSTNAME" - if [ -d "$host_files" ]; then - pushdir "$(basename "$host_files")" - for file in ${FILES:-*}; do - handle_file "$file" "$DEST_DIR" "$host_files" . 0 "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" - done - popdir - fi - - cd "$DOTFILES_DIR" - - for tag in $TAGS; do - if [ -d "tag-$tag" ]; then - pushdir "$(basename "tag-$tag")" - for file in ${FILES:-*}; do - $DEBUG "TAG: $tag, exclude_file_globs: $exclude_file_globs" - handle_file "$file" "$DEST_DIR" "$DOTFILES_DIR/tag-$tag" . 0 "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" - done - popdir - fi - done - -done diff --git a/bin/lsrc.in b/bin/lsrc.in new file mode 100755 index 0000000..1402fec --- /dev/null +++ b/bin/lsrc.in @@ -0,0 +1,328 @@ +#!@SHELL@ + +: ${RCM_LIB:=$(dirname "$0")/../share/rcm} +. "$RCM_LIB/rcm.sh" + +pushdir() { + DIR_STACK="$DIR_STACK:$PWD/$1" + $DEBUG "cd'ing to $1 from $PWD with stack $DIR_STACK" + cd "$1" +} + +popdir() { + current="$(echo "$DIR_STACK" | sed -e 's/.*://g')" + prior="$(echo "$DIR_STACK" | sed -e "s|:$current$||" | sed -e 's/.*://g')" + DIR_STACK="$(echo "$DIR_STACK" | sed -e 's/:[^:]*$//')" + $DEBUG "cd'ing to $prior from $PWD with stack $DIR_STACK" + cd "$prior" +} + +build_path() { + local dest="$1" + local file="$2" + local dotted=$3 + + if [ $dotted -eq 1 ]; then + echo "$dest/$file" + else + echo "$dest/.$file" + fi +} + +file_join() { + local result= + + for file; do + if [ "x$file" != "x." ]; then + if [ "x$result" = "x" ]; then + result="$file" + else + result="$result/$file" + fi + fi + done + + echo "$result" +} + +show_dir() { + local dir="$1" + local dest_dir="$2" + local dotfiles_dir="$3" + local dotfiles_subdir="$4" + local dotted=$5 + local exclude_file_globs="$6" + local include_file_globs="$7" + local symlink_dirs_file_globs="$8" + local dest_path="$(build_path "$dest_dir" "$dir" $dotted)" + + $DEBUG "show_dir $1 $2 $3 $4 $5 $6 $7 $8" + + $VERBOSE "recurring on $dest_path" + + pushdir "$dir" + for f in *; do + $DEBUG "handling the file $f" + next_dir="$(file_join "$dotfiles_subdir" "$dir")" + handle_file "$f" "$dest_path" "$dotfiles_dir" "$next_dir" 1 "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" + done + popdir +} + +sigil_for() { + local file="$1" + local symlink_dirs_file_globs="$2" + local copy_always=0 + local symlink_dirs=0 + + for copy_file in $COPY_ALWAYS; do + $DEBUG "copy_file: $copy_file" + $DEBUG "file: $file" + + case "$file" in + $copy_file) + copy_always=1 + break + ;; + esac + done + + if [ -n "$symlink_dirs_file_globs" ]; then + symlink_dirs=1 + fi + + if [ $copy_always -eq 1 ]; then + echo 'X' + elif [ $symlink_dirs -eq 1 ]; then + echo '$' + else + echo '@' + fi +} + +show_file() { + local file="$1" + local dest_dir="$2" + local dotfiles_dir="$3" + local dotfiles_subdir="$4" + local dotted=$5 + local symlink_dirs_file_globs="$6" + local dest_file="$(build_path "$dest_dir" "$file" $dotted)" + + if echo "$DEST_STACK" | grep -vq ":$dest_file"; then + DEST_STACK="$DEST_STACK:$dest_file" + + src_file="$(file_join "$dotfiles_subdir" "$file")" + abs_src_file="$(file_join "$dotfiles_dir" "$src_file")" + output="$dest_file:$abs_src_file" + + if [ $SHOW_SIGILS -eq 1 ]; then + sigil="$(sigil_for "$src_file" "$symlink_dirs_file_globs")" + output="$output:$sigil" + fi + + $PRINT "$output" + fi +} + +handle_file() { + local file="$1" + local dest_dir="$2" + local dotfiles_dir="$3" + local dotfiles_subdir="$4" + local dotted=$5 + local exclude_file_globs="$6" + local include_file_globs="$7" + local symlink_dirs_file_globs="$8" + + $DEBUG "handle_file $1 $2 $3 $4 $5 $6 $7 $8" + + if [ ! -e "$file" ]; then + $VERBOSE "skipping non-existent file $file" + elif is_excluded "$file" "$exclude_file_globs" "$include_file_globs"; then + $VERBOSE "skipping excluded file $file" + elif [ -d "$file" ] && is_excluded $file "$symlink_dirs_file_globs"; then + show_file "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted "$symlink_dirs_file_globs" + elif [ -d "$file" ]; then + show_dir "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" + else + show_file "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted + fi +} + +is_metafile() { + host_portion="$(echo "$1" | sed -e 's/host-.*/host-/')" + tag_portion="$(echo "$1" | sed -e 's/tag-.*/tag-/')" + + [ "x$host_portion" = 'xhost-' -o "x$tag_portion" = 'xtag-' -o "x$1" = "xhooks" ] +} + +dotfiles_dir_excludes() { + local dotfiles_dir="$1" + local excludes="$2" + + $DEBUG "dotfiles_dir_excludes $dotfiles_dir" + $DEBUG " with excludes: $excludes" + + for exclude in $excludes; do + if echo "$exclude" | grep -q ':'; then + dotfiles_dir_pat="$(echo "$exclude" | sed 's/:.*//')" + file_glob="$(echo "$exclude" | sed 's/.*://')" + + if [ "x$dotfiles_dir_pat" != "x*" ] && is_relative "$dotfiles_dir_pat"; then + dotfiles_dir_pat="$PWD/$dotfiles_dir_pat" + fi + + if [ "x$dotfiles_dir_pat" = "x*" -o "x$dotfiles_dir_pat" = "x$dotfiles_dir" ]; then + echo "$file_glob" + fi + else + echo "$exclude" + fi + done +} + +is_excluded() { + local file="$1" + local exclude_file_globs="$2" + local include_file_globs="$3" + + $DEBUG "is_excluded $file $exclude_file_globs $include_file_globs" + + for exclude_file_glob in $exclude_file_globs; do + $DEBUG "file: $file" + $DEBUG "exclude_file_glob: $exclude_file_glob" + + case "$file" in + $exclude_file_glob) + for include_file_glob in $include_file_globs; do + case "$file" in + $include_file_glob) return 1;; + esac + done + + return 0 + ;; + esac + done + + return 1 +} + +show_help() { + local exit_code=${1:-0} + + $PRINT "Usage: lsrc [-FVqvh] [-I EXCL_PAT] [-x EXCL_PAT] [-N EXCL_PAT ] [-t TAG] [-d DOT_DIR]" + $PRINT "see lsrc(1) and rcm(5) for more details" + + exit $exit_code +} + +handle_command_line() { + local arg_tags= + local verbosity=0 + local version=0 + local show_sigils=0 + local dotfiles_dirs= + local excludes= + local includes= + local symlink_dirs= + + while getopts FVqvhI:x:S:t:d: opt; do + case "$opt" in + F) show_sigils=1;; + h) show_help ;; + I) includes="$includes $OPTARG";; + t) arg_tags="$arg_tags $OPTARG";; + v) verbosity=$(($verbosity + 1));; + q) verbosity=$(($verbosity - 1));; + d) dotfiles_dirs="$dotfiles_dirs $OPTARG";; + V) version=1;; + x) excludes="$excludes $OPTARG";; + S) symlink_dirs="$symlink_dirs $OPTARG";; + esac + done + shift $(($OPTIND-1)) + + handle_common_flags lsrc $version $verbosity + SHOW_SIGILS=$show_sigils + TAGS="${arg_tags:-$TAGS}" + DOTFILES_DIRS="${dotfiles_dirs:-$DOTFILES_DIRS}" + EXCLUDES="${excludes:-$EXCLUDES}" + INCLUDES="${includes:-$INCLUDES}" + SYMLINK_DIRS="${symlink_dirs:-$SYMLINK_DIRS}" + FILES="$@" + + $DEBUG "TAGS: $TAGS" + $DEBUG "DOTFILES_DIRS: $DOTFILES_DIRS" +} + +DEST_STACK= + +handle_command_line "$@" + +: ${DOTFILES_DIRS:=$DOTFILES_DIRS $DEFAULT_DOTFILES_DIR} +$DEBUG "DOTFILES_DIRS: $DOTFILES_DIRS" + +: ${COPY_ALWAYS:=""} +$DEBUG "COPY_ALWAYS: $COPY_ALWAYS" + +: ${SYMLINK_DIRS:=""} +$DEBUG "SYMLINK_DIRS: $SYMLINK_DIRS" + +relative_root_dir="$PWD" + +for DOTFILES_DIR in $DOTFILES_DIRS; do + cd "$relative_root_dir" + + if is_relative $DOTFILES_DIR; then + DOTFILES_DIR="$PWD/$DOTFILES_DIR" + fi + + if [ ! -d "$DOTFILES_DIR" ]; then + $VERBOSE "skipping non-existent directory: $DOTFILES_DIR" + continue + fi + + exclude_file_globs="$(dotfiles_dir_excludes "$DOTFILES_DIR" "$EXCLUDES")" + $DEBUG "exclude_file_globs: $exclude_file_globs" + include_file_globs="$(dotfiles_dir_excludes "$DOTFILES_DIR" "$INCLUDES")" + symlink_dirs_file_globs="$(dotfiles_dir_excludes "$DOTFILES_DIR" "$SYMLINK_DIRS")" + $DEBUG "symlink_dirs_file_globs: $symlink_dirs_file_globs" + + cd "$DOTFILES_DIR" + DIR_STACK=":$DOTFILES_DIR" + + for file in ${FILES:-*}; do + if is_metafile "$file"; then + continue + fi + + handle_file "$file" "$DEST_DIR" "$DOTFILES_DIR" . 0 "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" + done + + cd "$DOTFILES_DIR" + + host_files="$DOTFILES_DIR/host-$HOSTNAME" + if [ -d "$host_files" ]; then + pushdir "$(basename "$host_files")" + for file in ${FILES:-*}; do + handle_file "$file" "$DEST_DIR" "$host_files" . 0 "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" + done + popdir + fi + + cd "$DOTFILES_DIR" + + for tag in $TAGS; do + if [ -d "tag-$tag" ]; then + pushdir "$(basename "tag-$tag")" + for file in ${FILES:-*}; do + $DEBUG "TAG: $tag, exclude_file_globs: $exclude_file_globs" + handle_file "$file" "$DEST_DIR" "$DOTFILES_DIR/tag-$tag" . 0 "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" + done + popdir + fi + done + +done diff --git a/bin/mkrc b/bin/mkrc deleted file mode 100755 index 3d9b749..0000000 --- a/bin/mkrc +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/sh - -: ${RCM_LIB:=$(dirname "$0")/../share/rcm} -. "$RCM_LIB/rcm.sh" - -destination() { - local dotfiles_dir="$1" - local dotless=$2 - local in_host=$3 - local tag="$4" - - if [ "x$tag" != "x" ]; then - echo "$dotfiles_dir/tag-$tag" - elif [ $in_host = 1 ]; then - echo "$dotfiles_dir/host-$HOSTNAME" - else - echo "$dotfiles_dir" - fi -} - -show_help() { - local exit_code=${1:-0} - - $PRINT "Usage: mkrc [-hvqo] [-t TAG] [-d DIR] FILES ..." - $PRINT "see mkrc(1) and rcm(5) for more details" - - exit $exit_code -} - -if [ $# -eq 0 ]; then - show_help 1 -fi - -for DOTFILES_DIR in $DOTFILES_DIRS $DEFAULT_DOTFILES_DIR; do - break -done - -tag= -verbosity=0 -in_host=0 -version=0 -always_copy=0 -force_symlink=0 - -while getopts ChSsVvqot:d: opt; do - case "$opt" in - C) always_copy=1 ;; - h) show_help ;; - t) tag="$OPTARG" ;; - v) verbosity=$(($verbosity + 1)) ;; - q) verbosity=$(($verbosity - 1)) ;; - o) in_host=1 ;; - d) DOTFILES_DIR="$OPTARG" ;; - V) version=1 ;; - S) force_symlink=1 ;; - s) force_symlink=0 ;; - esac -done -shift $(($OPTIND-1)) - -handle_common_flags mkrc $version $verbosity - -if [ $in_host -eq 1 -a "x$tag" != "x" ]; then - $ERROR 1 "Cannot specify both -o and -t" -fi - -if [ $always_copy -eq 1 ]; then - INSTALL="$INSTALL -C" -fi - -files=$@ - -if [ $force_symlink -eq 1 ]; then - for file in $files; do - dedotted="$(de_dot "$file")" - INSTALL="$INSTALL -S $dedotted" - done -fi - -for file in $files; do - dotless="$(de_dot "$file")" - dest="$(destination "$DOTFILES_DIR" "$dotless" $in_host "$tag")" - mkdir -p "$dest/$(dirname "$dotless")" - $PRINT "Moving..." - mv_v "$file" "$dest/$dotless" - $PRINT "Linking..." - $INSTALL -d "$DOTFILES_DIR" -t "${tag:--}" "$dotless" -done diff --git a/bin/mkrc.in b/bin/mkrc.in new file mode 100755 index 0000000..398996a --- /dev/null +++ b/bin/mkrc.in @@ -0,0 +1,88 @@ +#!@SHELL@ + +: ${RCM_LIB:=$(dirname "$0")/../share/rcm} +. "$RCM_LIB/rcm.sh" + +destination() { + local dotfiles_dir="$1" + local dotless=$2 + local in_host=$3 + local tag="$4" + + if [ "x$tag" != "x" ]; then + echo "$dotfiles_dir/tag-$tag" + elif [ $in_host = 1 ]; then + echo "$dotfiles_dir/host-$HOSTNAME" + else + echo "$dotfiles_dir" + fi +} + +show_help() { + local exit_code=${1:-0} + + $PRINT "Usage: mkrc [-hvqo] [-t TAG] [-d DIR] FILES ..." + $PRINT "see mkrc(1) and rcm(5) for more details" + + exit $exit_code +} + +if [ $# -eq 0 ]; then + show_help 1 +fi + +for DOTFILES_DIR in $DOTFILES_DIRS $DEFAULT_DOTFILES_DIR; do + break +done + +tag= +verbosity=0 +in_host=0 +version=0 +always_copy=0 +force_symlink=0 + +while getopts ChSsVvqot:d: opt; do + case "$opt" in + C) always_copy=1 ;; + h) show_help ;; + t) tag="$OPTARG" ;; + v) verbosity=$(($verbosity + 1)) ;; + q) verbosity=$(($verbosity - 1)) ;; + o) in_host=1 ;; + d) DOTFILES_DIR="$OPTARG" ;; + V) version=1 ;; + S) force_symlink=1 ;; + s) force_symlink=0 ;; + esac +done +shift $(($OPTIND-1)) + +handle_common_flags mkrc $version $verbosity + +if [ $in_host -eq 1 -a "x$tag" != "x" ]; then + $ERROR 1 "Cannot specify both -o and -t" +fi + +if [ $always_copy -eq 1 ]; then + INSTALL="$INSTALL -C" +fi + +files=$@ + +if [ $force_symlink -eq 1 ]; then + for file in $files; do + dedotted="$(de_dot "$file")" + INSTALL="$INSTALL -S $dedotted" + done +fi + +for file in $files; do + dotless="$(de_dot "$file")" + dest="$(destination "$DOTFILES_DIR" "$dotless" $in_host "$tag")" + mkdir -p "$dest/$(dirname "$dotless")" + $PRINT "Moving..." + mv_v "$file" "$dest/$dotless" + $PRINT "Linking..." + $INSTALL -d "$DOTFILES_DIR" -t "${tag:--}" "$dotless" +done diff --git a/bin/rcdn b/bin/rcdn deleted file mode 100755 index 2caa340..0000000 --- a/bin/rcdn +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/sh - -: ${RCM_LIB:=$(dirname "$0")/../share/rcm} -. "$RCM_LIB/rcm.sh" - -remove_link() { - local dest="$1" - local original="$2" - local sigil="$3" - - if [ "x$dest" = "x/" ]; then - $VERBOSE "not a symlink, skipping: $original" - elif [ -L "$dest" -o "x$sigil" = "xX" ]; then - rm_v -rf "$dest" - rmdir -p "$(dirname "$original")" 2>/dev/null - else - remove_link "$(dirname "$dest")" "$original" - fi -} - -show_help() { - local exit_code=${1:-0} - - $PRINT "Usage: rcdn [-Vqvh] [-I EXCL_PAT] [-x EXCL_PAT] [-t TAG] [-d DOT_DIR]" - $PRINT "see rcdn(1) and rcm(5) for more details" - - exit $exit_code -} - -handle_command_line() { - local arg_tags= - local verbosity=0 - local version=0 - local run_hooks=0 - local dotfiles_dirs= - local files= - local excludes= - local includes= - local symlink_dirs= - - while getopts VqvhI:x:S:t:d: opt; do - case "$opt" in - h) show_help ;; - I) includes="$includes $OPTARG";; - k) run_hooks=1 ;; - K) run_hooks=0 ;; - t) arg_tags="$arg_tags $OPTARG" ;; - S) symlink_dirs="$symlink_dirs $OPTARG";; - v) verbosity=$(($verbosity + 1));; - q) verbosity=$(($verbosity - 1));; - d) dotfiles_dirs="$dotfiles_dirs $OPTARG" ;; - V) version=1 ;; - x) excludes="$excludes $OPTARG" ;; - esac - done - shift $(($OPTIND-1)) - - handle_common_flags rcup $version $verbosity - - tags="${arg_tags:-$TAGS}" - dotfiles_dirs="${dotfiles_dirs:-$DOTFILES_DIRS}" - files="$@" - RUN_HOOKS=$run_hooks - - for tag in $tags; do - LS_ARGS="$LS_ARGS -t $tag" - done - for dotfiles_dir in $dotfiles_dirs; do - LS_ARGS="$LS_ARGS -d $dotfiles_dir" - done - for exclude in $excludes; do - LS_ARGS="$LS_ARGS -x $exclude" - done - for include in $includes; do - LS_ARGS="$LS_ARGS -I $include" - done - for symlink_dir in $symlink_dirs; do - LS_ARGS="$LS_ARGS -S $symlink_dir" - done - LS_ARGS="$LS_ARGS $files" - - $DEBUG "LS_ARGS: $LS_ARGS" -} - -LS_ARGS=-F - -handle_command_line "$@" -: ${DOTFILES_DIRS:=$DOTFILES_DIRS $DEFAULT_DOTFILES_DIR} - -run_hooks pre down - -dests_and_srcs="$(lsrc $LS_ARGS)" - -saved_ifs="$IFS" -IFS=' -' -for dest_and_src in $dests_and_srcs; do - IFS=: - set -- $dest_and_src - IFS="$saved_ifs" - dest="$1" - sigil="$3" - - remove_link "$dest" "$dest" "$sigil" -done - -run_hooks post down diff --git a/bin/rcdn.in b/bin/rcdn.in new file mode 100755 index 0000000..2ca6dae --- /dev/null +++ b/bin/rcdn.in @@ -0,0 +1,107 @@ +#!@SHELL@ + +: ${RCM_LIB:=$(dirname "$0")/../share/rcm} +. "$RCM_LIB/rcm.sh" + +remove_link() { + local dest="$1" + local original="$2" + local sigil="$3" + + if [ "x$dest" = "x/" ]; then + $VERBOSE "not a symlink, skipping: $original" + elif [ -L "$dest" -o "x$sigil" = "xX" ]; then + rm_v -rf "$dest" + rmdir -p "$(dirname "$original")" 2>/dev/null + else + remove_link "$(dirname "$dest")" "$original" + fi +} + +show_help() { + local exit_code=${1:-0} + + $PRINT "Usage: rcdn [-Vqvh] [-I EXCL_PAT] [-x EXCL_PAT] [-t TAG] [-d DOT_DIR]" + $PRINT "see rcdn(1) and rcm(5) for more details" + + exit $exit_code +} + +handle_command_line() { + local arg_tags= + local verbosity=0 + local version=0 + local run_hooks=0 + local dotfiles_dirs= + local files= + local excludes= + local includes= + local symlink_dirs= + + while getopts VqvhI:x:S:t:d: opt; do + case "$opt" in + h) show_help ;; + I) includes="$includes $OPTARG";; + k) run_hooks=1 ;; + K) run_hooks=0 ;; + t) arg_tags="$arg_tags $OPTARG" ;; + S) symlink_dirs="$symlink_dirs $OPTARG";; + v) verbosity=$(($verbosity + 1));; + q) verbosity=$(($verbosity - 1));; + d) dotfiles_dirs="$dotfiles_dirs $OPTARG" ;; + V) version=1 ;; + x) excludes="$excludes $OPTARG" ;; + esac + done + shift $(($OPTIND-1)) + + handle_common_flags rcup $version $verbosity + + tags="${arg_tags:-$TAGS}" + dotfiles_dirs="${dotfiles_dirs:-$DOTFILES_DIRS}" + files="$@" + RUN_HOOKS=$run_hooks + + for tag in $tags; do + LS_ARGS="$LS_ARGS -t $tag" + done + for dotfiles_dir in $dotfiles_dirs; do + LS_ARGS="$LS_ARGS -d $dotfiles_dir" + done + for exclude in $excludes; do + LS_ARGS="$LS_ARGS -x $exclude" + done + for include in $includes; do + LS_ARGS="$LS_ARGS -I $include" + done + for symlink_dir in $symlink_dirs; do + LS_ARGS="$LS_ARGS -S $symlink_dir" + done + LS_ARGS="$LS_ARGS $files" + + $DEBUG "LS_ARGS: $LS_ARGS" +} + +LS_ARGS=-F + +handle_command_line "$@" +: ${DOTFILES_DIRS:=$DOTFILES_DIRS $DEFAULT_DOTFILES_DIR} + +run_hooks pre down + +dests_and_srcs="$(lsrc $LS_ARGS)" + +saved_ifs="$IFS" +IFS=' +' +for dest_and_src in $dests_and_srcs; do + IFS=: + set -- $dest_and_src + IFS="$saved_ifs" + dest="$1" + sigil="$3" + + remove_link "$dest" "$dest" "$sigil" +done + +run_hooks post down diff --git a/bin/rcup b/bin/rcup deleted file mode 100755 index b45157b..0000000 --- a/bin/rcup +++ /dev/null @@ -1,188 +0,0 @@ -#!/bin/sh - -: ${RCM_LIB:=$(dirname "$0")/../share/rcm} -. "$RCM_LIB/rcm.sh" - -link_or_copy() { - $DEBUG "link_or_copy $1" - local sigil="$1" - - if [ "x$sigil" = "xX" ]; then - echo "cp_v" - else - echo "$LN" - fi -} - -link_file() { - local src="$1" - local dest="$2" - local sigil="$3" - - if [ -h "$dest" ]; then - rm_v -f "$dest" - fi - - action="$(link_or_copy "$sigil")" - $DEBUG "$action $src $dest" - $action "$src" "$dest" -} - -replace_file() { - local src="$1" - local dest="$2" - local sigil="$3" - - $DEBUG replace_file "$1" "$2" $3 - - rm_v -rf "$dest" - link_file "$src" "$dest" "$sigil" -} - -is_nested() { - echo "$1" | sed "s:$DEST_DIR/::" | grep -q '/' -} - -is_identical() { - diff -q -s "$1" "$2" > /dev/null -} - -handle_dir() { - local dest="$1" - - $DEBUG "handle_dir $1" - - dirname "$dest" | xargs $MKDIR -p -} - -handle_file() { - local src="$1" - local dest="$2" - local sigil="$3" - - $DEBUG "handle_file $1 $2 $3" - - if [ -e "$dest" ]; then - if is_identical "$src" "$dest"; then - $VERBOSE "identical $dest" - elif [ $REPLACE_ALL -eq 1 ]; then - replace_file "$src" "$dest" "$sigil" - else - $PROMPT "overwrite ${dest}? [ynaq]" - read overwrite - case "$overwrite" in - a) REPLACE_ALL=1 - replace_file "$src" "$dest" "$sigil" - ;; - y) replace_file "$src" "$dest" "$sigil" ;; - q) exit 1 ;; - *) $VERBOSE "skipping $dest" ;; - esac - fi - else - link_file "$src" "$dest" "$sigil" - fi -} - -show_help() { - local exit_code=${1:-0} - - $PRINT "Usage: rcup [-CVqvfhikK] [-I EXCL_PAT] [-x EXCL_PAT] [-t TAG] [-d DOT_DIR]" - $PRINT "see rcup(1) and rcm(5) for more details" - - exit $exit_code -} - -handle_command_line() { - local arg_tags= - local verbosity=0 - local version=0 - local run_hooks=1 - local dotfiles_dirs= - local files= - local excludes= - local includes= - local always_copy=0 - local symlink_dirs= - REPLACE_ALL=0 - - while getopts CVqvfhikKI:x:S:t:d: opt; do - case "$opt" in - C) always_copy=1 ;; - d) dotfiles_dirs="$dotfiles_dirs $OPTARG" ;; - f) REPLACE_ALL=1 ;; - h) show_help ;; - i) REPLACE_ALL=0 ;; - I) includes="$includes $OPTARG" ;; - k) run_hooks=1 ;; - K) run_hooks=0 ;; - q) verbosity=$(($verbosity - 1)) ;; - t) arg_tags="$arg_tags $OPTARG" ;; - S) symlink_dirs="$symlink_dirs $OPTARG";; - v) verbosity=$(($verbosity + 1)) ;; - V) version=1 ;; - x) excludes="$excludes $OPTARG" ;; - esac - done - shift $(($OPTIND-1)) - - LN="ln_v" - if [ $always_copy -eq 1 ]; then - LN="cp_v" - fi - - handle_common_flags rcup $version $verbosity - - tags="${arg_tags:-$TAGS}" - DOTFILES_DIRS="${dotfiles_dirs:-$DOTFILES_DIRS}" - RUN_HOOKS=$run_hooks - files="$@" - - for tag in $tags; do - LS_ARGS="$LS_ARGS -t $tag" - done - for dotfiles_dir in $DOTFILES_DIRS; do - LS_ARGS="$LS_ARGS -d $dotfiles_dir" - done - for exclude in $excludes; do - LS_ARGS="$LS_ARGS -x $exclude" - done - for include in $includes; do - LS_ARGS="$LS_ARGS -I $include" - done - for symlink_dir in $symlink_dirs; do - LS_ARGS="$LS_ARGS -S $symlink_dir" - done - LS_ARGS="$LS_ARGS $files" - - $DEBUG "LS_ARGS: $LS_ARGS" -} - -LS_ARGS=-F - -handle_command_line "$@" -: ${DOTFILES_DIRS:=$DOTFILES_DIRS $DEFAULT_DOTFILES_DIR} - -run_hooks pre up - -dests_and_srcs="$(lsrc $LS_ARGS)" - -saved_ifs="$IFS" -IFS=' -' -for dest_and_src in $dests_and_srcs; do - IFS=: - set -- $dest_and_src - IFS="$saved_ifs" - dest="$1" - src="$2" - sigil="$3" - - if is_nested "$dest"; then - handle_dir "$dest" - fi - - handle_file "$src" "$dest" "$sigil" -done - -run_hooks post up diff --git a/bin/rcup.in b/bin/rcup.in new file mode 100755 index 0000000..849a0f7 --- /dev/null +++ b/bin/rcup.in @@ -0,0 +1,188 @@ +#!@SHELL@ + +: ${RCM_LIB:=$(dirname "$0")/../share/rcm} +. "$RCM_LIB/rcm.sh" + +link_or_copy() { + $DEBUG "link_or_copy $1" + local sigil="$1" + + if [ "x$sigil" = "xX" ]; then + echo "cp_v" + else + echo "$LN" + fi +} + +link_file() { + local src="$1" + local dest="$2" + local sigil="$3" + + if [ -h "$dest" ]; then + rm_v -f "$dest" + fi + + action="$(link_or_copy "$sigil")" + $DEBUG "$action $src $dest" + $action "$src" "$dest" +} + +replace_file() { + local src="$1" + local dest="$2" + local sigil="$3" + + $DEBUG replace_file "$1" "$2" $3 + + rm_v -rf "$dest" + link_file "$src" "$dest" "$sigil" +} + +is_nested() { + echo "$1" | sed "s:$DEST_DIR/::" | grep -q '/' +} + +is_identical() { + diff -q -s "$1" "$2" > /dev/null +} + +handle_dir() { + local dest="$1" + + $DEBUG "handle_dir $1" + + dirname "$dest" | xargs $MKDIR -p +} + +handle_file() { + local src="$1" + local dest="$2" + local sigil="$3" + + $DEBUG "handle_file $1 $2 $3" + + if [ -e "$dest" ]; then + if is_identical "$src" "$dest"; then + $VERBOSE "identical $dest" + elif [ $REPLACE_ALL -eq 1 ]; then + replace_file "$src" "$dest" "$sigil" + else + $PROMPT "overwrite ${dest}? [ynaq]" + read overwrite + case "$overwrite" in + a) REPLACE_ALL=1 + replace_file "$src" "$dest" "$sigil" + ;; + y) replace_file "$src" "$dest" "$sigil" ;; + q) exit 1 ;; + *) $VERBOSE "skipping $dest" ;; + esac + fi + else + link_file "$src" "$dest" "$sigil" + fi +} + +show_help() { + local exit_code=${1:-0} + + $PRINT "Usage: rcup [-CVqvfhikK] [-I EXCL_PAT] [-x EXCL_PAT] [-t TAG] [-d DOT_DIR]" + $PRINT "see rcup(1) and rcm(5) for more details" + + exit $exit_code +} + +handle_command_line() { + local arg_tags= + local verbosity=0 + local version=0 + local run_hooks=1 + local dotfiles_dirs= + local files= + local excludes= + local includes= + local always_copy=0 + local symlink_dirs= + REPLACE_ALL=0 + + while getopts CVqvfhikKI:x:S:t:d: opt; do + case "$opt" in + C) always_copy=1 ;; + d) dotfiles_dirs="$dotfiles_dirs $OPTARG" ;; + f) REPLACE_ALL=1 ;; + h) show_help ;; + i) REPLACE_ALL=0 ;; + I) includes="$includes $OPTARG" ;; + k) run_hooks=1 ;; + K) run_hooks=0 ;; + q) verbosity=$(($verbosity - 1)) ;; + t) arg_tags="$arg_tags $OPTARG" ;; + S) symlink_dirs="$symlink_dirs $OPTARG";; + v) verbosity=$(($verbosity + 1)) ;; + V) version=1 ;; + x) excludes="$excludes $OPTARG" ;; + esac + done + shift $(($OPTIND-1)) + + LN="ln_v" + if [ $always_copy -eq 1 ]; then + LN="cp_v" + fi + + handle_common_flags rcup $version $verbosity + + tags="${arg_tags:-$TAGS}" + DOTFILES_DIRS="${dotfiles_dirs:-$DOTFILES_DIRS}" + RUN_HOOKS=$run_hooks + files="$@" + + for tag in $tags; do + LS_ARGS="$LS_ARGS -t $tag" + done + for dotfiles_dir in $DOTFILES_DIRS; do + LS_ARGS="$LS_ARGS -d $dotfiles_dir" + done + for exclude in $excludes; do + LS_ARGS="$LS_ARGS -x $exclude" + done + for include in $includes; do + LS_ARGS="$LS_ARGS -I $include" + done + for symlink_dir in $symlink_dirs; do + LS_ARGS="$LS_ARGS -S $symlink_dir" + done + LS_ARGS="$LS_ARGS $files" + + $DEBUG "LS_ARGS: $LS_ARGS" +} + +LS_ARGS=-F + +handle_command_line "$@" +: ${DOTFILES_DIRS:=$DOTFILES_DIRS $DEFAULT_DOTFILES_DIR} + +run_hooks pre up + +dests_and_srcs="$(lsrc $LS_ARGS)" + +saved_ifs="$IFS" +IFS=' +' +for dest_and_src in $dests_and_srcs; do + IFS=: + set -- $dest_and_src + IFS="$saved_ifs" + dest="$1" + src="$2" + sigil="$3" + + if is_nested "$dest"; then + handle_dir "$dest" + fi + + handle_file "$src" "$dest" "$sigil" +done + +run_hooks post up -- cgit v1.2.3