From 0cb4e3d23de7fb7a2d9b6f1313f6d9f07d850c35 Mon Sep 17 00:00:00 2001 From: erxspin Date: Mon, 20 Feb 2017 07:20:54 +0600 Subject: [PATCH] append a line to a repo file only if it does not already exist --- debian/resources/postgres.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/debian/resources/postgres.sh b/debian/resources/postgres.sh index e20fa33..67bfe77 100755 --- a/debian/resources/postgres.sh +++ b/debian/resources/postgres.sh @@ -13,7 +13,23 @@ echo "Install PostgreSQL and create the database and users\n" #apt-get install -y --force-yes sudo postgresql #postgres official repository -echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' >> /etc/apt/sources.list.d/pgdg.list +postgres_repo_url='deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' +postgres_repo_file='/etc/apt/sources.list.d/pgdg.list' + +#append a line to a file only if it does not already exist +#temp file +random=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64) +postgres_repo_tmp='/tmp/pgdg-'$random'.lst' +rm $postgres_repo_tmp + +#append a line +echo ''$postgres_repo_url'' >> $postgres_repo_file + +#delete duplicate, nonconsecutive lines from a file +awk '!seen[$0]++' $postgres_repo_file > $postgres_repo_tmp +cat $postgres_repo_tmp > $postgres_repo_file +rm $postgres_repo_tmp + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - apt-get update && apt-get upgrade -y apt-get install -y --force-yes sudo postgresql