2018-11-13 15:31:53 +00:00
|
|
|
#! /bin/bash
|
2019-03-14 15:03:54 +00:00
|
|
|
# Copyright (C) 2018-2019 Merspieler, merspieler _at_ airmail.cc
|
2018-11-21 20:17:10 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation; either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2018-11-13 15:31:53 +00:00
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]
|
|
|
|
do
|
|
|
|
key="$1"
|
|
|
|
|
|
|
|
case $key in
|
|
|
|
--skip-install)
|
|
|
|
skip_install=1
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
|
|
|
|
--skip-git)
|
|
|
|
skip_git=1
|
|
|
|
shift # past argument
|
2018-11-13 17:34:12 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
--skip-sql)
|
|
|
|
skip_sql=1
|
|
|
|
shift # past argument
|
2018-11-13 15:31:53 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
-h|--help)
|
|
|
|
echo "usage: install [OPTIONS]..."
|
|
|
|
echo "Installs all needed packages and clones the osm2city and osm2city-data repository"
|
|
|
|
echo ""
|
|
|
|
echo "OPTIONS:"
|
|
|
|
echo " -h, --help Shows this help and exits"
|
|
|
|
echo " --skip-install Skips install of packages and continues with setup"
|
|
|
|
echo " --skip-git Skips git clones of the osm2city and osm2city-data repository"
|
2018-11-13 17:34:12 +00:00
|
|
|
echo " --skip-sql Skips setup of the sql user"
|
2018-11-13 15:31:53 +00:00
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "Unknow option $key"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$skip_install" != 1 ]; then
|
|
|
|
which apt-get > /dev/null
|
|
|
|
if [ $? == 1 ]; then
|
|
|
|
echo "Currently apt is the only supported package manager but it seems that apt isn't installed."
|
|
|
|
echo "Please install the following packages manually"
|
|
|
|
echo "python3-venv"
|
|
|
|
echo "python-pip"
|
2018-11-13 16:30:30 +00:00
|
|
|
echo "postgresql"
|
|
|
|
echo "postgresql-postgis"
|
|
|
|
echo "postgresql-client"
|
|
|
|
echo "postgresql-contrib"
|
2018-11-13 15:31:53 +00:00
|
|
|
echo "pgadmin3"
|
|
|
|
echo "postgis"
|
|
|
|
echo "python3-psycopg2"
|
|
|
|
echo "osmosis"
|
|
|
|
echo "git"
|
|
|
|
echo "Then rerun this script with skip-install argument"
|
|
|
|
echo "./install --skip-install"
|
2019-04-04 06:48:30 +00:00
|
|
|
exit 3
|
2018-11-13 15:31:53 +00:00
|
|
|
fi
|
2019-05-17 05:55:07 +00:00
|
|
|
sudo apt-get install -y git osmosis postgis pgadmin3 postgresql-contrib postgresql-client postgresql-postgis postgresql python-pip python3-venv python3-dev
|
2018-11-13 16:20:52 +00:00
|
|
|
if [ $? == 100 ]; then
|
2018-11-13 16:18:45 +00:00
|
|
|
echo "apt-get had problems installing some packages"
|
|
|
|
echo "Please make sure that all of the following packages are installed"
|
2019-05-17 05:55:07 +00:00
|
|
|
echo "python3-dev"
|
2018-11-13 16:18:45 +00:00
|
|
|
echo "python3-venv"
|
|
|
|
echo "python-pip"
|
2018-11-13 16:30:30 +00:00
|
|
|
echo "postgresql"
|
|
|
|
echo "postgresql-postgis"
|
|
|
|
echo "postgresql-client"
|
|
|
|
echo "postgresql-contrib"
|
2018-11-13 16:18:45 +00:00
|
|
|
echo "pgadmin3"
|
|
|
|
echo "postgis"
|
|
|
|
echo "python3-psycopg2"
|
|
|
|
echo "osmosis"
|
|
|
|
echo "git"
|
|
|
|
echo "Then rerun this script with skip-install argument"
|
|
|
|
echo "./install --skip-install"
|
2019-04-04 06:48:30 +00:00
|
|
|
exit 3
|
2018-11-13 16:18:45 +00:00
|
|
|
fi
|
2018-11-13 15:31:53 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$skip_git" != 1 ]; then
|
|
|
|
which git > /dev/null
|
|
|
|
if [ $? == 1 ]; then
|
|
|
|
echo "Unable to find git. Please manually download the following two repositories:"
|
|
|
|
echo "https://gitlab.com/fg-radi/osm2city"
|
|
|
|
echo "https://gitlab.com/fg-radi/osm2city-data"
|
|
|
|
echo "Unzip them in this directory and make sure, the are named osm2city and osm2city-data"
|
2019-04-04 06:48:30 +00:00
|
|
|
exit 3
|
2018-11-13 15:31:53 +00:00
|
|
|
fi
|
|
|
|
git clone https://gitlab.com/fg-radi/osm2city.git
|
|
|
|
git clone https://gitlab.com/fg-radi/osm2city-data.git
|
|
|
|
fi
|
|
|
|
|
2018-11-13 17:34:12 +00:00
|
|
|
if [ "$skip_sql" != 1 ]; then
|
|
|
|
echo "Do you want to create a database user[y/n]? "
|
|
|
|
read ret
|
|
|
|
if [ "$ret" == "y" ]; then
|
|
|
|
echo "Please enter the username: "
|
|
|
|
read db_user
|
|
|
|
echo "Please enter a password: "
|
|
|
|
read db_passwd
|
2019-09-29 02:46:52 +00:00
|
|
|
sudo -u postgres psql -c "CREATE USER $db_user WITH PASSWORD '$db_passwd'; ALTER USER $db_user CREATEDB;"
|
2018-11-13 17:34:12 +00:00
|
|
|
echo "db_user=$db_user" >> general-settings
|
2019-09-29 02:46:52 +00:00
|
|
|
echo "db_passwd=\"$db_passwd\"" >> general-settings
|
2018-11-13 17:34:12 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-09-29 02:46:52 +00:00
|
|
|
echo "Creating template database..."
|
2019-09-29 03:16:52 +00:00
|
|
|
sudo -u postgres createdb --encoding=UTF8 osm2city_template && psql --dbname="osm2city_template" -c "CREATE EXTENSION postgis;" && psql --dbname="osm2city_template" -c "CREATE EXTENSION hstore;" && psql -d osm2city_template -f sql/pgsnapshot_schema_0.6.sql && psql -d osm2city_template -f sql/pgsnapshot_schema_0.6_bbox.sql && psql -c "ALTER DATABASE osm2city_template OWNER TO $db_user;"
|
2019-09-29 02:46:52 +00:00
|
|
|
|
2018-11-13 17:34:12 +00:00
|
|
|
if [ ! -f general-settings ]; then
|
|
|
|
echo "# This file must be used with "source general-settings" *from bash*" > general-settings
|
|
|
|
echo "# you cannot run it directly" >> general-settings
|
|
|
|
echo "" >> general-settings
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# check if the threads value is already in the general-settings
|
|
|
|
cat general-settings|grep ^threads > /dev/null
|
|
|
|
if [ $? == 1 ]; then
|
|
|
|
echo "What is the default number of threads you want to use for scenery generation?"
|
|
|
|
read threads
|
|
|
|
echo "threads=$threads" >> general-settings
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# check if the FG_ROOT value is already in the general-settings
|
|
|
|
cat general-settings|grep ^FG_ROOT > /dev/null
|
|
|
|
if [ $? == 1 ]; then
|
|
|
|
echo "Please give the full path to the fgdata directory"
|
|
|
|
read fg_root
|
|
|
|
echo "FG_ROOT=$fg_root" >> general-settings
|
2018-11-13 18:08:50 +00:00
|
|
|
echo "export FG_ROOT" >> general-settings
|
2018-11-13 17:34:12 +00:00
|
|
|
fi
|
|
|
|
|
2018-11-13 17:44:25 +00:00
|
|
|
# check if the fg_elev value is already in the general-settings
|
|
|
|
cat general-settings|grep ^fg_elev > /dev/null
|
|
|
|
if [ $? == 1 ]; then
|
|
|
|
echo "Please give the full path to the fgelev executable"
|
|
|
|
read fg_elev
|
|
|
|
echo "fg_elev=$fg_elev" >> general-settings
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check if the fg_scenery value is already in the general-settings
|
|
|
|
cat general-settings|grep ^fg_scenery > /dev/null
|
|
|
|
if [ $? == 1 ]; then
|
|
|
|
echo "Please give the full path to the flightgear scenery"
|
|
|
|
read fg_scenery
|
2018-11-13 18:20:02 +00:00
|
|
|
echo "fg_scenery=$fg_scenery" >> general-settings
|
2018-11-13 17:44:25 +00:00
|
|
|
fi
|
|
|
|
|
2018-11-13 17:34:12 +00:00
|
|
|
# check if the PYTHONPATH value is already in the general-settings
|
|
|
|
cat general-settings|grep ^PYTHONPATH > /dev/null
|
|
|
|
if [ $? == 1 ]; then
|
|
|
|
echo "PYTHONPATH=$(pwd)/osm2city" >> general-settings
|
2018-11-13 18:08:50 +00:00
|
|
|
echo "export PYTHONPATH" >> general-settings
|
2018-11-13 17:34:12 +00:00
|
|
|
fi
|
|
|
|
|
2018-11-13 17:44:25 +00:00
|
|
|
# check if the db_host value is already in the general-settings
|
|
|
|
cat general-settings|grep ^db_host > /dev/null
|
|
|
|
if [ $? == 1 ]; then
|
|
|
|
echo "db_host=localhost" >> general-settings
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check if the db_port value is already in the general-settings
|
|
|
|
cat general-settings|grep ^db_port > /dev/null
|
|
|
|
if [ $? == 1 ]; then
|
|
|
|
echo "db_port=5432" >> general-settings
|
|
|
|
fi
|
|
|
|
|
2018-11-13 15:31:53 +00:00
|
|
|
# Create directory for .pbf files
|
2018-11-13 16:18:45 +00:00
|
|
|
mkdir -p pbf
|
2018-11-13 16:46:08 +00:00
|
|
|
mkdir -p projects
|
2019-02-28 22:25:48 +00:00
|
|
|
|
|
|
|
./create-venv
|