From 6960ec8065a6a394634bc31eb3b274d78ae067ea Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Thu, 23 Nov 2006 19:37:04 +1300 Subject: [PATCH] Randomly generate the first administrator password. --- dba/create-database.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/dba/create-database.sh b/dba/create-database.sh index 1bb975ec..e61d953d 100755 --- a/dba/create-database.sh +++ b/dba/create-database.sh @@ -8,7 +8,10 @@ DBNAME="${1:-rscds}" DBADIR="`dirname \"$0\"`" # FIXME: Need to check that the database was actually created. -createdb -E UTF8 "${DBNAME}" -T template0 +if ! createdb -E UTF8 "${DBNAME}" -T template0 ; then + echo "Unable to create database" + exit 1 +fi # # This will fail if the language already exists, but it should not @@ -23,4 +26,19 @@ psql -q -f "${DBADIR}/caldav_functions.sql" "${DBNAME}" psql -q -f "${DBADIR}/base-data.sql" "${DBNAME}" +# +# Generate a random administrative password. If pwgen is available we'll use that, +# otherwise try and hack something up using a few standard utilities +PWGEN="`which pwgen`" +if [ "$PWGEN" = "" ] ; then + ADMINPW="`dd if=/dev/urandom bs=512 count=1 2>/dev/null | tr -c -d "[:alnum:]" | cut -c2-9`" +else + ADMINPW="`pwgen -Bcny | tr \"\\\'\" '^='`" +fi +psql -q -c "UPDATE usr SET password = '**${ADMINPW}' WHERE user_no = 1;" "${DBNAME}" + +echo "The password for the 'admin' user has been set to '${ADMINPW}'" + +# +# The supported locales are in a separate file to make them easier to upgrade psql -q -f "${DBADIR}/supported_locales.sql" "${DBNAME}"