From cfa545394d1579419bf1392a5f1e9ebbefff9579 Mon Sep 17 00:00:00 2001 From: Michael Wolf Date: Wed, 12 Aug 2020 13:46:21 -0500 Subject: [PATCH] Create and document basic installation script --- README.md | 29 +++++++++++++++++++++++++++++ install.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100755 install.sh diff --git a/README.md b/README.md index 6e65757..96791aa 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,35 @@ would-reformat - automatic reformatting for emacs without being annoying # Installation +- Change to the directory where you would want to use **would-reformat**: + `$ cd ~/devel/my-project` +- From that directory, call the script `install.sh` in the directory where + you have **would-reformat** checked out: + `you@host:~/devel/my-project $ ~/src/would-reformat/install.sh` + +This will do the following: + +- create the directory `~/devel/my-project/bin` if it does not exist +- create `~/devel/my-project/_reformat-common.sh`, + `~/devel/my-project/do-reformat.sh`, and + `~/devel/my-project/bin/would-reformat.sh` as symlinks to files with + the same names in `~/src/would-reformat`. +- create `~/devel/my-project/.dir-locals.el` as a symlink to the file + with the same name in `~/src/would-reformat`. + +This should work from a checkout wherever you happen to have it. It doesn't +need to be in `~/src`. However, if you remove the checkout, then the symlinks +will break, so don't do that. If you rename the checkout, the symlinks will break. + +The directory `bin` with respect to `my-project` however is hardcoded +(enhancements here are welcome). + +The script `install.sh` favors conservatism over being clever: for example, +if it finds the file `~/devel/my-project/bin/do-reformat.sh` then it +checks whether it is a symlink to `~/src/would-reformat/do-reformat.sh`. +If it is not, then it just prints a warning rather than attempting to correct +the situation. + # Development diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..54093d4 --- /dev/null +++ b/install.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +set -uo pipefail +IFS=$'\n\t' + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +here=$(pwd) + +ret=0 + +# If this use of readlink breaks, see +# https://unix.stackexchange.com/questions/47710/find-only-destination-of-symlink +# for discussion of alternatives. + +for i in _reformat-common.sh do-reformat.sh would-reformat.sh; do + if [[ -f "$here"/bin/"$i" ]] ; then + dest=$(readlink bin/$i) + if [[ x"$dest" == x"$DIR/$i" ]] ; then + echo $i is in place, good + else + echo $i exists but it is not a symlink or does not point to the right place + echo If it is a symlink, it points to: $dest + echo "(If it doesn't point anywhere, then it probably is not a symlink)" + ret=1 + fi + else + # it doesn't exist; create it + echo setting $i up + mkdir -p $here/bin + ln -s $DIR/$i $here/bin/$i + fi +done + +if [[ -f $here/.dir-locals.el ]] ; then + dest=$(readlink .dir-locals.el) + if [[ x"$dest" == x"$DIR/_dir-locals.el" ]] ; then + echo .dir-locals.el is in place, good + else + echo .dir-locals.el exists but it is not a symlink or does not point to + echo the right place + echo + echo It is possible that you are using .dir-locals.el for other purposes, + echo in which case this is not really an error. + ret=1 + fi +else + echo setting .dir-locals.el up + ln -s $DIR/_dir-locals.el $here/.dir-locals.el +fi + +exit $ret