append a line to a repo file only if it does not already exist

This commit is contained in:
erxspin 2017-02-20 07:20:54 +06:00
parent fbdca20dee
commit 0cb4e3d23d
1 changed files with 17 additions and 1 deletions

View File

@ -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