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