#!/bin/sh # script to add apt.postgresql.org to sources.list # Copyright (C) 2013-2020 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.list" DEB_SRC="#deb-src" COMPONENTS="main" PGDG="pgdg" while getopts "c:f: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 i) INSTALL="yes" ;; # install packages for version given with -v p) PURGE="yes" ;; # purge existing postgresql packages s) DEB_SRC="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" # lsb_release is the best interface, but not always available if [ -z "$CODENAME" ]; then CODENAME=$(lsb_release -cs 2>/dev/null) fi # parse os-release if [ -z "$CODENAME" -a -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 # guess from sources.list if [ -z "$CODENAME" ]; then CODENAME=$(grep '^deb ' /etc/apt/sources.list | head -n1 | awk '{ print $3 }') fi # complain if no result yet if [ -z "$CODENAME" ]; then cat < $SOURCESLIST <