summaryrefslogtreecommitdiff
path: root/repo/promote
blob: 8c092332f9a81097abb4bc5417bd76c026bdad70 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh

set -eu

#DEBUG=1

# read pgapt config
for dir in . .. /srv/apt; do
  test -f $dir/pgapt.conf || continue
  . $dir/pgapt.conf
  break
done

[ "$USER" = "aptuser" ] || SUDO="sudo -u aptuser"
export REPREPRO_BASE_DIR="/srv/apt/repo"
REPREPRO="flock $REPREPRO_BASE_DIR/db/.lock /usr/bin/reprepro -b $REPREPRO_BASE_DIR --morguedir $REPREPRO_BASE_DIR/morgue --verbose"
DISTS="all"
COMPONENT="main"

if [ "${DEBUG:-}" ]; then
	SUDO="echo"
fi

while getopts "c:d:efq" opt ; do
	case $opt in
		c) COMPONENT="$OPTARG" ;; # check this component to determine if packages exists
		d) DISTS="$OPTARG" ;; # promote these dists only
		e) REPREPRO="$REPREPRO --export=never" ;; # skip "reprepro export"
		f) FORCE="force" ;; # ignore server packages component mismatch
		q) QUIET="quiet" ;; # don't send announcement mail
		*) exit 5 ;;
	esac
done
# shift away args
shift $(($OPTIND - 1))

PKG="$1"
[ "$DISTS" = "all" ] && DISTS="$PG_SUPPORTED_DISTS"
set -- $DISTS
FIRST_DIST="$1"

# server packages: test .deb files for correct components
if [ -z "${FORCE:-}" ]; then
  case $PKG in
    postgresql-?.?|postgresql-??)
      for DIST in $DISTS; do
	/srv/apt/repo/bin/validate-component \
	  /srv/apt/repo/dists/$DIST-pgdg-testing/*/binary-*/Packages
      done
      ;;
  esac
fi

NEWVERSION=$($REPREPRO -A source list $FIRST_DIST-pgdg-testing "$PKG" | awk '{ print $3 }')
if [ -z "$NEWVERSION" ]; then
	echo "ERROR: $PKG does not seem to be a source package"
	exit 1
fi
INITIAL=$(echo $PKG | grep -Eo '^(lib)?.')
POOLDIR="/srv/apt/repo/pool/$COMPONENT/$INITIAL/$PKG"
if ! test -d $POOLDIR; then
  echo "$POOLDIR is missing (did you mean promote -c NN ?)"
  exit 1
fi
BINARIES=$(ls $POOLDIR/*deb | sed -e 's!.*/!!' -e 's/_.*//' | sort -u)
OTHERBINARIES=$(echo "$BINARIES" | while read b; do if [ "$b" != "$PKG" ]; then echo "$b"; fi; done)

if [ -z "${QUIET:-}" ]; then
OLDVERSION=$($REPREPRO -A source list $FIRST_DIST-pgdg "$PKG" | awk '{ print $3 }')
echo "Old status:"
OLDLS=$($REPREPRO ls $PKG; for p in $OTHERBINARIES; do $REPREPRO ls $p; done)
echo "$OLDLS"
OLDLSPROD=$(echo "$OLDLS" | grep -v -e pgdg-testing -e pgdg-snapshot | sed -e 's/   */ /g' | column -t -s '|' -o '|')
echo
fi

for DIST in $DISTS ; do
	${SUDO:-} $REPREPRO copysrc $DIST-pgdg $DIST-pgdg-testing $PKG
done

[ "${QUIET:-}" ] && exit

echo
echo "New status:"
NEWLS=$($REPREPRO ls $PKG; for p in $OTHERBINARIES; do $REPREPRO ls $p; done)
echo "$NEWLS"
NEWLSPROD=$(echo "$NEWLS" | grep -v -e pgdg-testing -e pgdg-snapshot | sed -e 's/   */ /g' | column -t -s '|' -o '|')
echo

if [ -z "${DEBUG:-}" ] && [ "$OLDLSPROD" = "$NEWLSPROD" ]; then
	echo "No change in the repository, not sending mail"
	exit
fi

NEWSHORTVERSION=$(echo "$NEWVERSION" | sed -e 's/.*://')

if [ "$OLDVERSION" ]; then
	SOMEDEB=$(ls $POOLDIR/*$NEWSHORTVERSION*deb | head -1)
	CHANGES=$(LANGUAGE= LANG=C.UTF-8 apt-listchanges -f text --which=both --since=$OLDVERSION $SOMEDEB | grep -Fv 'Reading changelogs...')
	CHANGESTEXT="$CHANGES"
else
	CHANGESTEXT="This is the first version of this package in the repository."
fi

echo "Sending mail to $MAILING_LIST ..."

TEXT="From: $MAIL_FROM
To: $MAILING_LIST
Reply-To: $MAILING_LIST
Subject: $PKG updated to version $NEWVERSION

The package $PKG was updated on apt.postgresql.org.

$CHANGESTEXT

New version $NEWVERSION:

$NEWLSPROD

The public mirrors serving apt.postgresql.org are synced hourly,
the updated packages will be available there shortly.
"
echo "$TEXT"
[ -z "${DEBUG:-}" ] && echo "$TEXT" | /usr/sbin/sendmail -t

exit 0