1.1 --- a/tools/config.sh Sun Apr 03 21:41:44 2016 +0200
1.2 +++ b/tools/config.sh Sun Apr 03 21:43:35 2016 +0200
1.3 @@ -6,3 +6,10 @@
1.4 INSTALL_DIR=/var/lib/imip-agent
1.5 WEB_INSTALL_DIR=/var/www/imip-agent
1.6 CONFIG_DIR=/etc/imip-agent
1.7 +
1.8 +# Store-specific settings.
1.9 +
1.10 +# For STORE_TYPE=postgresql:
1.11 +
1.12 +POSTGRESQL_DB=imip_agent
1.13 +POSTGRESQL_USERS="imip-agent www-data"
2.1 --- a/tools/fix.sh Sun Apr 03 21:41:44 2016 +0200
2.2 +++ b/tools/fix.sh Sun Apr 03 21:43:35 2016 +0200
2.3 @@ -14,36 +14,34 @@
2.4
2.5 if [ "$1" = "--help" ]; then
2.6 cat 1>&2 <<EOF
2.7 -Usage: $PROGNAME [ <stored data directory> [ <published data directory> [ <user> [ <group> ] ] ] ]
2.8 +Usage: $PROGNAME
2.9 +
2.10 +Fix permissions for the stored and published data directories, operating on...
2.11
2.12 -Fix permissions for the stored and published data directories, operating on the
2.13 -given stored data and published data directories (or, respectively,
2.14 -$INSTALL_DIR and $WEB_INSTALL_DIR if omitted).
2.15 + * $INSTALL_DIR
2.16 + * $WEB_INSTALL_DIR
2.17
2.18 -Set ownership and membership using the given user and group (or, respectively,
2.19 -$IMIP_AGENT_USER and $IMIP_AGENT_GROUP if omitted).
2.20 +...respectively.
2.21 +
2.22 +Set ownership and membership to the user and group respectively given as
2.23 +$IMIP_AGENT_USER and $IMIP_AGENT_GROUP.
2.24 EOF
2.25 exit 1
2.26 fi
2.27
2.28 -INSTALL_DIR=${1:-$INSTALL_DIR}
2.29 -WEB_INSTALL_DIR=${2:-$WEB_INSTALL_DIR}
2.30 -USER=${3:-$IMIP_AGENT_USER}
2.31 -GROUP=${4:-$IMIP_AGENT_GROUP}
2.32 -
2.33 -chown -R "$USER" "$INSTALL_DIR"
2.34 -chgrp -R "$GROUP" "$INSTALL_DIR"
2.35 +chown -R "$IMIP_AGENT_USER" "$INSTALL_DIR"
2.36 +chgrp -R "$IMIP_AGENT_GROUP" "$INSTALL_DIR"
2.37
2.38 for DIR in "$INSTALL_DIR"/preferences "$WEB_INSTALL_DIR"/static ; do
2.39 - chown -R "$USER" "$DIR"
2.40 - chgrp -R "$GROUP" "$DIR"
2.41 + chown -R "$IMIP_AGENT_USER" "$DIR"
2.42 + chgrp -R "$IMIP_AGENT_GROUP" "$DIR"
2.43 chmod -R g+w "$DIR"
2.44 done
2.45
2.46 if [ "$STORE_TYPE" = "file" ]; then
2.47 for DIR in "$INSTALL_DIR"/store "$INSTALL_DIR"/journal ; do
2.48 - chown -R "$USER" "$DIR"
2.49 - chgrp -R "$GROUP" "$DIR"
2.50 + chown -R "$IMIP_AGENT_USER" "$DIR"
2.51 + chgrp -R "$IMIP_AGENT_GROUP" "$DIR"
2.52 chmod -R g+w "$DIR"
2.53 done
2.54 fi
3.1 --- a/tools/init.sh Sun Apr 03 21:41:44 2016 +0200
3.2 +++ b/tools/init.sh Sun Apr 03 21:43:35 2016 +0200
3.3 @@ -1,61 +1,139 @@
3.4 #!/bin/sh
3.5
3.6 DIRNAME=`dirname $0`
3.7 +CONFIG="$DIRNAME/config.sh"
3.8
3.9 -if [ -e "$DIRNAME/config.sh" ]; then
3.10 - CONFIG="$DIRNAME/config.sh"
3.11 +if [ -e "$CONFIG" ]; then
3.12 . "$CONFIG"
3.13 else
3.14 CONFIG=/etc/imip-agent/config.sh
3.15 . "$CONFIG"
3.16 fi
3.17
3.18 +SCHEMA="$DIRNAME/../conf/postgresql/schema.sql"
3.19 +
3.20 +if [ ! -e "$SCHEMA" ]; then
3.21 + SCHEMA=/etc/imip-agent/postgresql/schema.sql
3.22 +fi
3.23 +
3.24 PROGNAME=`basename $0`
3.25
3.26 if [ "$1" = "--help" ]; then
3.27 cat 1>&2 <<EOF
3.28 -Usage: $PROGNAME [ <stored data directory> [ <published data directory> [ <user> [ <group> ] ] ] ]
3.29 +Usage: $PROGNAME
3.30 +
3.31 +Initialise stored and published data directories at...
3.32
3.33 -Initialise stored and published data directories either at any specified
3.34 -locations or, respectively, at $INSTALL_DIR and $WEB_INSTALL_DIR.
3.35 + * $INSTALL_DIR
3.36 + * $WEB_INSTALL_DIR
3.37
3.38 -Set permissions to the given user and group or, respectively, to $IMIP_AGENT_USER
3.39 +...respectively.
3.40 +
3.41 +Set permissions to the user and group respectively given as $IMIP_AGENT_USER
3.42 and $IMIP_AGENT_GROUP.
3.43
3.44 -Within the stored data directory (using $INSTALL_DIR as an example), the
3.45 -following directories are created:
3.46 +Within the stored data directory, the following directories will be created
3.47 +(with STORE_TYPE currently set as "$STORE_TYPE"):
3.48
3.49 - * $INSTALL_DIR/journal (if STORE_TYPE is "file")
3.50 * $INSTALL_DIR/preferences
3.51 - * $INSTALL_DIR/store (if STORE_TYPE is "file")
3.52 +EOF
3.53
3.54 -Within the published data directory (using $WEB_INSTALL_DIR as an example), the
3.55 -following directory is created:
3.56 + if [ "$STORE_TYPE" = "file" ]; then
3.57 + cat 1>&2 <<EOF
3.58 + * $INSTALL_DIR/journal (if STORE_TYPE is "file")
3.59 + * $INSTALL_DIR/store (if STORE_TYPE is "file")
3.60 +EOF
3.61 + fi
3.62 +
3.63 + cat 1>&2 <<EOF
3.64 +
3.65 +Within the published data directory the following directory will be created:
3.66
3.67 * $WEB_INSTALL_DIR/static
3.68 +EOF
3.69
3.70 -See $CONFIG for the STORE_TYPE setting.
3.71 + if [ "$STORE_TYPE" = "postgresql" ]; then
3.72 + cat 1>&2 <<EOF
3.73 +
3.74 +With STORE_TYPE set as "database", a database schema will be initialised for the
3.75 +following database:
3.76 +
3.77 + * $POSTGRESQL_DB
3.78 +EOF
3.79 + fi
3.80 +
3.81 + cat 1>&2 <<EOF
3.82 +
3.83 +See $CONFIG for the settings used as described above.
3.84 EOF
3.85 exit 1
3.86 fi
3.87
3.88 -INSTALL_DIR=${1:-$INSTALL_DIR}
3.89 -WEB_INSTALL_DIR=${2:-$WEB_INSTALL_DIR}
3.90 -USER=${3:-$IMIP_AGENT_USER}
3.91 -GROUP=${4:-$IMIP_AGENT_GROUP}
3.92 -
3.93 for DIR in "$INSTALL_DIR"/preferences "$WEB_INSTALL_DIR"/static ; do
3.94 mkdir -p "$DIR"
3.95 - chown "$USER" "$DIR"
3.96 - chgrp "$GROUP" "$DIR"
3.97 + chown "$IMIP_AGENT_USER" "$DIR"
3.98 + chgrp "$IMIP_AGENT_GROUP" "$DIR"
3.99 chmod g+ws "$DIR"
3.100 done
3.101
3.102 +# Initialise a file store.
3.103 +
3.104 if [ "$STORE_TYPE" = "file" ]; then
3.105 for DIR in "$INSTALL_DIR"/store "$INSTALL_DIR"/journal ; do
3.106 mkdir -p "$DIR"
3.107 - chown "$USER" "$DIR"
3.108 - chgrp "$GROUP" "$DIR"
3.109 + chown "$IMIP_AGENT_USER" "$DIR"
3.110 + chgrp "$IMIP_AGENT_GROUP" "$DIR"
3.111 chmod g+ws "$DIR"
3.112 done
3.113 +
3.114 +# Initialise a PostgreSQL store.
3.115 +
3.116 +elif [ "$STORE_TYPE" = "postgresql" ]; then
3.117 +
3.118 + # Check for the database.
3.119 +
3.120 + if psql -tA -c 'select datname from pg_database' postgres | grep -q ^"$POSTGRESQL_DB"$ ; then
3.121 + cat 1>&2 <<EOF
3.122 +Database $POSTGRESQL_DB already exists.
3.123 +EOF
3.124 + exit 1
3.125 + fi
3.126 +
3.127 + # Attempt to create the database.
3.128 +
3.129 + if ! createdb "$POSTGRESQL_DB" ; then
3.130 + cat 1>&2 <<EOF
3.131 +Could not create database $POSTGRESQL_DB using createdb.
3.132 +EOF
3.133 + exit 1
3.134 + fi
3.135 +
3.136 + # Attempt to initialise the schema.
3.137 +
3.138 + if ! psql -f "$SCHEMA" "$POSTGRESQL_DB" ; then
3.139 + cat 1>&2 <<EOF
3.140 +Could not initialise schema in database $POSTGRESQL_DB using psql.
3.141 +EOF
3.142 + exit 1
3.143 + fi
3.144 +
3.145 + # For each user needing to connect, attempt to create a role and grant it
3.146 + # privileges on the tables.
3.147 +
3.148 + for USER in $POSTGRESQL_USERS ; do
3.149 + if ! createuser -D -R -S "$USER" ; then
3.150 + cat 1>&2 <<EOF
3.151 +Could not create database user $USER using createuser.
3.152 +EOF
3.153 + fi
3.154 + if ! psql -Atc '\dt' "$POSTGRESQL_DB" \
3.155 + | cut -d '|' -f 2 \
3.156 + | xargs -I{} psql -c "grant all privileges on table {} to \"$USER\"" "$POSTGRESQL_DB" ; then
3.157 +
3.158 + cat 1>&2 <<EOF
3.159 +Could not grant permissions for schema in database $POSTGRESQL_DB to $USER
3.160 +using psql.
3.161 +EOF
3.162 + fi
3.163 + done
3.164 fi
4.1 --- a/tools/init_user.sh Sun Apr 03 21:41:44 2016 +0200
4.2 +++ b/tools/init_user.sh Sun Apr 03 21:43:35 2016 +0200
4.3 @@ -14,26 +14,37 @@
4.4
4.5 if [ "$1" = "--help" ]; then
4.6 cat 1>&2 <<EOF
4.7 -Usage: $PROGNAME <calendar user> [ <stored data directory> [ <published data directory> [ <user> ] ] ]
4.8 +Usage: $PROGNAME <calendar user>
4.9
4.10 Initialise a given calendar user within an existing installation, creating
4.11 -resources within the given stored data and published data directories or,
4.12 -respectively, within $INSTALL_DIR and $WEB_INSTALL_DIR.
4.13 +resources within the given stored data and published data directories...
4.14 +
4.15 + * $INSTALL_DIR
4.16 + * $WEB_INSTALL_DIR
4.17
4.18 -The resources will be defined as having the given system user as owner or,
4.19 -if the user is omitted, the $IMIP_AGENT_USER as owner.
4.20 +...respectively.
4.21 +
4.22 +The resources will be defined as having $IMIP_AGENT_USER as owner.
4.23 +
4.24 +See $CONFIG for the settings used as described above.
4.25 EOF
4.26 exit 1
4.27 fi
4.28
4.29 CALENDAR_USER=$1
4.30 -INSTALL_DIR=${2:-$INSTALL_DIR}
4.31 -WEB_INSTALL_DIR=${3:-$WEB_INSTALL_DIR}
4.32 -USER=${4:-$IMIP_AGENT_USER}
4.33 +
4.34 +if [ ! "$CALENDAR_USER" ]; then
4.35 + cat 1>&2 <<EOF
4.36 +Need a calendar user to initialise.
4.37 +EOF
4.38 + exit 1
4.39 +fi
4.40 +
4.41 +# Initialise the directories.
4.42
4.43 for DIR in "$INSTALL_DIR"/preferences "$WEB_INSTALL_DIR"/static ; do
4.44 mkdir -p "$DIR/$CALENDAR_USER"
4.45 - chown "$USER" "$DIR/$CALENDAR_USER"
4.46 + chown "$IMIP_AGENT_USER" "$DIR/$CALENDAR_USER"
4.47 chmod g+ws "$DIR/$CALENDAR_USER"
4.48 # Group privileges should already be set.
4.49 done
4.50 @@ -41,7 +52,7 @@
4.51 if [ "$STORE_TYPE" = "file" ]; then
4.52 for DIR in "$INSTALL_DIR"/store "$INSTALL_DIR"/journal ; do
4.53 mkdir -p "$DIR/$CALENDAR_USER"
4.54 - chown "$USER" "$DIR/$CALENDAR_USER"
4.55 + chown "$IMIP_AGENT_USER" "$DIR/$CALENDAR_USER"
4.56 chmod g+ws "$DIR/$CALENDAR_USER"
4.57 # Group privileges should already be set.
4.58 done
5.1 --- a/tools/install.sh Sun Apr 03 21:41:44 2016 +0200
5.2 +++ b/tools/install.sh Sun Apr 03 21:43:35 2016 +0200
5.3 @@ -87,6 +87,14 @@
5.4
5.5 cp tools/config.sh "$CONFIG_DIR/"
5.6
5.7 +# Copy related configuration files.
5.8 +
5.9 +if [ ! -e "$CONFIG_DIR/postgresql" ]; then
5.10 + mkdir -p "$CONFIG_DIR/postgresql"
5.11 +fi
5.12 +
5.13 +cp conf/postgresql/schema.sql "$CONFIG_DIR/postgresql/"
5.14 +
5.15 # Tools
5.16
5.17 TOOLS="fix.sh init.sh init_user.sh make_freebusy.py set_quota_limit.py update_quotas.py update_scheduling_modules.py"