1a61006602
these will be added as soon as I can track them down properly (probably along with an upgrade to 3.1.1) This update incorporates contributions from Dru Lavigne and Dmitriy Kirhlarov, and was sponsored by the University of Tromsø (uit.no).
151 lines
4.7 KiB
Bash
151 lines
4.7 KiB
Bash
#! /bin/sh
|
|
# auto-configure nav, anders@FreeBSD.org 2004-11-14
|
|
#
|
|
# Variabels that needs to be set: LOCALBASE
|
|
|
|
navuser=navcron
|
|
navgroup=nav
|
|
|
|
if [ -z "$LOCALBASE" ]
|
|
then
|
|
echo "LOCALBASE variable not set. Aborting."
|
|
exit 1
|
|
fi
|
|
if [ -z "$PORTSDIR" ]
|
|
then
|
|
echo "PORTSDIR variable not set. Aborting."
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "`grep \"^if \[ -f $LOCALBASE/nav/bin/navenv\.sh \]; then \. $LOCALBASE/nav/bin/navenv\.sh; fi\" /etc/profile`" ]
|
|
then
|
|
echo "Add sourcing of environment in /etc/profile."
|
|
echo "if [ -f $LOCALBASE/nav/bin/navenv.sh ]; then . $LOCALBASE/nav/bin/navenv.sh; fi" >>/etc/profile
|
|
fi
|
|
|
|
if [ ! -f $LOCALBASE/etc/cricket-conf.pl ]
|
|
then
|
|
echo "Default cricket config missing, copying default one to"
|
|
echo "$LOCALBASE/etc/cricket-conf.pl."
|
|
install -g $navgroup -o $navuser -m 0755 $LOCALBASE/etc/cricket-conf.pl.dist $LOCALBASE/etc/cricket-conf.pl
|
|
fi
|
|
|
|
setdbcvar() {
|
|
# $1: variable $2: password $3: config
|
|
sed -e "s/^$1=.*/$1=$2/" $3 >$3.tmp
|
|
cp $3.tmp $3
|
|
rm -f $3.tmp
|
|
}
|
|
|
|
ifyes() {
|
|
read line
|
|
if [ "`echo $line | cut -c1-1 | tr 'A-Z' 'a-z'`" != "y" ]
|
|
then
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
apgck() {
|
|
if [ ! -x $LOCALBASE/bin/apg ]
|
|
then
|
|
printf "Password-generation program ports/security/apg is missing. Do you want me to\n"
|
|
printf "try to install it for you? (y/n) "
|
|
if (ifyes)
|
|
then
|
|
cd $PORTSDIR/security/apg
|
|
(make clean && make install && make clean) >/dev/null 2>&1
|
|
fi
|
|
if [ ! -x $LOCALBASE/bin/apg ]
|
|
then
|
|
echo "Please install ports/security/apg. Need it to generate random passwords"
|
|
echo "for PostgreSQL. Then re-run this script/make auto-config."
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
if (id pgsql >/dev/null 2>&1)
|
|
then
|
|
printf "Do you want to auto-configure PostgreSQL? (y/n) "
|
|
if (ifyes)
|
|
then
|
|
apgck
|
|
|
|
pdir=$LOCALBASE/pgsql/data
|
|
pconf=$pdir/postgresql.conf
|
|
phbaconf=$pdir/pg_hba.conf
|
|
pgsqlp=`$LOCALBASE/bin/apg -M NCL -n 1`
|
|
nav=`$LOCALBASE/bin/apg -M NCL -n 1`
|
|
navdbconf=$LOCALBASE/nav/etc/db.conf
|
|
navdbbkconf=$LOCALBASE/nav/etc/pg_backup.conf
|
|
|
|
if [ ! -d $pdir ]
|
|
then
|
|
echo "Running PostgreSQL initdb."
|
|
su -l pgsql -c "$LOCALBASE/bin/initdb"
|
|
fi
|
|
if [ -f $pconf ]
|
|
then
|
|
echo "Setting up TCP/IP socket for PostgreSQL."
|
|
sed "s/.*tcpip_socket.*/tcpip_socket = true/" \
|
|
$pconf >$pconf.tmp
|
|
cp $pconf.tmp $pconf
|
|
rm -f $pconf.tmp
|
|
fi
|
|
printf "To continue, we need to start the database engine. Proceed? (y/n) "
|
|
if (ifyes)
|
|
then
|
|
echo "Starting PostgreSQL database."
|
|
su -l pgsql -c "$LOCALBASE/bin/pg_ctl start -s -w"
|
|
echo "Waiting 5 seconds."
|
|
sleep 5
|
|
echo "Creating users & databases, importing data."
|
|
usedb=template1
|
|
# firstdb=`su -l pgsql -c "$LOCALBASE/bin/psql -l -t -A" | head -1 | cut -d'|' -f1`
|
|
PGUSER=pgsql
|
|
export PGUSER
|
|
$LOCALBASE/bin/createuser -A -D nav
|
|
$LOCALBASE/bin/createdb --owner nav --encoding UTF-8 arnold
|
|
$LOCALBASE/bin/createdb --owner nav --encoding UTF-8 manage
|
|
$LOCALBASE/bin/createdb --owner nav --encoding UTF-8 navprofiles
|
|
$LOCALBASE/bin/createdb --owner nav --encoding UTF-8 logger
|
|
$LOCALBASE/bin/createlang plpgsql manage
|
|
$LOCALBASE/bin/createlang plpgsql navprofiles
|
|
$LOCALBASE/bin/psql -f $LOCALBASE/nav/doc/sql/manage.sql manage nav
|
|
$LOCALBASE/bin/psql -f $LOCALBASE/nav/doc/sql/types.sql manage nav
|
|
$LOCALBASE/bin/psql -f $LOCALBASE/nav/doc/sql/snmpoid.sql manage nav
|
|
$LOCALBASE/bin/psql -f $LOCALBASE/nav/doc/sql/navprofiles.sql navprofiles nav
|
|
$LOCALBASE/bin/psql -f $LOCALBASE/nav/doc/sql/logger.sql logger nav
|
|
$LOCALBASE/bin/psql -f $LOCALBASE/nav/doc/sql/arnold.sql arnold nav
|
|
echo "Setting passwords."
|
|
echo "alter user nav with password '$nav';" | $LOCALBASE/bin/psql $usedb
|
|
echo "alter user pgsql with password '$pgsqlp';" | $LOCALBASE/bin/psql $usedb
|
|
echo
|
|
echo "Password for database user nav: $nav"
|
|
echo "Password for database user pgsql: $pgsqlp"
|
|
echo "Make a mental note of it!"
|
|
echo
|
|
echo "Setting database passwords in NAV db.conf and pg_backup.conf."
|
|
setdbcvar userpw_nav $nav $navdbconf
|
|
setdbcvar username pgsql $navdbbkconf
|
|
setdbcvar password $pgsqlp $navdbbkconf
|
|
echo "Configure database to only allow authentcated connections."
|
|
cat $phbaconf | sed -E "s/(^(local|host).*)trust/\1md5/" >$phbaconf.tmp
|
|
cp $phbaconf.tmp $phbaconf
|
|
rm -f $phbaconf.tmp
|
|
echo "Reloading database."
|
|
su -l pgsql -c "$LOCALBASE/bin/pg_ctl reload"
|
|
else
|
|
echo "Fine, you have an empty database set up. Now create users, set passwords,"
|
|
echo "and import default data. Do not forget to configure pg_hba.conf."
|
|
fi
|
|
else
|
|
echo "Fine, see if I care."
|
|
fi
|
|
else
|
|
echo
|
|
echo "Consider installing a matching ports/databases/postgresqlXX-serverfor your"
|
|
echo "PostgreSQL client installation if you want a local NAV database. This target"
|
|
echo "(auto-config) can set up the database for you then, just run make auto-config"
|
|
echo "again."
|
|
fi
|