summaryrefslogtreecommitdiff
path: root/bin/rcup
diff options
context:
space:
mode:
authorGravatar Mike Burns <mike@mike-burns.com>2013-08-11 17:29:01 +0200
committerGravatar Mike Burns <mike@mike-burns.com>2013-08-11 21:18:53 +0200
commit8d7f6c94a3458328b339b6582592b6c1fecec950 (patch)
treeff9ea4a2a83fafb910d0c604435d648bf01cedbf /bin/rcup
parent0fbc27dbe296e03b4001586a7e29780328cbc657 (diff)
Add the COPY_ALWAYS option
The suite now honors the `COPY_ALWAYS` option in rcrc(5). This can be set to a space-separated list of file globs. Any file matching a glob is copied instead of symlinked. This is handy both for secure programs (`netrc`, `ssh/id_*`) and for programs that oddly re-write files (`weechat/*`). To always copy everything, use the `*` glob. This is reflected throughout the suite as follows: * lsrc now has a `-F` option which shows a symbol to indicate whether it is a symlink (`@`) or a copy (`X`). * rcdn only removes symlinks unless the file under question matches a `COPY_ALWAYS` glob, in which case it is removed regardless of whether it is a symlink. * rcup will copy instead of symlinking any file that matches any `COPY_ALWAYS` glob.
Diffstat (limited to 'bin/rcup')
-rwxr-xr-xbin/rcup47
1 files changed, 35 insertions, 12 deletions
diff --git a/bin/rcup b/bin/rcup
index af7a012..5f51192 100755
--- a/bin/rcup
+++ b/bin/rcup
@@ -3,25 +3,40 @@
: ${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
+ else
+ echo $LN
+ fi
+}
+
link_file() {
local src=$1
local dest=$2
+ local sigil=$3
if [ -h $dest ]; then
$RM -f $dest
fi
- $LN $src $dest
+ 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
+ $DEBUG replace_file $1 $2 $3
$RM -rf $dest
- link_file $src $dest
+ link_file $src $dest $sigil
}
is_nested() {
@@ -44,28 +59,29 @@ handle_dir() {
handle_file() {
local src=$1
local dest=$2
+ local sigil=$3
- $DEBUG handle_file $1 $2
+ $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
+ replace_file $src $dest $sigil
else
$PROMPT "overwrite ${dest}? [ynaq]"
read overwrite
case $overwrite in
a) REPLACE_ALL=1
- replace_file $src $dest
+ replace_file $src $dest $sigil
;;
- y) replace_file $src $dest ;;
+ y) replace_file $src $dest $sigil ;;
q) exit 1 ;;
*) $VERBOSE "skipping $dest" ;;
esac
fi
else
- link_file $src $dest
+ link_file $src $dest $sigil
fi
}
@@ -97,7 +113,7 @@ handle_command_line() {
shift $(($OPTIND-1))
if [ $always_copy -eq 1 ]; then
- LN=cp
+ LN=$CP
fi
handle_common_flags rcup $version $verbosity
@@ -123,6 +139,8 @@ handle_command_line() {
$DEBUG "LS_ARGS: $LS_ARGS"
}
+LS_ARGS=-F
+
if [ -e $HOME/.rcrc ]; then
. $HOME/.rcrc
fi
@@ -130,12 +148,17 @@ fi
handle_command_line $*
for dest_and_src in `lsrc $LS_ARGS`; do
- dest=`echo $dest_and_src | sed 's/:.*//'`
- src=`echo $dest_and_src | sed 's/.*://'`
+ saved_ifs=$IFS
+ 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
+ handle_file $src $dest $sigil
done