summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2023-01-25 14:48:02 -0700
committerSean Whitton <spwhitton@spwhitton.name>2023-01-25 15:01:23 -0700
commit763bf6b3752231ea0af19b665b61eee9f9a39619 (patch)
tree2c45f9ff904210631c96736ba224e959ac20f172 /bin
parent62d54deaaf8c3f77848b146569af873feea10123 (diff)
downloaddotfiles-763bf6b3752231ea0af19b665b61eee9f9a39619.tar.gz
insinuate-dotfiles: implement updates
These updates don't require that Git is available on the remote side.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/insinuate-dotfiles65
1 files changed, 45 insertions, 20 deletions
diff --git a/bin/insinuate-dotfiles b/bin/insinuate-dotfiles
index 2c0616aa..7465a735 100755
--- a/bin/insinuate-dotfiles
+++ b/bin/insinuate-dotfiles
@@ -2,7 +2,7 @@
# insinuate-dotfiles -- try to get my dotfiles onto a host, securely
-# Copyright (C) 2017-2019 Sean Whitton
+# Copyright (C) 2017-2019, 2023 Sean Whitton
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -20,41 +20,66 @@
# Replacement for COM.SILENTFLAME.CONSFIG::DOTFILES-INSINUATED for when I
-# can't access my consfig locally. Possible additional functionality would be
-# to do an update of what's already there, but this will be much slower over
-# sshfs than the following, which should copy files in just one direction
-
-# Enhancement: When don't have git on remote and src/dotfiles does not exist,
-# copy over .bashrc, .inputrc, .profile, .shinit, .emacs.d and maybe more,
-# unconditionally (i.e. overwrite what's there, in case want to update to a
-# newer version). Maybe confirm that I want to do that before copying, in
-# case what I would prefer is just to go and install git on the remote
-# machine.
+# can't access my consfig locally. For tightly space-constrained hosts, we
+# might want a feature to just copy over .bashrc, .inputrc, .profile, .shinit,
+# .emacs.d and maybe more, overwriting what's already there.
+#
+# A very slow alternative to --update, for hosts without Git, is to mount with
+# sshfs and then can use the local installation of Git to update.
set -e
+getopt=$(getopt -s bash -o "" -n insinuate-dotfiles -l update -- "$@")
+eval set -- "$getopt"
+update=false
+while true; do
+ case "$1" in
+ --update) update=true; shift; continue ;;
+ --) shift; break ;;
+ esac
+done
+[ $# -eq 1 ] || { echo >&2 "usage: insinuate-dotfiles [--update] [USER@]HOST"
+ exit 1; }
+host=$1
+
# assume connection sharing is set up in ~/.ssh/config
-ssh -fN "$1"
+ssh -fN "$host"
-if ssh "$1" "test -d src/dotfiles"; then
- echo >&2 "src/dotfiles exists"
- exit 1
+if ssh "$host" "test -d src/dotfiles"; then
+ if $update \
+ || { mr_out="$(ssh -t "$host" \
+ src/dotfiles/bin/mr -m -d src/dotfiles status)"
+ mr_exit=$?
+ [ $mr_exit -eq 0 -a -z "$mr_out" ]; }; then
+ ssh "$host" \
+ "rm -rf src/dotfiles/* src/dotfiles/.[!.]* src/dotfiles/..?*"
+ else
+ printf >&2 "%s\n\n" "$mr_out"
+ if [ $mr_exit -eq 0 ]; then
+ echo >&2 "src/dotfiles exists;"\
+ "run again with --update to replace contents"
+ else
+ echo >&2 "remote 'mr status' for src/dotfiles exited non-zero"
+ fi
+ exit 1
+ fi
+else
+ ssh "$host" "mkdir -p src/dotfiles"
fi
-ssh "$1" "mkdir -p src/dotfiles"
temp="$(mktemp -d -p $HOME/tmp insinuate.XXX)"
git clone --no-hardlinks --depth 1 -o local -b master \
"file://$HOME/src/dotfiles" "$temp"
( cd "$temp" && git remote rm local && rm -rf .git/refs/remotes/local )
tar -C"$temp/.." -zcf - "$(basename $temp)" \
- | ssh "$1" 'tar --strip-components=1 -Csrc/dotfiles -zxf -'
+ | ssh "$host" 'tar --strip-components=1 -Csrc/dotfiles -zxf -'
rm -rf "$temp"
# stow dotfiles into $HOME
-ssh "$1" "sh src/dotfiles/bin/bstraph"
+ssh "$host" "sh src/dotfiles/bin/bstraph"
# copy my gpg key over there so I can use `mr up` to update dotfiles
-if ssh "$1" command -v gpg >/dev/null; then
+if ssh "$host" command -v gpg >/dev/null; then
gpg --export-options export-minimal --export spwhitton@spwhitton.name \
- | ssh "$1" gpg --import
+ | ssh "$host" gpg --import
fi