Skip to content

Commit

Permalink
fixing duplicated code, refs #20, #8.
Browse files Browse the repository at this point in the history
  • Loading branch information
guedes committed Aug 4, 2012
1 parent ad78c16 commit 1c9df18
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions include/helpers
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

shopt -s expand_aliases

case $OSTYPE in
case $OSTYPE in
darwin*)
alias md5sum=create_osx_md5
;;
Expand Down Expand Up @@ -69,7 +69,7 @@ get_curl_cmd()
shift
file=$1
shift

parse_options $*

if [ ! -z $opt_silent ]
Expand Down Expand Up @@ -153,40 +153,36 @@ download()
get_postgres()
{
version=${1:-$version}
if [ $(echo $version|wc -c) -eq 4 ]
version_length=$(echo $version|wc -c)

if [ $version_length -eq 4 ]
then
version=$(download http://www.postgresql.org/versions.rss - | grep "is the latest release in the" | sed "s/^.*\([0-9]\.[0-9]\+\.[0-9]\+\) is the latest release in the \([0-9]\.[0-9]\+\).*/\1/" |grep $version)
elif [ $(echo $version|wc -c) -eq 2 ]
elif [ $version_length -eq 2 ]
then
version=$(download http://www.postgresql.org/versions.rss - | grep "is the latest release in the" | sed "s/^.*\([0-9]\.[0-9]\+\.[0-9]\+\) is the latest release in the \([0-9]\.[0-9]\+\).*/\1/" |grep ^"$version"|head -n1)
version=$(download http://www.postgresql.org/versions.rss - | grep "is the latest release in the" | sed "s/^.*\([0-9]\.[0-9]\+\.[0-9]\+\) is the latest release in the \([0-9]\.[0-9]\+\).*/\1/" |grep ^"$version"|head -n1)
fi


pg_dest_dir=$pgvm_home/src
pg_url=$(postgres_download_url $version)

mkdir -p $pg_dest_dir

cd $pg_dest_dir
echo -n "downloading '$pg_url', please be patient... "
download $pg_url postgresql-$version.tar.gz --silent --location --continue --check-timestamp
download $pg_url.md5 postgresql-$version.tar.gz.md5 --silent --location --continue --check-timestamp
echo "done."

if [ ! -e postgresql-$version.tar.gz ]; then
echo -n "downloading '$pg_url', please be patient... "
download $pg_url postgresql-$version.tar.gz --silent --location --continue --check-timestamp
download $pg_url.md5 postgresql-$version.tar.gz.md5 --silent --location --continue --check-timestamp
echo "done."
else
echo -n "checking 'postgresql-$version.tar.gz' integrity... "
echo -n "downloading '$pg_url', please be patient... "
download $pg_url postgresql-$version.tar.gz --silent --location --continue --check-timestamp
download $pg_url.md5 postgresql-$version.tar.gz.md5 --silent --location --continue --check-timestamp
echo "done."
fi

md5sum -c postgresql-$version.tar.gz.md5 >/dev/null 2>/dev/null
echo -n "checking 'postgresql-$version.tar.gz' integrity... "

[[ $? -ne 0 ]] && echo "ERRO: CHECKSUM of 'postgresql-$version.tar.gz' has failed! Aborting!" && exit 1
echo "done."
fi
md5sum -c postgresql-$version.tar.gz.md5 >/dev/null 2>/dev/null

[[ $? -ne 0 ]] && echo "ERRO: CHECKSUM of 'postgresql-$version.tar.gz' has failed! Aborting!" && rm postgresql-$version.tar.gz* && exit 1
echo "done."
}

extract_postgres()
Expand Down

0 comments on commit 1c9df18

Please sign in to comment.