summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorGravatar Mike Burns <mike@mike-burns.com>2014-08-12 13:28:04 +0200
committerGravatar Mike Burns <mike@mike-burns.com>2014-08-26 16:58:46 +0200
commitdf29698f530357f9419cb72e70a808f93235e915 (patch)
tree60df5953ee7dc0fa454f87b69bbef7b6e732dd6c /bin
parent8465d6a8d3568537f15688c66bc136a137e9c005 (diff)
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.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/mkrc.in4
-rwxr-xr-xbin/rcup.in119
2 files changed, 110 insertions, 13 deletions
diff --git a/bin/mkrc.in b/bin/mkrc.in
index 55a7cd8..8932926 100755
--- a/bin/mkrc.in
+++ b/bin/mkrc.in
@@ -101,8 +101,8 @@ for file in $files; do
dotless="$(de_dot "$file")"
dest="$(destination "$DOTFILES_DIR" "$dotless" $in_host "$tag")"
mkdir -p "$dest/$(dirname "$dotless")"
- $PRINT "Moving..."
+ $VERBOSE "Moving..."
mv_v "$file" "$dest/$dotless"
- $PRINT "Linking..."
+ $VERBOSE "Linking..."
$INSTALL -d "$DOTFILES_DIR" -t "${tag:--}" $install_args "$dotless"
done
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 <<PREFACE
+#!/bin/sh
+#
+# Usage:
+#
+# sh install.sh
+#
+# Environment variables: VERBOSE, CP, LN, MKDIR, RM, DIRNAME, XARGS.
+#
+# env VERBOSE=1 sh install.sh
+#
+# DO NOT EDIT THIS FILE
+#
+# This file is generated by rcm(7) as:
+#
+# rcup $@
+#
+# To update it, re-run the above command.
+#
+: \${VERBOSE:=0}
+: \${CP:=/bin/cp}
+: \${LN:=/bin/ln}
+: \${MKDIR:=/bin/mkdir}
+: \${RM:=/bin/rm}
+: \${DIRNAME:=/usr/bin/dirname}
+: \${XARGS:=/usr/bin/xargs}
+verbose() {
+ if [ "\$VERBOSE" -gt 0 ]; then
+ echo "\$@"
+ fi
+}
+handle_file_cp() {
+ 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
+ \$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