1 #!/bin/sh 2 3 # This tool initialises users within data stores and published data 4 # directories. It is configured using the contents of the config.sh script. 5 # 6 # Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> 7 # 8 # This program is free software; you can redistribute it and/or modify it under 9 # the terms of the GNU General Public License as published by the Free Software 10 # Foundation; either version 3 of the License, or (at your option) any later 11 # version. 12 # 13 # This program is distributed in the hope that it will be useful, but WITHOUT 14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 # details. 17 # 18 # You should have received a copy of the GNU General Public License along with 19 # this program. If not, see <http://www.gnu.org/licenses/>. 20 21 DIRNAME=`dirname "$0"` 22 23 if [ -e "$DIRNAME/config.sh" ]; then 24 CONFIG="$DIRNAME/config.sh" 25 . "$CONFIG" 26 else 27 CONFIG=/etc/imip-agent/config.sh 28 . "$CONFIG" 29 fi 30 31 PROGNAME=`basename "$0"` 32 33 if [ "$1" = "--help" ] || [ ! "$1" ]; then 34 cat 1>&2 <<EOF 35 Usage: $PROGNAME <calendar user> 36 37 Initialise a given calendar user within an existing installation, creating 38 resources within the given stored data and published data directories... 39 40 * $INSTALL_DIR 41 * $WEB_INSTALL_DIR 42 43 ...respectively. 44 45 The resources will be defined as having $IMIP_AGENT_USER as owner. 46 47 See $CONFIG for the settings used as described above. 48 49 Example: 50 51 $PROGNAME mailto:vincent.vole@example.com 52 EOF 53 exit 1 54 fi 55 56 CALENDAR_USER=$1 57 58 if [ ! "$CALENDAR_USER" ]; then 59 cat 1>&2 <<EOF 60 Need a calendar user to initialise. 61 EOF 62 exit 1 63 fi 64 65 # Test for a privileged user. 66 67 if [ `whoami` != 'root' ]; then 68 cat 1>&2 <<EOF 69 You will need to become a privileged user using su or sudo to run this program 70 because it changes file ownership. 71 EOF 72 exit 1 73 fi 74 75 # Initialise the directories. 76 77 echo "Creating preferences and static Web directories..." 1>&2 78 79 for DIR in "$INSTALL_DIR"/preferences "$WEB_INSTALL_DIR"/static ; do 80 mkdir -p "$DIR/$CALENDAR_USER" 81 chown "$IMIP_AGENT_USER" "$DIR/$CALENDAR_USER" 82 chmod g+ws "$DIR/$CALENDAR_USER" 83 # Group privileges should already be set. 84 done 85 86 if [ "$STORE_TYPE" = "file" ]; then 87 88 echo "Creating store and journal directories..." 1>&2 89 90 for DIR in "$INSTALL_DIR"/store "$INSTALL_DIR"/journal ; do 91 mkdir -p "$DIR/$CALENDAR_USER" 92 chown "$IMIP_AGENT_USER" "$DIR/$CALENDAR_USER" 93 chmod g+ws "$DIR/$CALENDAR_USER" 94 # Group privileges should already be set. 95 done 96 fi