summaryrefslogtreecommitdiff
path: root/test
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 /test
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 'test')
-rw-r--r--test/Makefile.am1
-rw-r--r--test/rcup-standalone.t75
2 files changed, 76 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index afa2631..aafa5ca 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -20,6 +20,7 @@ TESTS = \
rcrc.t \
rcup-link-files.t \
rcup-hostname.t \
+ rcup-standalone.t \
rcup-symlink-dirs.t \
rcup-usage.t
diff --git a/test/rcup-standalone.t b/test/rcup-standalone.t
new file mode 100644
index 0000000..7dd3b58
--- /dev/null
+++ b/test/rcup-standalone.t
@@ -0,0 +1,75 @@
+ $ . "$TESTDIR/helper.sh"
+
+-g generates a script
+
+ $ mkdir -p .dotfiles/eggplant_firetruck/lampshade
+ > touch .dotfiles/eggplant_firetruck/lampshade/bottle
+
+ $ rcup -g
+ #!/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 -g
+ #
+ # 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"
+ }
+ handle_file_ln "*eggplant_firetruck/lampshade/bottle" "*.eggplant_firetruck/lampshade/bottle" (glob)