summaryrefslogtreecommitdiff
path: root/refresh_keys.sh
blob: 122b68d66385a33d614da996c7927f2cb40a24ff (plain) (blame)
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
#!/bin/bash

set -xeo pipefail

auth_key_file=${1:-~/.ssh/authorized_keys}

function main() {
    cd /tmp
    rm -rf /tmp/keys || true
    git clone --quiet https://code.liz.coffee/keys.git/
    cd keys
    echo "+ Cloned keys"

    gpg --status-fd 1 --verify authorized_keys.sig 2>/dev/null | grep VALIDSIG | grep -q "DC4323D1738F27358793D6E87BB52F7036FA7C18" || return 1
    echo "+ Validated"
    gpg --output authorized_keys --decrypt authorized_keys.sig 2>/dev/null || return 1
    echo "+ Decrypted"

    sed -i '/emprespresso/d' ~/.ssh/authorized_keys && grep -qv "emprespresso" ~/.ssh/authorized_keys  || mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys
    echo "+ Removed emprespresso keys"
    cat authorized_keys >> $auth_key_file
    echo "+ Appended emprespresso keys"

    cd /tmp
    rm -rf keys
    echo "+ Done"
}

function handle_error() {
    curl -d "ERROR IN UPDATING KEYS: $(cat /etc/hostname)" ntfy.sh/emprespresso-liz-dot-coffee
}

main || handle_error