Debian Codegraph @

scripts/debuerreotype-recalculate-epoch

raw
1 #!/usr/bin/env bash
2 set -Eeuo pipefail
3
4 thisDir="$(dirname "$(readlink -vf "$BASH_SOURCE")")"
5 source "$thisDir/.constants.sh" \
6 '<target-dir>' \
7 'rootfs'
8
9 eval "$dgetopt"
10 while true; do
11 flag="$1"; shift
12 dgetopt-case "$flag"
13 case "$flag" in
14 --) break ;;
15 *) eusage "unknown flag '$flag'" ;;
16 esac
17 done
18
19 targetDir="${1:-}"; shift || eusage 'missing target-dir'
20 [ -n "$targetDir" ]
21
22 # ideally this would use something like "apt-get indextargets" instead of hard-coding these particular "/var/lib/apt/lists" paths, but it doesn't include the Release files :(
23 # also a caution from DonKult: "the Release file might really be an InRelease file which failed signature checks"
24
25 shopt -s nullglob
26 releaseFiles=( "$targetDir"/var/lib/apt/lists/*_{In,}Release )
27 if [ "${#releaseFiles[@]}" -eq 0 ]; then
28 echo >&2 "error: no 'Release' files found at /var/lib/apt/lists in '$targetDir'"
29 echo >&2 " did you forget to populate 'sources.list' or run 'apt-get update' first?"
30 exit 1
31 fi
32
33 epoch="$(
34 awk -F ': ' '$1 == "Date" { printf "%s%c", $2, 0 }' "${releaseFiles[@]}" \
35 | xargs -r0n1 date '+%s' --date \
36 | sort -un \
37 | tail -1
38 )"
39 echo "$epoch" > "$targetDir/debuerreotype-epoch"