From df29698f530357f9419cb72e70a808f93235e915 Mon Sep 17 00:00:00 2001 From: Mike Burns Date: Tue, 12 Aug 2014 13:28:04 +0200 Subject: Generate an installation script This commit adds a `-g` flag to rcup(1) to generate a standalone shell script. This shell script can then be run again, even on different computers, to recreate the symlinks. This allows people to recreate the "download my dotfiles and run ./install.sh" instructions, but with generated code that they do not need to maintain. This provides us more freedom with lsrc(1): since rcm can be used to generate a universal shell script, lsrc(1) now can be harder to install -- it can depend on a compiler, for example -- because you only need to install it on one machine. The generated script is rather limited; this can be improved in future commits, as desired. --- bin/rcup.in | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 108 insertions(+), 11 deletions(-) (limited to 'bin/rcup.in') diff --git a/bin/rcup.in b/bin/rcup.in index 1823099..80e55f3 100755 --- a/bin/rcup.in +++ b/bin/rcup.in @@ -3,24 +3,107 @@ : ${RCM_LIB:=$(dirname "$0")/../share/rcm} . "$RCM_LIB/rcm.sh" +print_ln_v() { + $PRINT "handle_file_ln \"$1\" \"$2\"" +} + +print_cp_v() { + $PRINT "handle_file_cp \"$1\" \"$2\"" +} + +print_rm_v() { + : +} + link_or_copy() { $DEBUG "link_or_copy $1" local sigil="$1" if [ "x$sigil" = "xX" ]; then - echo "cp_v" + echo "$CP" else echo "$LN" fi } +print_generated_preface() { + cat < '\$2'" + \$DIRNAME "\$2" | \$XARGS \$MKDIR -p + \$CP -R "\$1" "\$2" +} +handle_file_ln() { + if [ -e "\$2" ]; then + printf "%s " "overwrite \$2? [yN]" + read overwrite + case "\$overwrite" in + y) + \$RM -rf "\$2" + ;; + *) + echo "skipping \$2" + return + ;; + esac + fi + verbose "'\$1' -> '\$2'" + \$DIRNAME "\$2" | \$XARGS \$MKDIR -p + \$LN -sf "\$1" "\$2" +} +PREFACE +} + link_file() { local src="$1" local dest="$2" local sigil="$3" if [ -h "$dest" ]; then - rm_v -f "$dest" + $RM -f "$dest" fi action="$(link_or_copy "$sigil")" @@ -35,7 +118,7 @@ replace_file() { $DEBUG replace_file "$1" "$2" $3 - rm_v -rf "$dest" + $RM -rf "$dest" link_file "$src" "$dest" "$sigil" } @@ -56,13 +139,14 @@ handle_dir() { } handle_file() { - local src="$1" - local dest="$2" - local sigil="$3" + local generate="$1" + local src="$2" + local dest="$3" + local sigil="$4" - $DEBUG "handle_file $1 $2 $3" + $DEBUG "handle_file $1 $2 $3 $4" - if [ -e "$dest" ]; then + if [ "$generate" -ne 1 -a -e "$dest" ]; then if is_identical "$src" "$dest"; then $VERBOSE "identical $dest" elif [ $REPLACE_ALL -eq 1 ]; then @@ -106,14 +190,18 @@ handle_command_line() { local symlink_dirs= local never_symlink_dirs= local hostname= + local generate=0 + local args=$* REPLACE_ALL=0 + GENERATE= - while getopts :CVqvfhikKI:x:S:s:t:d:B: opt; do + while getopts :CVqvfghikKI:x:S: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 ;; + g) generate=1 ;; h) show_help ;; i) REPLACE_ALL=0 ;; I) includes="$includes $OPTARG" ;; @@ -132,9 +220,18 @@ handle_command_line() { shift $(($OPTIND-1)) LN="ln_v" + CP="cp_v" + RM="rm_v" if [ $always_copy -eq 1 ]; then - LN="cp_v" + LN="$CP" + fi + if [ "$generate" -eq 1 ]; then + LN="print_ln_v" + CP="print_cp_v" + RM="print_rm_v" + print_generated_preface $args fi + GENERATE="$generate" handle_common_flags rcup $version $verbosity hostname="$(determine_hostname "$hostname")" @@ -191,7 +288,7 @@ for dest_and_src in $dests_and_srcs; do handle_dir "$dest" fi - handle_file "$src" "$dest" "$sigil" + handle_file "$GENERATE" "$src" "$dest" "$sigil" done run_hooks post up -- cgit v1.2.3