From 8c26bfec32441830b4a0e5938a6cc7de1a64ff99 Mon Sep 17 00:00:00 2001 From: Mike Burns Date: Mon, 5 May 2014 11:08:02 +0200 Subject: Add a hostname override Based on issue #82, we now provide `-B` to override the hostname. In particular: - `mkrc -B foo` will enable `-o` but with the hostname set up `foo`. - `lsrc -B foo` will work like normal `lsrc` except it treats `host-foo` as the host-specific directory. - `rcup -B foo` will run a normal `rcup` except `host-foo` is the host-specific directory. - `rcdn -B foo` is just like normal `rcdn`, but with `host-foo` as the host-specific directory. The `HOSTNAME` can also be set in the rcrc(5), and this is overridden by the aforementioned `-B`. While making this change: The `test/Makefile.am` used a mix of tabs and spaces. Since it's a Makefile, replace it all with tabs. --- bin/lsrc.in | 5 ++++- bin/mkrc.in | 14 ++++++++++++-- bin/rcdn.in | 7 +++++-- bin/rcup.in | 7 +++++-- 4 files changed, 26 insertions(+), 7 deletions(-) (limited to 'bin') diff --git a/bin/lsrc.in b/bin/lsrc.in index c5ad700..760d769 100755 --- a/bin/lsrc.in +++ b/bin/lsrc.in @@ -227,8 +227,9 @@ handle_command_line() { local excludes= local includes= local symlink_dirs= + local hostname= - while getopts FVqvhI:x:S:t:d: opt; do + while getopts FVqvhI:x:B:S:t:d: opt; do case "$opt" in F) show_sigils=1;; h) show_help ;; @@ -240,11 +241,13 @@ handle_command_line() { V) version=1;; x) excludes="$excludes $OPTARG";; S) symlink_dirs="$symlink_dirs $OPTARG";; + B) hostname="$OPTARG";; esac done shift $(($OPTIND-1)) handle_common_flags lsrc $version $verbosity + HOSTNAME="$(determine_hostname "$hostname")" SHOW_SIGILS=$show_sigils TAGS="${arg_tags:-$TAGS}" DOTFILES_DIRS="${dotfiles_dirs:-$DOTFILES_DIRS}" diff --git a/bin/mkrc.in b/bin/mkrc.in index e8d3864..7cab210 100755 --- a/bin/mkrc.in +++ b/bin/mkrc.in @@ -9,6 +9,8 @@ destination() { local in_host=$3 local tag="$4" + $DEBUG "destination $dotfiles_dir $dotless $in_host $tag" + if [ "x$tag" != "x" ]; then echo "$dotfiles_dir/tag-$tag" elif [ $in_host = 1 ]; then @@ -36,13 +38,15 @@ for DOTFILES_DIR in $DOTFILES_DIRS $DEFAULT_DOTFILES_DIR; do done tag= +hostname= verbosity=0 in_host=0 version=0 always_copy=0 force_symlink=0 +install_args= -while getopts ChSsVvqot:d: opt; do +while getopts ChSsVvqot:d:B: opt; do case "$opt" in C) always_copy=1 ;; h) show_help ;; @@ -54,11 +58,17 @@ while getopts ChSsVvqot:d: opt; do V) version=1 ;; S) force_symlink=1 ;; s) force_symlink=0 ;; + B) + in_host=1 + hostname="$OPTARG" + install_args="-B $hostname" + ;; esac done shift $(($OPTIND-1)) handle_common_flags mkrc $version $verbosity +HOSTNAME="$(determine_hostname "$hostname")" if [ $in_host -eq 1 -a "x$tag" != "x" ]; then $ERROR 1 "Cannot specify both -o and -t" @@ -88,5 +98,5 @@ for file in $files; do $PRINT "Moving..." mv_v "$file" "$dest/$dotless" $PRINT "Linking..." - $INSTALL -d "$DOTFILES_DIR" -t "${tag:--}" "$dotless" + $INSTALL -d "$DOTFILES_DIR" -t "${tag:--}" $install_args "$dotless" done diff --git a/bin/rcdn.in b/bin/rcdn.in index 2ca6dae..e633f3e 100755 --- a/bin/rcdn.in +++ b/bin/rcdn.in @@ -37,10 +37,12 @@ handle_command_line() { local excludes= local includes= local symlink_dirs= + local hostname= - while getopts VqvhI:x:S:t:d: opt; do + while getopts VqvhI:x:S:t:d:B: opt; do case "$opt" in h) show_help ;; + B) hostname="$OPTARG" ;; I) includes="$includes $OPTARG";; k) run_hooks=1 ;; K) run_hooks=0 ;; @@ -56,6 +58,7 @@ handle_command_line() { shift $(($OPTIND-1)) handle_common_flags rcup $version $verbosity + hostname="$(determine_hostname "$hostname")" tags="${arg_tags:-$TAGS}" dotfiles_dirs="${dotfiles_dirs:-$DOTFILES_DIRS}" @@ -77,7 +80,7 @@ handle_command_line() { for symlink_dir in $symlink_dirs; do LS_ARGS="$LS_ARGS -S $symlink_dir" done - LS_ARGS="$LS_ARGS $files" + LS_ARGS="$LS_ARGS -B $hostname $files" $DEBUG "LS_ARGS: $LS_ARGS" } diff --git a/bin/rcup.in b/bin/rcup.in index 849a0f7..8e541e8 100755 --- a/bin/rcup.in +++ b/bin/rcup.in @@ -104,10 +104,12 @@ handle_command_line() { local includes= local always_copy=0 local symlink_dirs= + local hostname= REPLACE_ALL=0 - while getopts CVqvfhikKI:x:S:t:d: opt; do + while getopts CVqvfhikKI:x:S:t:d:B: opt; do case "$opt" in + B) hostname="$OPTARG" ;; C) always_copy=1 ;; d) dotfiles_dirs="$dotfiles_dirs $OPTARG" ;; f) REPLACE_ALL=1 ;; @@ -132,6 +134,7 @@ handle_command_line() { fi handle_common_flags rcup $version $verbosity + hostname="$(determine_hostname "$hostname")" tags="${arg_tags:-$TAGS}" DOTFILES_DIRS="${dotfiles_dirs:-$DOTFILES_DIRS}" @@ -153,7 +156,7 @@ handle_command_line() { for symlink_dir in $symlink_dirs; do LS_ARGS="$LS_ARGS -S $symlink_dir" done - LS_ARGS="$LS_ARGS $files" + LS_ARGS="$LS_ARGS -B $hostname $files" $DEBUG "LS_ARGS: $LS_ARGS" } -- cgit v1.2.3