Make create-db and delete-db work with DBs on other hosts
Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
parent
706805d342
commit
70a36d805f
2 changed files with 55 additions and 6 deletions
48
create-db
48
create-db
|
@ -16,6 +16,8 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
root_path="$( cd "$(dirname "$0")" ; pwd -P )"
|
root_path="$( cd "$(dirname "$0")" ; pwd -P )"
|
||||||
|
auth=pw
|
||||||
|
hostname=localhost
|
||||||
|
|
||||||
first=1
|
first=1
|
||||||
while [[ $# -gt 0 ]]
|
while [[ $# -gt 0 ]]
|
||||||
|
@ -29,6 +31,23 @@ case $key in
|
||||||
shift # past value
|
shift # past value
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
-H|--host)
|
||||||
|
hostname="$2"
|
||||||
|
shift # past argument
|
||||||
|
shift # past value
|
||||||
|
;;
|
||||||
|
|
||||||
|
-s|--sudo)
|
||||||
|
auth=sudo
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
|
-p|--password)
|
||||||
|
export PGPASSWORD="$2"
|
||||||
|
shift # past argument
|
||||||
|
shift # past value
|
||||||
|
;;
|
||||||
|
|
||||||
-h|--help)
|
-h|--help)
|
||||||
echo "usage: create-db <database> [OPTIONS]"
|
echo "usage: create-db <database> [OPTIONS]"
|
||||||
echo "Creates and prepares the database for the use with osm2city"
|
echo "Creates and prepares the database for the use with osm2city"
|
||||||
|
@ -36,6 +55,9 @@ case $key in
|
||||||
echo "OPTIONS"
|
echo "OPTIONS"
|
||||||
echo " -u, --user User the database will be owned by."
|
echo " -u, --user User the database will be owned by."
|
||||||
echo " NOTE: If not given, the one from the general-settings will be used"
|
echo " NOTE: If not given, the one from the general-settings will be used"
|
||||||
|
echo " -H, --host Database host name"
|
||||||
|
echo " -s, --sudo Authenticate via sudo, databases on localhost only"
|
||||||
|
echo " -p, --password Authenticate via password. Password for the postgres user"
|
||||||
echo " -h, --help Shows this help and exit"
|
echo " -h, --help Shows this help and exit"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
@ -64,11 +86,27 @@ if [ ! -z "$man_user" ]; then
|
||||||
db_user="$man_user"
|
db_user="$man_user"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo -u postgres createdb --encoding=UTF8 --owner=$db_user "$database"
|
if [ "$auth" = "pw" ]; then
|
||||||
sudo -u postgres psql --dbname="$database" -c "CREATE EXTENSION postgis;"
|
if [ -z "$pw" ]; then
|
||||||
sudo -u postgres psql --dbname="$database" -c "CREATE EXTENSION hstore;"
|
echo "ERROR: No password or --sudo flag given"
|
||||||
psql -d "$database" -f "$root_path"/sql/pgsnapshot_schema_0.6.sql
|
exit 1
|
||||||
psql -d "$database" -f "$root_path"/sql/pgsnapshot_schema_0.6_bbox.sql
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$auth" = "sudo" ]; then
|
||||||
|
sudo -u postgres createdb --encoding=UTF8 --owner=$db_user "$database"
|
||||||
|
sudo -u postgres psql --dbname="$database" -c "CREATE EXTENSION postgis;"
|
||||||
|
sudo -u postgres psql --dbname="$database" -c "CREATE EXTENSION hstore;"
|
||||||
|
psql -d "$database" -f "$root_path"/sql/pgsnapshot_schema_0.6.sql
|
||||||
|
psql -d "$database" -f "$root_path"/sql/pgsnapshot_schema_0.6_bbox.sql
|
||||||
|
else
|
||||||
|
createdb --host="$hostname" --username=postgres --encoding=UTF8 --owner=$db_user "$database"
|
||||||
|
psql --host="$hostname" --username=postgres --dbname="$database" -c "CREATE EXTENSION postgis;"
|
||||||
|
psql --host="$hostname" --username=postgres --dbname="$database" -c "CREATE EXTENSION hstore;"
|
||||||
|
psql --host="$hostname" --username=postgres -d "$database" -f "$root_path"/sql/pgsnapshot_schema_0.6.sql
|
||||||
|
psql --host="$hostname" --username=postgres -d "$database" -f "$root_path"/sql/pgsnapshot_schema_0.6_bbox.sql
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ ! -f ".databases" ]; then
|
if [ ! -f ".databases" ]; then
|
||||||
touch "$root_path"/.databases
|
touch "$root_path"/.databases
|
||||||
|
|
13
delete-db
13
delete-db
|
@ -16,6 +16,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
root_path="$( cd "$(dirname "$0")" ; pwd -P )"
|
root_path="$( cd "$(dirname "$0")" ; pwd -P )"
|
||||||
|
hostname=localhost
|
||||||
|
|
||||||
first=1
|
first=1
|
||||||
while [[ "$#" -gt 0 ]]
|
while [[ "$#" -gt 0 ]]
|
||||||
|
@ -23,11 +24,18 @@ do
|
||||||
key="$1"
|
key="$1"
|
||||||
|
|
||||||
case $key in
|
case $key in
|
||||||
|
-H|--host)
|
||||||
|
hostname="$2"
|
||||||
|
shift # past argument
|
||||||
|
shift # past value
|
||||||
|
;;
|
||||||
|
|
||||||
-h|--help)
|
-h|--help)
|
||||||
echo "usage: delete-db <database> [OPTIONS]"
|
echo "usage: delete-db <database> [OPTIONS]"
|
||||||
echo "Deletes the database"
|
echo "Deletes the database"
|
||||||
echo ""
|
echo ""
|
||||||
echo "OPTIONS"
|
echo "OPTIONS"
|
||||||
|
echo " -H, --host Database host name"
|
||||||
echo " -h, --help Shows this help and exit"
|
echo " -h, --help Shows this help and exit"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
@ -45,5 +53,8 @@ case $key in
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
psql --dbname="postgres" -c "DROP DATABASE IF EXISTS \"$database\""
|
source "$root_path"/general-settings > /dev/null
|
||||||
|
export PGPASSWORD="$db_passwd"
|
||||||
|
|
||||||
|
psql --host="$hostname" --username="$db_user" --dbname="postgres" -c "DROP DATABASE IF EXISTS \"$database\""
|
||||||
sed -ri "s/^$key$//" "$root_path"/.databases
|
sed -ri "s/^$key$//" "$root_path"/.databases
|
||||||
|
|
Loading…
Reference in a new issue