#!/bin/sh # insinuate-dotfiles -- try to get my dotfiles onto a host, securely # 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 # the Free Software Foundation, either version 3 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Replacement for COM.SILENTFLAME.CONSFIG::DOTFILES-INSINUATED for when I # 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 "$host" 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 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 ) remote_uid="$(ssh "$host" id -u)" main_opts="$([ "$remote_uid" = 0 ] && echo ozxf || echo zxf)" tar -C"$temp/.." -zcf - "$(basename $temp)" \ | ssh "$host" 'tar --strip-components=1 -Csrc/dotfiles -'$main_opts' -' rm -rf "$temp" # stow dotfiles into $HOME ssh "$host" "sh src/dotfiles/bin/bstraph" # copy my gpg key over there so I can use `mr up` to update dotfiles if ssh "$host" command -v gpg >/dev/null; then gpg --export-options export-minimal --export spwhitton@spwhitton.name \ | ssh "$host" gpg --import fi