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

# Try to get my dotfiles onto a host, securely

# Intended for machines on which I don't have root -- otherwise I'd
# just use propellor

# Assumes ssh connection sharing

# TODO use technique in verifyOriginBranch from propellor

. $HOME/.shenv
. $HOME/lib/tputfs.sh

status "trying to clone dotfiles to $1 using git daemon protocol"

# post-end of support for jessie (git-verify-commit on jessie does not support --raw)
# ssh "$1" 'wget -O- https://spwhitton.name/spwhitton.asc | gpg --import'

ssh "$1" 'cd $HOME && git clone --depth 1 git://spwhitton.name/dotfiles src/dotfiles'

# pre-end of support for jessie
hash=$(ssh "$1" 'cd $HOME/src/dotfiles && git show-ref -s master | head -n1')
( cd "$HOME/src/dotfiles" && git branch --contains "$hash" | grep master)
# post-end of support for jessie
# ssh "$1" 'cd $HOME/src/dotfiles && git verify-commit --raw master 2>&1 | grep "VALIDSIG .* 8DC2487E51ABDD90B5C4753F0F56D0553B6D411B"'

if [ $? = 0 ]; then
    status "clone ok; running bootstrap script"
    ssh "$1" 'cd $HOME && sh src/dotfiles/bin/bstraph.sh'
else
    # pre-end of support for jessie
    status "couldn't find remote HEAD in local master branch"
    # post-end of support for jessie
    # status "couldn't verify PGP signature on dotfiles commit"

    status "nuking corrupted clone on $1"
    ssh "$1" 'rm -rf $HOME/src/dotfiles'
    exit 1
fi