Debian Codegraph @

pg_updateaptconfig

raw
1 #!/bin/sh
2
3 # Tell apt which PostgreSQL versions have clusters present
4
5 set -eu
6
7 APTCONFDIR="/etc/apt/apt.conf.d"
8 [ -d "$APTCONFDIR" ] || exit 0 # skip generation on RPM systems
9 APTCONF="$APTCONFDIR/02autoremove-postgresql"
10 TMPCONF="$(mktemp --tmpdir pg_updateaptconfig.XXXXXX)"
11 trap "rm -f $TMPCONF" EXIT
12
13 cat > $TMPCONF <<EOF
14 // DO NOT EDIT!
15 // File maintained by /usr/share/postgresql-common/pg_updateaptconfig.
16 //
17 // Mark all PostgreSQL packages as NeverAutoRemove for which PostgreSQL
18 // clusters exist. This is especially important when the "postgresql" meta
19 // package changes its dependencies to a new version, which might otherwise
20 // trigger the old postgresql-NN package to be automatically removed, rendering
21 // the old database cluster inaccessible.
22
23 APT
24 {
25 NeverAutoRemove
26 {
27 EOF
28
29 pg_lsclusters -h | cut -d ' ' -f 1 | uniq | while read version; do
30 echo " \"^postgresql.*-$version\";" >> $TMPCONF
31 done
32
33 cat >> $TMPCONF <<EOF
34 };
35 };
36 EOF
37
38 if ! cmp --silent $TMPCONF $APTCONF; then
39 cp $TMPCONF $APTCONF
40 chmod 444 $APTCONF
41 fi