From 4ea27075916eea2c404fa070fbdba6652e7e0d3f Mon Sep 17 00:00:00 2001 From: Fernando Ike Date: Sat, 11 Jul 2015 15:20:38 -0300 Subject: [PATCH] more package friendly and fix tests --- actions/uninstall | 6 +- bin/pgvm | 1 + bin/pgvm-self-install | 15 ++++- include/helpers | 20 ++++-- test/pgvm_comment_test.sh | 125 +++++++++++++++++++------------------- 5 files changed, 95 insertions(+), 72 deletions(-) diff --git a/actions/uninstall b/actions/uninstall index a10434a..ae1c044 100644 --- a/actions/uninstall +++ b/actions/uninstall @@ -79,7 +79,7 @@ remove() rm -rf ${pgvm_environments}/* if [ $purge -eq 1 ] then - rm -rf $pgvm_home/src/* + rm -rf $pgvm_src/* fi break elif [ -d $pgvm_home/environments/$version ] @@ -105,7 +105,7 @@ remove() if [ $purge -eq 1 ] then - rm -rf $pgvm_home/src/postgresql-$version* + rm -rf $pgvm_src/postgresql-$version* fi break else @@ -119,7 +119,7 @@ remove() uninstall() { VERSIONS=$($LS -1 $pgvm_home/environments/ 2> /dev/null | grep -v current) - SOURCES=$($LS -1 $pgvm_home/src/ 2> /dev/null) + SOURCES=$($LS -1 $pgvm_src/ 2> /dev/null) version=$1 shift diff --git a/bin/pgvm b/bin/pgvm index 518c451..83ddae4 100755 --- a/bin/pgvm +++ b/bin/pgvm @@ -23,6 +23,7 @@ source $pgvm_home/include/helpers +verify_env_vars load_conf action=$1 diff --git a/bin/pgvm-self-install b/bin/pgvm-self-install index aa4ad1d..7b9cb3d 100755 --- a/bin/pgvm-self-install +++ b/bin/pgvm-self-install @@ -38,6 +38,12 @@ clone_repo() } +copy_repo() +{ + from_dir=${1} + cp -a $from_dir $pgvm_home +} + update_repo() { cd $pgvm_home @@ -73,11 +79,12 @@ set_bash_env() cat > ${pgvm_home}/pgvm_env </dev/null && grep -i postgresql README &>/dev/null && git status &>/dev/null } checkout_postgres() { version=$1 - pg_clone_dir=$pgvm_home/src/postgresql-clone + pg_clone_dir=$pgvm_src/postgresql-clone cd $pg_clone_dir && git checkout $version &>/dev/null && git clean -f &>/dev/null [[ $? -eq 1 ]] && echo "the branch '$version' seems to be invalid." && exit 1 @@ -168,7 +176,7 @@ checkout_postgres() clone_postgres() { - pg_dest_dir=$pgvm_home/src + pg_dest_dir=$pgvm_src pg_url=$(git_repo_url $version) echo "getting postgres from '$pg_url'" @@ -191,7 +199,7 @@ get_postgres() version=$(download http://www.postgresql.org/versions.rss - | grep "is the latest release in the" | sed -E "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_dest_dir=$pgvm_src pg_url=$(postgres_download_url $version) mkdir -p $pg_dest_dir @@ -216,7 +224,7 @@ get_postgres() extract_postgres() { version=${1:-$version} - pg_dest_dir=$pgvm_home/src + pg_dest_dir=$pgvm_src cd $pg_dest_dir @@ -231,7 +239,7 @@ compile_and_install_postgres() version=${1:-$version} configure_options=${CONFIG_OPTS} make_options=${MAKE_OPTS} - pg_dest_dir=$pgvm_home/src + pg_dest_dir=$pgvm_src if seems_to_be_from_repo $version then diff --git a/test/pgvm_comment_test.sh b/test/pgvm_comment_test.sh index 13b0ecf..e7cd1eb 100644 --- a/test/pgvm_comment_test.sh +++ b/test/pgvm_comment_test.sh @@ -1,11 +1,12 @@ ## prepare environment pgvm_home=`pwd` pgvm_home=${pgvm_home} +pgvm_src=${pgvm_home}/src pgvm_logs=${pgvm_home}/logs pgvm_clusters=${pgvm_home}/clusters pgvm_environments=${pgvm_home}/environments -export pgvm_home pgvm_logs pgvm_environments pgvm_clusters +export pgvm_home pgvm_src pgvm_logs pgvm_environments pgvm_clusters export PATH="/bin:/usr/bin:/sbin" export PATH=${pgvm_home}/bin:$PATH @@ -24,23 +25,23 @@ pgvm list pgvm install 9 #status=0 -#match=/^configuring PostgreSQL Version: 9.3.4 ... done.$/ +#match=/^configuring PostgreSQL Version: 9.4.4 ... done.$/ #match=/^compiling ... done.$/ #match=/^installing ... done.$/ -CONFIG_OPTS="--enable-cassert" pgvm install 8.4.21 +CONFIG_OPTS="--enable-cassert" pgvm install 8.4.22 #status=0 -#match=/^configuring PostgreSQL Version: 8.4.21 ... done.$/ +#match=/^configuring PostgreSQL Version: 8.4.22 ... done.$/ -${pgvm_environments}/8.4.21/bin/pg_config +${pgvm_environments}/8.4.22/bin/pg_config #status=0 #match=/--enable-cassert/ pgvm list #status=0 #match=/^PostgreSQL Installed Version:$/ -#match=/^ 9.3.4/ -#match=/^ 8.4.21/ +#match=/^ 9.4.4/ +#match=/^ 8.4.22/ ## testing uninstalled versions @@ -50,138 +51,138 @@ pgvm use 999 #match=/^version 999 is not installed$/ -## testing version 9.3.4 +## testing version 9.4.4 -pgvm use 9.3.4 +pgvm use 9.4.4 #status=0 -#match=/^switched to 9.3.4$/ +#match=/^switched to 9.4.4$/ pgvm current #status=0 -#match=/^9.3.4$/ +#match=/^9.4.4$/ pgvm list #status=0 #match=/^PostgreSQL Installed Version:$/ -#match=/^ => 9.3.4/ -#match=/^ 8.4.21/ +#match=/^ => 9.4.4/ +#match=/^ 8.4.22/ pgvm cluster list #status=1 -#match=/^there is no clusters in current environment \(9.3.4\)$/ +#match=/^there is no clusters in current environment \(9.4.4\)$/ pg_config --configure --version #status=0 -#match=/--prefix=.+\/environments/9.3.4/ -#match=/PostgreSQL 9.3.4/ +#match=/--prefix=.+\/environments/9.4.4/ +#match=/PostgreSQL 9.4.4/ psql --version #status=0 -#match=/^psql \(PostgreSQL\) 9.3.4$/ +#match=/^psql \(PostgreSQL\) 9.4.4$/ -## testing version 8.4.21 +## testing version 8.4.22 -pgvm use 8.4.21 +pgvm use 8.4.22 #status=0 -#match=/^switched to 8.4.21$/ +#match=/^switched to 8.4.22$/ pgvm current #status=0 -#match=/^8.4.21$/ +#match=/^8.4.22$/ pgvm list #status=0 #match=/^PostgreSQL Installed Version:$/ -#match=/^ 9.3.4/ -#match=/^ => 8.4.21/ +#match=/^ 9.4.4/ +#match=/^ => 8.4.22/ pgvm cluster list #status=1 -#match=/^there is no clusters in current environment \(8.4.21\)$/ +#match=/^there is no clusters in current environment \(8.4.22\)$/ pg_config --configure --version #status=0 -#match=/--prefix=.+\/environments/8.4.21/ +#match=/--prefix=.+\/environments/8.4.22/ #match=/--enable-cassert/ -#match=/PostgreSQL 8.4.21/ +#match=/PostgreSQL 8.4.22/ psql --version #status=0 -#match=/^psql \(PostgreSQL\) 8.4.21$/ +#match=/^psql \(PostgreSQL\) 8.4.22$/ -## testing clusters in 8.4.21 +## testing clusters in 8.4.22 pgvm cluster create test #status=0 -#match=/^initializing cluster in '.+\/clusters\/8.4.21\/test'... ok!$/ +#match=/^initializing cluster in '.+\/clusters\/8.4.22\/test'... ok!$/ pgvm cluster start test #status=0 -#match=/^starting cluster test@8.4.21$/ +#match=/^starting cluster test@8.4.22$/ pgvm cluster list #status=0 -#match=/^cluster in current environment \(8.4.21\):$/ +#match=/^cluster in current environment \(8.4.22\):$/ #match=/^ test is online at port 5433$/ pgvm cluster create latin1_cluster --encoding=latin1 --locale=en_US.iso8859-1 #status=0 -#match=/^initializing cluster in '.+\/clusters\/8.4.21\/latin1_cluster'... ok!$/ +#match=/^initializing cluster in '.+\/clusters\/8.4.22\/latin1_cluster'... ok!$/ -## testing clusters in 9.3.4 +## testing clusters in 9.4.4 -pgvm use 9.3.4 +pgvm use 9.4.4 #status=0 -#match=/^switched to 9.3.4$/ +#match=/^switched to 9.4.4$/ pgvm cluster list #status=1 -#match=/^there is no clusters in current environment \(9.3.4\)$/ +#match=/^there is no clusters in current environment \(9.4.4\)$/ pgvm cluster create my_cluster #status=0 -#match=/^initializing cluster in '.+\/clusters\/9.3.4\/my_cluster'... ok!$/ +#match=/^initializing cluster in '.+\/clusters\/9.4.4\/my_cluster'... ok!$/ pgvm cluster start my_cluster #status=0 -#match=/^starting cluster my_cluster@9.3.4$/ +#match=/^starting cluster my_cluster@9.4.4$/ pgvm cluster list #status=0 -#match=/^cluster in current environment \(9.3.4\):$/ +#match=/^cluster in current environment \(9.4.4\):$/ #match=/^ my_cluster is online at port 5435$/ pgvm cluster create my_another_cluster #status=0 -#match=/^initializing cluster in '.+\/clusters\/9.3.4\/my_another_cluster'... ok!$/ +#match=/^initializing cluster in '.+\/clusters\/9.4.4\/my_another_cluster'... ok!$/ pgvm cluster start my_another_cluster #status=0 -#match=/^starting cluster my_another_cluster@9.3.4$/ +#match=/^starting cluster my_another_cluster@9.4.4$/ pgvm cluster list #status=0 -#match=/^cluster in current environment \(9.3.4\):$/ +#match=/^cluster in current environment \(9.4.4\):$/ #match=/^ my_another_cluster is online at port 5436$/ #match=/^ my_cluster is online at port 5435$/ ## testing stopping cluster -pgvm use 8.4.21 +pgvm use 8.4.22 pgvm cluster stop test #status=0 -#match=/stopping cluster test@8.4.21/ +#match=/stopping cluster test@8.4.22/ -pgvm use 9.3.4 +pgvm use 9.4.4 pgvm cluster stop my_cluster #status=0 -#match=/stopping cluster my_cluster@9.3.4/ +#match=/stopping cluster my_cluster@9.4.4/ pgvm cluster stop my_another_cluster #status=0 -#match=/stopping cluster my_another_cluster@9.3.4/ +#match=/stopping cluster my_another_cluster@9.4.4/ pgvm cluster create to_be_removed pgvm cluster start to_be_removed @@ -191,8 +192,8 @@ pgvm cluster remove to_be_removed pgvm cluster remove to_be_removed --force #status=0 -#match=/stopping cluster to_be_removed@9.3.4/ -#match=/removing 'to_be_removed' directory '.+\/clusters\/9.3.4\/to_be_removed' ... ok/ +#match=/stopping cluster to_be_removed@9.4.4/ +#match=/removing 'to_be_removed' directory '.+\/clusters\/9.4.4\/to_be_removed' ... ok/ pgvm install master #status=0 @@ -240,35 +241,35 @@ pgvm cluster list #match=/^cluster in current environment \(a4c8f14\):$/ #match=/^ cl_test_other is online at port 5438$/ -echo "select version()" | pgvm console my_cluster@9.3.4 +echo "select version()" | pgvm console my_cluster@9.4.4 #status=1 #match=/the cluster 'my_cluster' seems to be offline/ -echo "select version()" | pgvm console test@8.4.21 +echo "select version()" | pgvm console test@8.4.22 #status=1 #match=/the cluster 'test' seems to be offline/ -pgvm use 9.3.4 +pgvm use 9.4.4 pgvm cluster start my_cluster -pgvm use 8.4.21 +pgvm use 8.4.22 pgvm cluster start test pgvm use master -echo "select version()" | pgvm console my_cluster@9.3.4 +echo "select version()" | pgvm console my_cluster@9.4.4 #status=0 -#match=/PostgreSQL 9.3.4/ +#match=/PostgreSQL 9.4.4/ -echo "select version()" | pgvm console test@8.4.21 +echo "select version()" | pgvm console test@8.4.22 #status=0 -#match=/PostgreSQL 8.4.21/ +#match=/PostgreSQL 8.4.22/ -pgvm use 9.3.4 +pgvm use 9.4.4 echo "select version()" | pgvm console my_cluster #status=0 -#match=/PostgreSQL 9.3.4/ +#match=/PostgreSQL 9.4.4/ echo "select version()" | pgvm console #status=0 -#match=/PostgreSQL 9.3.4/ +#match=/PostgreSQL 9.4.4/ pgvm cluster stop my_cluster @@ -276,10 +277,10 @@ echo "select version()" | pgvm console #status=1 #match=/please, choose a cluster to connect/ -pgvm use 8.4.21 +pgvm use 8.4.22 echo "select version()" | pgvm console test #status=0 -#match=/PostgreSQL 8.4.21/ +#match=/PostgreSQL 8.4.22/ pgvm cluster stop test pgvm install REL9_3_STABLE