#!/bin/sh # script to add apt.postgresql.org to sources.list.d # Copyright (C) 2013-2022 Christoph Berg # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # The full text of the GPL is distributed as in # /usr/share/common-licenses/GPL-2 on Debian systems. SOURCESLIST="/etc/apt/sources.list.d/pgdg.sources" TYPES="deb" COMPONENTS="main" PGDG="pgdg" # variables imported from https://git.postgresql.org/gitweb/?p=pgapt.git;a=blob;f=pgapt.conf # checked out in $HOME/apt.postgresql.org/; run "make" to update PG_BETA_VERSION="" PG_DEVEL_VERSION="16" PG_REPOSITORY_DISTS="sid bookworm bullseye buster kinetic jammy focal bionic" PG_ARCHIVE_DISTS="sid bookworm bullseye buster stretch jessie wheezy squeeze lenny etch kinetic jammy impish hirsute groovy focal eoan disco cosmic bionic zesty xenial wily utopic saucy precise lucid" while getopts "c:f:h:ipstv:y" opt ; do case $opt in c) COMPONENTS="main $OPTARG" ;; # make these extra components available f) SOURCESLIST=$OPTARG ;; # sources.list filename to write to h) HOST="$OPTARG" ;; # hostname to use in sources.list i) INSTALL="yes" ;; # install packages for version given with -v p) PURGE="yes" ;; # purge existing postgresql packages s) TYPES="deb deb-src" ;; # include source repository as well t) PGDG="pgdg-testing" ;; # use *-pgdg or *-pgdg-testing v) PGVERSION="$OPTARG" ;; # set up sources.list to use this version (useful for beta/devel packages) y) ;; # don't ask for confirmation *) exit 5 ;; esac YES="yes" # don't ask for confirmation if any option is given done # shift away args shift $((OPTIND - 1)) # check options if [ "$INSTALL" ] && [ -z "$PGVERSION" ]; then echo "With -i, a version to install must be provided (-v)" exit 1 fi # codename from command line CODENAME="$1" # parse os-release if [ -z "$CODENAME" ] && [ -f /etc/os-release ]; then . /etc/os-release if [ "$VERSION_CODENAME" ]; then # added in buster/xenial CODENAME="$VERSION_CODENAME" else # Debian: VERSION="7.0 (wheezy)" # Ubuntu: VERSION="13.04, Raring Ringtail" # VERSION="18.04.1 LTS (Bionic Beaver)" CODENAME=$(echo $VERSION | sed -ne 's/.*(\(.*\)).*/\1/') # works on Debian only fi fi # try lsb_release if [ -z "$CODENAME" ] && command -v lsb_release >/dev/null; then CODENAME=$(lsb_release -cs 2>/dev/null) fi # guess from sources.list if [ -z "$CODENAME" ] && [ -f /etc/apt/sources.list ]; then CODENAME=$(grep '^deb ' /etc/apt/sources.list | head -n1 | awk '{ print $3 }') fi # complain if no result yet if [ -z "$CODENAME" ]; then cat < $KEYRING < $SOURCESLIST <> $SOURCESLIST <