# HG changeset patch # User Paul Boddie # Date 1461161609 -7200 # Node ID 939457b7a88672f643c08171911d89bcb8cb6201 # Parent 238440836219c0237ea02b48c60d44a31c261302 Added privileged user tests, fixed PostgreSQL access when granting privileges, added status messages and comments. diff -r 238440836219 -r 939457b7a886 tools/init.sh --- a/tools/init.sh Tue Apr 19 23:44:33 2016 +0200 +++ b/tools/init.sh Wed Apr 20 16:13:29 2016 +0200 @@ -69,6 +69,21 @@ exit 1 fi +# Test for a privileged user. + +if [ `whoami` != 'root' ]; then + cat 1>&2 <&2 + for DIR in "$INSTALL_DIR"/preferences "$WEB_INSTALL_DIR"/static ; do mkdir -p "$DIR" chown "$IMIP_AGENT_USER" "$DIR" @@ -79,6 +94,9 @@ # Initialise a file store. if [ "$STORE_TYPE" = "file" ]; then + + echo "Creating store and journal directories..." 1>&2 + for DIR in "$INSTALL_DIR"/store "$INSTALL_DIR"/journal ; do mkdir -p "$DIR" chown "$IMIP_AGENT_USER" "$DIR" @@ -92,6 +110,8 @@ # Check for the database. + echo "Checking for the database ${POSTGRESQL_DB}..." 1>&2 + if $AS_POSTGRES psql -tA -c 'select datname from pg_database' postgres | grep -q ^"$POSTGRESQL_DB"$ ; then cat 1>&2 <&2 + if ! $AS_POSTGRES createdb "$POSTGRESQL_DB" ; then cat 1>&2 <&2 + + if ! $AS_POSTGRES psql -q -f "$SCHEMA" "$POSTGRESQL_DB" ; then cat 1>&2 <&2 + if ! $AS_POSTGRES createuser -D -R -S "$USER" ; then cat 1>&2 <&2 + if ! $AS_POSTGRES psql -Atc '\dt' "$POSTGRESQL_DB" \ | cut -d '|' -f 2 \ - | xargs -I{} psql -c "grant all privileges on table {} to \"$USER\"" "$POSTGRESQL_DB" ; then + | xargs -I{} $AS_POSTGRES psql -q -c "grant all privileges on table {} to \"$USER\"" "$POSTGRESQL_DB" ; then cat 1>&2 <&2 <&2 + for DIR in "$INSTALL_DIR"/preferences "$WEB_INSTALL_DIR"/static ; do mkdir -p "$DIR/$CALENDAR_USER" chown "$IMIP_AGENT_USER" "$DIR/$CALENDAR_USER" @@ -50,6 +66,9 @@ done if [ "$STORE_TYPE" = "file" ]; then + + echo "Creating store and journal directories..." 1>&2 + for DIR in "$INSTALL_DIR"/store "$INSTALL_DIR"/journal ; do mkdir -p "$DIR/$CALENDAR_USER" chown "$IMIP_AGENT_USER" "$DIR/$CALENDAR_USER"