summaryrefslogtreecommitdiff
path: root/bin/insinuate-dotfiles
blob: e6a0947fa2714d6cf9770de098a0d10b51cb62b1 (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
#!/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/>.



# Intended for machines on which I don't have root -- otherwise I'd
# just use propellor.  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

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.sh'