blob: 3accd676372efa85cb80d243cfc706ec00ede478 (
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#!/usr/bin/env bash
SCRIPTLOC="$(readlink -f "${BASH_SOURCE[0]%/*}")"
# for gpg's keys
export HOME="${SCRIPTLOC}/misc"
cd /export/gentoo-rsync/rsync0-prefix-tree/snapshots || exit 1
TODAY=$(date +%s)
YESTERDAY=$((TODAY - 86400))
RSYNCTREE=${PWD%/*}
SNAME=${PWD}/portage-$(date +%Y%m%d -d @${YESTERDAY}).tar
TMPDIR=${PWD}/tmp-prefix-snapshot
# clean up
find . -maxdepth 2 -daystart -ctime +4 -type f -exec rm '{}' +
# pull in active snapshot
BOOTSTRAP_SNAPSHOT=$( \
grep -A1 MKSNAPSHOT-ANCHOR "${RSYNCTREE}"/scripts/bootstrap-prefix.sh | \
sed -n 's/^.*PV="\([0-9]\+\)"\s*$/portage-\1.tar.bz2/p' \
)
if [[ ! -s "${BOOTSTRAP_SNAPSHOT}" ]] ; then
curl -s -L "https://distfiles.prefix.bitzolder.nl/prefix/distfiles/${BOOTSTRAP_SNAPSHOT}" > "${BOOTSTRAP_SNAPSHOT}"
fi
rm -Rf "${TMPDIR}"
mkdir -p "${TMPDIR}"
# quickly take a snapshot, such that we get a consistent image
pushd "${RSYNCTREE}" > /dev/null || exit 1
tar -cf "${SNAME}" --exclude=snapshots -- * || exit 1
popd > /dev/null || exit 1
# now revamp it such that it's in a directory "portage"
rm -Rf "${TMPDIR}"
mkdir -p "${TMPDIR}"
pushd "${TMPDIR}" > /dev/null || exit 1
mkdir portage
tar -xf "${SNAME}" -C portage/
tar --numeric-owner --format=posix --hard-dereference -cf "${SNAME}" portage/
popd > /dev/null || exit 1
rm -Rf "${TMPDIR}"
COMPRS=(
"gz:gzip -c -9"
"bz2:bzip2 -c -9"
"xz:xz -c -9"
"lz:lzip -c -9"
"zst:zstd -c -k -f -9"
)
# produce compressed variants, use as much cpu as left on the system, do
# all in parallel
for compr in "${COMPRS[@]}" ; do
read -r -a args <<< "${compr#*:}"
nice -n19 "${args[@]}" "${SNAME}" > "${SNAME}.${compr%%:*}" &
done
wait
# generate accompanying meta files
for compr in "${COMPRS[@]}" ; do
compr=${compr%%:*}
md5sum "${SNAME##*/}" > "${SNAME}.${compr}.umd5sum"
md5sum "${SNAME##*/}.${compr}" > "${SNAME}.${compr}.md5sum"
done
# create GPG detached signature, use passphrase-fd to pass password
gpgopts=(
"--quiet"
"--batch"
"--no-tty"
"--passphrase-fd" 0
"--pinentry-mode" "loopback"
"--default-key" "C6317B3C"
"--detach-sign"
"--armor"
)
for compr in "${COMPRS[@]}" ; do
compr=${compr%%:*}
gpg "${gpgopts[@]}" -o "${SNAME}.${compr}.gpgsig" "${SNAME}.${compr}" \
< "${SCRIPTLOC}"/autosigner.pwd
done
# we no longer need the (original/uncompressed) tar
rm "${SNAME}"
# make convenience symlinks
for compr in "${COMPRS[@]}" ; do
compr=${compr%%:*}
for f in "${compr}"{,.gpgsig,.md5sum,.umd5sum} ; do
rm "portage-latest.tar.${f}"
ln -s "${SNAME##*/}.${f}" "portage-latest.tar.${f}"
done
done
|