summaryrefslogtreecommitdiff
path: root/bin/insinuate-dotfiles
blob: d7ec917865c6971497c7e444b0ee0cabbf03d3bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh

# insinuate-dotfiles -- try to get my dotfiles onto a host, securely

# Copyright (C) 2017-2019 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 <http://www.gnu.org/licenses/>.



# 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, .shenv, .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.

set -e

. $HOME/.shenv

# assume connection sharing is set up in ~/.ssh/config
ssh -fN "$1"

if ssh "$1" "test -d src/dotfiles"; then
    echo >&2 "src/dotfiles exists"
    exit 1
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 -r .git/refs/remotes/local )
tar -C"$temp/.." -zcf - "$(basename $temp)" \
    | ssh "$1" 'tar --strip-components=1 -Csrc/dotfiles -zxf -'
rm -rf "$temp"

# copy my gpg key over there so I can use `mr up` to update dotfiles
if ssh "$1" which gpg >/dev/null; then
    gpg --export-options export-minimal --export spwhitton@spwhitton.name \
        | ssh "$1" gpg --import
fi
# stow dotfiles into $HOME
ssh "$1" 'sh src/dotfiles/bin/bstraph'