diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2022-11-11 23:32:12 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-11-12 11:23:53 -0700 |
commit | f223f38fcab3c94402603d1fadb2d6fa0ac3d05a (patch) | |
tree | 8036d67f8e96d335368d8b1ff19d3c98770fd754 /lib-src/mr | |
parent | 74585ec4711667c76ecdad7eb53590cb912501ba (diff) | |
download | dotfiles-f223f38fcab3c94402603d1fadb2d6fa0ac3d05a.tar.gz |
GNU Stow -> hstow, and follow-up tidying & simplifications
Diffstat (limited to 'lib-src/mr')
-rw-r--r-- | lib-src/mr/config | 175 | ||||
-rw-r--r-- | lib-src/mr/stow | 273 |
2 files changed, 25 insertions, 423 deletions
diff --git a/lib-src/mr/config b/lib-src/mr/config index 06af1b6e..9cd84fe2 100644 --- a/lib-src/mr/config +++ b/lib-src/mr/config @@ -23,6 +23,11 @@ git_isclean = git is-clean git_clean = git clean -xdff +stow = hstow stow "$MR_REPO" +unstow = hstow unstow "$MR_REPO" +restow = hstow restow "$MR_REPO" +adopt = hstow adopt "$MR_REPO" + # --- Plugin for dgit repos # actually shipped with upstream mr, but use an include command that @@ -40,17 +45,6 @@ include = cat ~/src/dotfiles/lib-src/mr/dgit # after we include the dgit lib, which also redefines git_update) git_update = git pull-safe -# --- Adam Spiers' plugin for managing dotfile symlinks with mr - -# actually shipped with upstream mr, but use an include command that -# will always work -include = - # stow is not available on Windows - if [ -e "$HOME/src/dotfiles/lib-src/mr/stow" ] \ - && ! [ "$(perl -e 'print $^O')" = "msys" ]; then - cat "$HOME/src/dotfiles/lib-src/mr/stow" - fi - # --- joeyh's code for specifying what machine we're on for repo skip # --- tests, plus my code for detecting Git-on-Windows @@ -106,66 +100,6 @@ lib = # --- standard procedures lib = - homedir_mkdirs() { - ( - cd $HOME - mkdir -p \ - .ssh \ - tmp \ - src \ - lib \ - mnt \ - local/mutt \ - local/src \ - local/bin \ - local/big \ - local/lib \ - local/log \ - local/pub \ - local/tmp \ - local/auth \ - local/info - # lib/athena \ - # lib/backup \ - # local/anacron/spool \ - chmod 700 local/auth - # [ -L "src/build-area" ] || ln -s -T /tmp/debuild src/build-area - [ -e "Downloads" ] || ln -s tmp Downloads - # clean up after additions to .stow-local-ignore - find bin lib -type l 2>/dev/null | while read -r link; do - if readlink "$link" | grep --quiet "^[../]*/.STOW/"; then - rm "$link" - fi - done - # cleanup some old dirs if they're empty - find \ - bin \ - lib/aid \ - lib/backup \ - lib/perl5 \ - lib/hooks \ - lib/athena \ - lib/bins \ - lib/img \ - lib/mr \ - lib/src \ - local/anacron/spool \ - -type d -empty -delete 2>/dev/null ||: - ) - } - # specify files that should automatically be adopted because - # programs convert them from symlinks to regular files. Arguments - # to this function should be paths relative to the stow target - # (usually $HOME) - always_adopt () { - for f in $@; do - if ! [ -L "$STOW_TARGET/$f" ]; then - # ignore errors; if it doesn't work, the user will - # have to fix up manually - mv 2>/dev/null "$STOW_TARGET/$f" "$MR_REPO/$f" || true - fi - done - } # export plain text Org agenda in post_ hooks of ~/doc repo (not currently used) export_org_agenda () { if on athena; then @@ -179,72 +113,18 @@ lib = # --- primary dotfiles repository -# TODO we need to unstow before switching branches, and stow -# afterwards, or else do some sort of automatic cleanup of dangling -# symlinks before a restow, so a broken situation is easy to fix? -# Also see kill-broken-stowed-symlink() in .bashrc. -# -# Note that the scan is expensive. So actually we probably don't want -# the cleanup to happen automatically. Also, it should exclude -# lib/annex, src/*/ (but not src/) because I don't stow files into -# those dirs. -# -# Maybe just run it as part of sysmaint -# -# Hmm. Situation is not as bad as I thought. stow manages to clean -# up quite a few of the symlinks. So running it as part of sysmaint -# seems like a sufficient fix - [src/dotfiles] checkout = git clone https://git.spwhitton.name/dotfiles.git dotfiles -stowable = true -# we have a script to update master, and all other branches should -# only be checked out and committed to on a single host +# We have a script to update master, and all other branches should be checked +# out and committed to on only a single host, so no need to pull them, and +# they'll always be rebaseable. update = git dotfiles-update-master -push = git push origin master -# use `git dotfiles-rebase` instead -# rebase = -# # usual rebasing pattern. Per dotfiles repo policy (excluding -# # win32 case), the branch being rebased will always be rebaseable -# # on master, since it is only checked out and committed to on this -# # host -# branch="$(git rev-parse --abbrev-ref HEAD)" -# hostname="$(hostname -s)" -# if [ "$branch" = "win32" -o "$branch" = "$hostname" -o "$branch" = "develacc-$hostname" ]; then -# git rebase master -# fi -fixups = - # Use a rebase workflow as I'm the only committer - git config pull.rebase true - # Pushing and pulling are always done explicitly - for head in $(git for-each-ref --format='%(refname)' refs/heads/); do - branch=$(echo "$head" | cut -d/ -f3) - git branch --unset-upstream "$branch" 2>/dev/null || true - done - git config push.default nothing - # this is just for M-x magit-status - git config remote.pushDefault origin - # - homedir_mkdirs - chmod -Rf u+rwX,go= $HOME/local/auth/* || true - # eventually move the following two lines from fixups to post_checkout - install-git-hooks dotfiles - git config user.signingkey 8DC2487E51ABDD90B5C4753F0F56D0553B6D411B - # eventually drop this - rm -f .git/hooks/post-checkout{,_01gpgsign} - -# clean-ups so that initial stow will be successful -pre_stow = - homedir_mkdirs - $HOME/src/dotfiles/bin/unskel - # these will often end up created, e.g. by insinuate-dotfiles script - rm -f $HOME/.gnupg/{gpg.conf,gpg-agent.conf,dirmngr.conf,.gpg-v21-migrated} - -# this file frequently gets desymlinked -pre_unstow_append = always_adopt .config/mimeapps.list -pre_restow_append = always_adopt .config/mimeapps.list -pre_stow_append = always_adopt .config/mimeapps.list -pre_update_append = always_adopt .config/mimeapps.list +push = git dotfiles-rebase +# Restowing is expensive, and most dangling symlinks into ~/.STOW do no harm, +# so we leave it to be run manually -- bstraph stows but does not restow. +# Possibly restowing could be done by locmaint, or we could have hstow skip +# annex/ and src/, into which I don't stow anything. +fixups = bstraph # --- private dotfiles repositories @@ -252,7 +132,9 @@ pre_update_append = always_adopt .config/mimeapps.list checkout = git clone athenag:libpriv.git priv update = git annex sync --content cloud origin push = git annex sync --content cloud origin -stowable = true +post_update = + hstow stow ~/lib/priv + load-trustdb sync = mr autoci && git annex sync --no-commit --content cloud origin skip = lazy @@ -261,6 +143,11 @@ post_checkout = git annex init git annex enableremote cloud git annex group . backup + # Delete any pubring.kbx created by INSINUATE-DOTFILES Consfigurator + # property / 'insinuate-dotfiles' shell script: don't want to adopt it. + rm -f ~/.gnupg/pubring.kbx + hstow stow ~/lib/priv + load-trustdb fixups = chmod 600 .passwddb.pet \ @@ -282,21 +169,18 @@ fixups = git config mrrepo.review-unused false autoci = + hstow stow ~/lib/priv # to perform adoptions git annex add .passwddb.pet .labbook.gpg .gnupg/pubring.kbx git commit -a -m \ "auto passwddb, pubring and labbook commit on $(hostname -s)" || true pre_update = mr autoci -# since dotfiles repo also stows into ~/.gnupg, and athpriv repo stows -# into ~/.duply, make the dirs first -pre_stow = homedir_mkdirs -post_stow = load-trustdb - [src/athpriv] checkout = git clone demeterp:athpriv athpriv pre_update = on athena || git annex sync origin athenah pre_push = on athena || git annex sync --content origin athenah -stowable = true +post_update = hstow stow ~/src/athpriv +post_checkout = hstow stow ~/src/athpriv skip = ! mine post_checkout = @@ -321,15 +205,6 @@ autoci = git annex add News/* git commit News -m"auto commit of Gnus score files" ||: -# since priv repo also stows into ~/.duply, make the dir first -pre_stow = homedir_mkdirs - -# r2e always desymlinks this file -pre_stow_append = always_adopt .config/rss2email.cfg -pre_unstow_append = always_adopt .config/rss2email.cfg -pre_restow_append = always_adopt .config/rss2email.cfg -pre_update_append = always_adopt .config/rss2email.cfg - # --- hosts configuration [src/propellor] diff --git a/lib-src/mr/stow b/lib-src/mr/stow deleted file mode 100644 index 254bd0c3..00000000 --- a/lib-src/mr/stow +++ /dev/null @@ -1,273 +0,0 @@ -# Plug-in to use GNU Stow to manage symlinks whose targets lie in a -# repository managed with myrepos -# -# The standard use case is for managing dotfiles inside one's home -# directory. -# -# Original author (2011): -# Adam Spiers <mr@adamspiers.org> -# -# This version reworked (2016, 2017) & maintained (2017) by: -# Sean Whitton <spwhitton@spwhitton.name> - -# BASIC USAGE INSTRUCTIONS -# -# To make mr use this file, add a line like this inside the [DEFAULT] -# section of your ~/.mrconfig: -# -# include = cat /usr/share/mr/stow -# -# and then inside each [repo] section of your ~/.mrconfig for -# which you want the contents to be stowed, add this line: -# -# stowable = true -# -# You must have at least version 2.1.0 of stow available. [1] -# -# If stow is not in your $PATH, you can export STOW_COMMAND to tell -# this plug-in where it is. -# -# The default behaviour is to stow on checkout, and restow on update. -# The manual actions 'stow', 'restow', 'unstow' and 'adopt' are also -# available. -# -# By default, ~/.STOW is used as the stow directory, and ~ as the -# target directory. You can export STOW_DIR and STOW_TARGET to -# override these defaults. -# -# DEALING WITH APPLICATIONS THAT MISTREAT SYMLINKS -# -# Some programs will replace a symlink to a stowed file with a regular -# copy of the file, and a subset of these will do this even if they -# haven't edited the file. This will cause stow operations to fail. -# -# To deal with this, run 'mr adopt'. This will move the modified file -# into your repository, and restore the usual symlink. Then you can -# use your VCS tools ('git diff', 'hg diff') to decide whether you -# want to keep the changes. -# -# FOLDING -# -# By default, this library passes --no-folding to stow. This allows -# you to have more than one repository stowing files into a single -# subdirectory in your home directory. For example, you might have a -# private and a public repository both stowing into ~/.gnupg. If you -# don't want this behaviour, set MR_FOLD. For example, in a -# repository's myrepos config section or in [DEFAULT]: -# -# lib = MR_FOLD= -# -# FIXUPS THAT CREATE FILES TO BE STOWED -# -# Stowing is automatically performed via post_checkout, and restowing -# via post_update, as can be seen from below (search for 'Automatic -# actions'). Note that these run before fixups, which allows fixups -# to refer to stowed files, but isn't ideal if the fixups are -# responsible for creating the stow package's installation image, -# e.g. via a typical './configure && make install' sequence. Here's a -# suggested mrconfig chunk to handle this particular use case: -# -# stowable = true -# lib = -# STOW_PKG_TYPE=directory -# STOW_NO_AUTOMATIC_ACTIONS=yes -# mr_pre_unstow () { -# install-info --delete --info-dir=$HOME/share/info $STOW_PKG_PATH/share/info/*.info -# } -# mr_post_stow () { -# install-info --info-dir=$HOME/share/info $STOW_PKG_PATH/share/info/*.info -# } -# fixups = -# if ! [ -e configure ]; then -# bash ./autogen.sh -# fi -# set_stow_common_opts -# ./configure --prefix=$STOW_PKG_PATH -# make install prefix=$STOW_PKG_PATH -# rm $STOW_PKG_PATH/share/info/dir -# mr_restow_regardless -# -# [1] Older versions could create a frankenstein ~/.git/ directory -# containing symlinks to multiple .git/ sub-directories in different -# stow packages! 2.1.0 onwards does not have this problem - it -# supports local per-directory .stow-local-ignore and global -# ~/.stow-global-ignore files, and even without configuration of -# these, it chooses sensible default ignore lists which prevent -# stowing of a package's .git/ sub-directory. These ignore lists are -# also ideal if you only want to stow a subset of a stow package's -# contents. - -lib = - : ${STOW_DIR:=$HOME/.STOW} - : ${STOW_TARGET:=$HOME} - STOW_NAME=$(echo "$MR_REPO" | tr / _) - # - if ! [ -d "$STOW_TARGET" ]; then mkdir -p "$STOW_TARGET"; fi - if ! [ -d "$STOW_DIR" ]; then mkdir -p "$STOW_DIR" ; fi - if ! [ -f "$STOW_DIR/.stow" ]; then touch "$STOW_DIR/.stow"; fi - # - #MR_STOWABLE=no - is_stowable () { - [ -z "$MR_DISABLE_STOW" ] && - ( cd "$MR_REPO" && mr stowable >/dev/null 2>&1 ) - #[ "$MR_STOWABLE" = yes ] - } - stowable_then_continue () { - if is_stowable; then - return 0 - else - if [ -n "$1" ]; then - info "$STOW_NAME isn't stowable; skipping $MR_ACTION" - fi - return 1 - fi - } - # - set_stow_common_opts () { - : ${STOW_PKG_TYPE:=symlink} - STOW_PKG_PATH="$STOW_DIR/$STOW_NAME" - # canonicalise -t and -d params with readlink if available - # stow can fail if they aren't canonical - if which readlink >/dev/null 2>&1; then - stow_common_opts="-t $(readlink -f $STOW_TARGET) -d $(readlink -f $STOW_DIR)" - else - stow_common_opts="-t $STOW_TARGET -d $STOW_DIR" - fi - STOW="${STOW_COMMAND:-$HOME/src/dotfiles/lib-src/stow/stow}" - case "`$STOW --version`" in - 'version 1.*') - stow_common_opts="$stow_common_opts -p" - ;; - *) - ;; - esac - if [ -n "$MR_STOW_OPTIONS" ]; then - stow_common_opts="$stow_common_opts $MR_STOW_OPTIONS" - fi - if [ -n "$MR_STOW_OVER" ]; then - stow_common_opts="$stow_common_opts --override=$MR_STOW_OVER" - fi - if ! (: "${MR_FOLD?}") 2>/dev/null; then - stow_common_opts="$stow_common_opts --no-folding" - fi - } - # - mr_stow () { - stowable_then_continue || return 0 - set_stow_common_opts - ensure_package_exists - command "$STOW" $stow_common_opts "$@" "$STOW_NAME" - mr_post_stow - info "Stowed $STOW_NAME" - } - mr_restow_if_already_stowed () { - stowable_then_continue || return 0 - if ! [ -L "$STOW_PKG_PATH" ]; then - info "$MR_REPO wasn't stowed yet; won't restow." - return - fi - mr_restow_regardless "$@" - } - mr_restow_regardless () { - stowable_then_continue || return 0 - set_stow_common_opts - ensure_package_exists - mr_pre_unstow - command "$STOW" -R $stow_common_opts "$@" "$STOW_NAME" - mr_post_stow - info "Restowed $STOW_NAME" - } - mr_pre_unstow () { - : # This can be "overridden" by the lib section of a repo definition - #info "no mr_pre_unstow hook" - } - mr_post_stow () { - : # This can be "overridden" by the lib section of a repo definition - #info "no mr_post_stow hook" - } - mr_unstow () { - stowable_then_continue || return 0 - set_stow_common_opts - if ! [ -d "$STOW_PKG_PATH" ]; then - info "$MR_REPO wasn't stowed yet in $STOW_PKG_PATH; can't unstow." - return - fi - mr_pre_unstow - command "$STOW" -D $stow_common_opts "$@" "$STOW_NAME" - if [ "$STOW_PKG_TYPE" = 'symlink' ]; then - rm -f "$STOW_PKG_PATH" - fi - info "Unstowed $STOW_NAME" - } - # - ensure_symlink_exists () { - [ $# = 2 ] || error "CONFIG BUG: Usage: ensure_symlink_exists SYMLINK TARGET" - symlink="$1" - required_target="$2" - if [ -L "$symlink" ]; then - actual_target="`readlink $symlink`" - if [ "$actual_target" = "$required_target" ]; then - return - else - error "Symlink $symlink already points to $actual_target, cannot point to $required_target; aborting." - fi - fi - if [ -e "$symlink" ]; then - error "Cannot create symlink $symlink - already exists; aborting." - fi - ln -s "$required_target" "$symlink" - } - # - mr_adopt () { - stowable_then_continue || return 0 - set_stow_common_opts - ensure_package_exists - mr_pre_unstow - command "$STOW" --adopt $stow_common_opts "$@" "$STOW_NAME" - mr_post_stow - info "Stowed $STOW_NAME with adoption" - } - # - ensure_package_exists () { - case "$STOW_PKG_TYPE" in - symlink) - ensure_symlink_exists "$STOW_PKG_PATH" "$MR_REPO" - ;; - directory) - [ -e "$STOW_PKG_PATH" ] || mkdir "$STOW_PKG_PATH" - [ -d "$STOW_PKG_PATH" ] || error "Expected $STOW_PKG_PATH to be a directory; aborting." - if [ -L "$STOW_PKG_PATH" ]; then - error "Didn't expect $STOW_PKG_PATH to be a symlink; aborting." - fi - ;; - *) - error "Unrecognised value '$STOW_PKG_TYPE' for \$STOW_PKG_TYPE; aborting." - ;; - esac - } - -#stowable = is_stowable -stowable = false -showstowable = - if is_stowable; then - echo "$STOW_NAME is stowable" - else - echo "$STOW_NAME is not stowable" - fi - -# Automatic actions -post_checkout_append = [ -n "$STOW_NO_AUTOMATIC_ACTIONS" ] || mr_stow -#post_update_append = mr_restow_if_already_stowed -post_update_append = [ -n "$STOW_NO_AUTOMATIC_ACTIONS" ] || mr_restow_regardless - -# Manual actions -stow = mr_stow "$@" -stowover = MR_STOW_OVER=. mr_stow "$@" -unstow = mr_unstow "$@" -restow = mr_restow_regardless "$@" -restowover = MR_STOW_OVER=. mr_restow_regardless "$@" -adopt = mr_adopt "$@" - -# Local variables: -# mode: sh -# End: |