#!/bin/sh
##----------------------------------------------------------------------
## NOC post-install script
##
##----------------------------------------------------------------------
## Copyright (C) 2007-2011 The NOC Project
## See LICENSE for details
##----------------------------------------------------------------------
PREFIX=/opt/noc
REPO=/var/repo
BACKUP=/var/backup
LOG=/var/log/noc
PIDDIR=$LOG
NOCUSER=noc
NOCGROUP=noc

## Parse arguments
while getopts hp:r:b:l:P:u:g: o
do case "$o" in
    h)
        echo "Usage: $0 [-p <prefix>] [-r <repo>] [-b <backup>] [-l <log>] [-P <pid_dir>] [-u <user>] [-g <group>]"
        exit 0
    ;;
    p) PREFIX="$OPTARG";;
    r) REPO="$OPTARG";;
    b) BACKUP="$OPTARG";;
    l) LOG="$OPTARG";;
    P) PIDDIR="$OPTARG";;
    u) NOCUSER="$OPTARG";;
    g) NOCGROUP="$OPTARG";;
esac done

if [ ! -d "$PREFIX" ]; then
    echo "Directory $PREFIX is not found"
    exit 1
fi
cd $PREFIX
##
## Set up configuration files
##
echo "Set up configuration files"
./scripts/install-conf -r "$REPO" -b "$BACKUP" -l "$LOG" -P "$PIDDIR"
chmod 640 etc/*.conf
chown noc:noc etc/*.conf
##
## Create required directories
##
echo "Create directories"
for d in local etc/ssh static/doc $REPO $BACKUP $LOG; do
    [ ! -d $d ] && mkdir -p $d
    chown $NOCUSER:$NOCGROUP $d
done
chmod 700 etc/ssh
echo "post-install completed"
