I'm installing PostgreSQL + POSTGIS on a CentOS 7 virtual machine using Vagrant and Virtual Box.
My Vagtantfile is the follow ...
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.network "private_network", ip: "192.168.56.2"
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
vb.name = "Test"
end
config.vm.provision "shell", path: "./scripts/InstallPostgresqlPostgis.sh"
end
In ./scripts/InstallPostgresqlPostgis.sh there are all the commands to install PostgreSQL and, when run, PostgreSQL is installed and works.
To add POSTGIS at my PostgreSQL installation, in interactive way, I use this procedure
su postgres
----->>>>>>> HERE I'VE TO PUT THE USER PASSWORD <<<<<<<-------
psql
-- Enable PostGIS (includes raster)
CREATE EXTENSION postgis;
-- Enable Topology
CREATE EXTENSION postgis_topology;
-- Enable PostGIS Advanced 3D
-- and other geoprocessing algorithms
-- sfcgal not available with all distributions
CREATE EXTENSION postgis_sfcgal;
-- fuzzy matching needed for Tiger
CREATE EXTENSION fuzzystrmatch;
-- rule based standardizer
CREATE EXTENSION address_standardizer;
-- example rule data set
CREATE EXTENSION address_standardizer_data_us;
-- Enable US Tiger Geocoder
CREATE EXTENSION postgis_tiger_geocoder;
\q
and all works.
I've to "translate" this procedure in my InstallPostgresqlPostgis.sh that I refer in my Vagrantfile and I've tried this
sudo -u postgres -H -- psql -d postgres -c "CREATE EXTENSION postgis"
sudo -u postgres -H -- psql -d postgres -c "CREATE EXTENSION postgis_topology"
sudo -u postgres -H -- psql -d postgres -c "CREATE EXTENSION postgis_sfcgal"
sudo -u postgres -H -- psql -d postgres -c "CREATE EXTENSION fuzzystrmatch"
sudo -u postgres -H -- psql -d postgres -c "CREATE EXTENSION address_standardizer"
sudo -u postgres -H -- psql -d postgres -c "CREATE EXTENSION address_standardizer_data_us"
sudo -u postgres -H -- psql -d postgres -c "CREATE EXTENSION postgis_tiger_geocoder"
but the result is ...
default: could not change directory to "/home/vagrant": Permission denied
default: CREATE EXTENSION
default: could not change directory to "/home/vagrant": Permission denied
default: CREATE EXTENSION
default: could not change directory to "/home/vagrant": Permission denied
default: CREATE EXTENSION
default: could not change directory to "/home/vagrant": Permission denied
default: CREATE EXTENSION
default: could not change directory to "/home/vagrant": Permission denied
default: CREATE EXTENSION
default: could not change directory to "/home/vagrant": Permission denied
default: CREATE EXTENSION
default: could not change directory to "/home/vagrant": Permission denied
default: CREATE EXTENSION
Where am I doing wrong?
/home/vagrantdirectory that is the home directory for the uservagrant.... I've seen that the home directory for the userpostgresis/var/lib/pgsql.... Any idea how may I change, in my shell script, to change directory or change user (also modifying my approach ...)?