blob: 681f976052c7c9aef15fda4563b62e09e1300daa (
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
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
62
63
64
65
66
67
68
69
70
71
72
73
|
{ pkgs, ... }:
let
inherit (pkgs) writeShellScript;
inherit (pkgs.lib.strings) makeBinPath;
in
{
install = writeShellScript "install-configs" ''
cd "$WPCARRO/configs" && ${pkgs.stow}/bin/stow --target="$HOME" .
'';
uninstall = writeShellScript "uninstall-configs" ''
cd "$WPCARRO/configs" && ${pkgs.stow}/bin/stow --delete --target="$HOME" .
'';
# Run this script to import all of the information exported by `export.sh`.
# Usage: import-gpg path/to/export.zip
import-gpg = writeShellScript "import-gpg" ''
set -euo pipefail
if [ -z "''${1+x}" ]; then
echo "You must specify the path to export.zip. Exiting..."
exit 1
fi
PATH="${makeBinPath (with pkgs; [ busybox gnupg ])}"
destination="$(mktemp -d)"
function cleanup() {
rm -rf "$destination"
}
trap cleanup EXIT
unzip "$1" -d "$destination" >/dev/null
gpg --import "$destination/public.asc"
gpg --import "$destination/secret.asc"
gpg --import-ownertrust "$destination/ownertrust.txt"
# Run this at the end to output some verification
gpg --list-keys
gpg --list-secret-keys
'';
# Run this script to export all the information required to transport your GPG
# information to a zip file.
# Usage: export-gpg
export-gpg = writeShellScript "export-gpg" ''
set -euo pipefail
PATH="${makeBinPath (with pkgs; [ busybox gnupg zip ])}"
output="$(pwd)/export.zip"
destination="$(mktemp -d)"
function cleanup() {
rm -rf "$destination"
}
trap cleanup EXIT
gpg --armor --export >"$destination/public.asc"
gpg --armor --export-secret-keys >"$destination/secret.asc"
gpg --armor --export-ownertrust >"$destination/ownertrust.txt"
# Strangely enough this appears to be the only way to create a zip of a
# directory that doesn't contain the (noisy) full paths of each item from
# the source filesystem. (i.e. -j doesn't cooperate with -r).
pushd "$destination"
zip -r "$output" ./*
popd
echo "$(realpath $output)"
'';
}
|