diff options
author | Mike Burns <mike@mike-burns.com> | 2013-08-05 06:15:17 +0200 |
---|---|---|
committer | Mike Burns <mike@mike-burns.com> | 2013-08-05 06:15:17 +0200 |
commit | fc648042ca2e753b8ecdabc5fa52aea5313c3b03 (patch) | |
tree | e69c2dba330066ef1ddc5725d97ab0b336ef5783 /bin | |
parent | 122bbf0c6da226fc7e8a7e2a8d173b3e6259f7cf (diff) |
Add -C for copying files
Some files prefer to be copies instead of symlinks---for example,
OpenSSH ignores symlinks. Add the `-C` option to mkrc(1) and rcup(1) to
handle this.
mkrc -C .ssh
rcup -C ssh
This does raise a synchronization problem that I do not yet know how to
solve; namely, what to do when the rc file changes. Perhaps a `rcsync`
command is in order; perhaps `rcup` should handle this; perhaps `rcsync`
is a better name for `rcup`.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/mkrc | 20 | ||||
-rwxr-xr-x | bin/rcup | 22 |
2 files changed, 26 insertions, 16 deletions
@@ -35,15 +35,17 @@ tag= verbosity=0 in_host=0 version=0 +always_copy=0 -while getopts Vvqot:d: opt; do +while getopts CVvqot:d: opt; do case "$opt" in - t) tag=$OPTARG;; - v) verbosity=$(($verbosity + 1));; - q) verbosity=$(($verbosity - 1));; - o) in_host=1;; - d) DOTFILES_DIR=$OPTARG;; - V) version=1 + C) always_copy=1 ;; + t) tag=$OPTARG ;; + v) verbosity=$(($verbosity + 1)) ;; + q) verbosity=$(($verbosity - 1)) ;; + o) in_host=1 ;; + d) DOTFILES_DIR=$OPTARG ;; + V) version=1 ;; esac done shift $(($OPTIND-1)) @@ -54,6 +56,10 @@ 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=$@ for file in $files; do @@ -7,12 +7,11 @@ link_file() { local src=$1 local dest=$2 - $PRINT "linking $dest" if [ -h $dest ]; then - rm -f $dest + $RM -f $dest fi - $LN -s $src $dest + $LN $src $dest } replace_file() { @@ -78,24 +77,29 @@ handle_command_line() { local files= local excludes= local includes= + local always_copy=0 REPLACE_ALL=0 - - while getopts VqvfiI:e:t:d: opt; do + while getopts CVqvfiI:e:t:d: opt; do case "$opt" in - e) excludes="$excludes $OPTARG";; + C) always_copy=1 ;; + d) dotfiles_dirs="$dotfiles_dirs $OPTARG" ;; + e) excludes="$excludes $OPTARG" ;; f) REPLACE_ALL=1 ;; i) REPLACE_ALL=0 ;; - I) includes="$includes $OPTARG";; + I) includes="$includes $OPTARG" ;; + q) verbosity=$(($verbosity - 1)) ;; t) arg_tags="$arg_tags $OPTARG" ;; v) verbosity=$(($verbosity + 1)) ;; - q) verbosity=$(($verbosity - 1)) ;; - d) dotfiles_dirs="$dotfiles_dirs $OPTARG" ;; V) version=1 esac done shift $(($OPTIND-1)) + if [ $always_copy -eq 1 ]; then + LN=cp + fi + handle_common_flags rcup $version $verbosity tags=${arg_tags:-$TAGS} |