Web inteface: nicer system error page, and introduced a bug (OK, a photo of a bug :-)
[openxpki.git] / trunk / deployment / bin / openxpki-configure.in
blobab104c24c88cf1323b4eaf0669b05861df28684a
1 #!/usr/bin/env bash
3 # OpenXPKI (Re)configuration script
5 # Written by Martin Bartosch for the OpenXPKI project 2006
6 # Copyright (c) 2006 by The OpenXPKI Project
9 prefix="[% dir.prefix %]"
10 exec_prefix="[% dir.exec_prefix %]"
11 TEMPLATEDIR="[% dir.templatedir %]"
12 TEMPLATE="default"
13 SYSCONFDIR="[% dir.sysconfdir %]"
14 OPENXPKICONFDIR="[% dir.openxpkiconfdir %]"
16 INTERACTIVE=1
17 CREATE_DIRS=""
18 FORCE=""
21 reconfigure() {
22 # interactively create initial configuration
23 $CFG --sectionsmenu --interactive --force --writecfg $OPENXPKICONFDIR/openxpki.conf
24 return $?
27 write_config() {
28 echo
29 echo "* Creating configuration files in $OPENXPKICONFDIR"
30 for xmlfile in $* ; do
31 basename=`basename $xmlfile`
32 echo -n "$basename... "
33 $CFG --file $xmlfile $FORCE --dstdir $OPENXPKICONFDIR
34 if [ $? = 0 ] ; then
35 echo "done"
36 else
37 echo "FAILED"
38 echo "*** Configuration incomplete (and probably broken)."
39 echo "*** Please correct the problem and repeat."
40 exit 1
42 done
45 # if no arguments are given this function only checks if the required
46 # directories are present. otherwise these directories are also created
47 check_dirs() {
48 echo
49 echo "* Checking directories"
50 error=0
51 for entry in openxpkistatedir openxpkisessiondir dataexchange tmpdir; do
52 dir="`$CFG --getcfg dir.$entry`"
53 echo -n "$entry: "
54 if [ -d "$dir" ] ; then
55 echo "$dir: OK"
56 else
57 if [ "$1" != "" ] ; then
58 if [ "`uname`" == "SunOS" ]; then
59 INSTALL="/usr/sbin/install -u";
60 else
61 INSTALL="install -o";
62 fi ;
63 if $INSTALL $RUNUSER -g $RUNGROUP -m 0750 -d $dir ; then
64 echo "$dir: CREATED"
65 else
66 echo "$dir: FAILED TO CREATE"
67 error=1
69 else
70 echo "$dir: DOES NOT EXIST"
71 error=1
74 done
75 return $error
79 ###########################################################################
80 echo
81 echo "OpenXPKI (Re)configuration Script"
82 echo "Copyright (c) 2006 by The OpenXPKI Project"
83 echo
85 while [ -n "$1" ] ; do
86 case "$1" in
87 --help)
88 pod2man $0 | nroff -man -Tascii
89 exit 0
91 --batch)
92 echo "Entering batch mode..."
93 INTERACTIVE=0
94 shift
96 --force)
97 FORCE="$1"
98 shift
100 --template)
101 TEMPLATE="$2"
102 shift
103 shift
105 --createdirs)
106 CREATE_DIRS=1
107 shift
110 shift
111 METACONF_OPTS="$*"
112 echo "Additional options to openxpki-metaconf: '$METACONF_OPTS'"
113 shift $#
116 echo "Usage: $0 OPTIONS"
117 echo "Options:"
118 echo " --batch Noninteractively reconfigure XML files from openxpki.conf"
119 exit 0;
121 esac
122 done
124 for DIR in /etc/openxpki /usr/local/etc/openxpki "$OPENXPKICONFDIR" "`pwd`/etc/openxpki" "`pwd`"; do
125 if [ -e "$DIR/openxpki.conf" ]; then
126 OPENXPKICONFDIR="$DIR"
128 done
130 CFG="openxpki-metaconf --config $OPENXPKICONFDIR/openxpki.conf $METACONF_OPTS"
132 echo "Configuring in $OPENXPKICONFDIR..."
134 if [ "$INTERACTIVE" = "1" ] ; then
135 if ! reconfigure ; then
136 echo "Exiting..."
137 exit 0
141 XMLSTYLE="`$CFG --getcfg deployment.xmlstyle`"
142 RUNUSER="`$CFG --getcfg server.runuser`"
143 RUNGROUP="`$CFG --getcfg server.rungroup`"
145 FILES="$TEMPLATEDIR/$TEMPLATE/log.conf"
147 case $XMLSTYLE in
148 multi-file)
149 echo "Creating configuration (multiple XML files)..."
150 FILES="$FILES `ls $TEMPLATEDIR/$TEMPLATE/*.xml`"
152 all-in-one)
153 echo "Creating configuration (single XML file)..."
154 FILES="$FILES $TEMPLATEDIR/$TEMPLATE/config.xml"
157 echo "Illegal deployment mode $XMLSTYLE"
158 exit 1
160 esac
162 write_config $FILES
164 if ! check_dirs $CREATE_DIRS ; then
165 echo
166 echo "One or more required directories do not exist. Please inspect the above"
167 echo "error output and either create the missing directories or run"
168 echo
169 echo "$0 [OPTIONS] --createdirs"
170 echo
171 echo "to automatically create them."
172 echo
173 exit 1
176 echo
177 echo "OpenXPKI instance configured successfully."
179 exit 0
181 :<<__EOF
183 ###########################################################################
185 =head1 NAME
187 openxpki-configure - Create OpenXPKI config files from meta-configuration.
189 =head1 USAGE
191 openxpki-configure [OPTIONS]
193 Options:
194 --help display this help text and exit
195 --batch non-interactive configuration
196 --force overwrite existing files
197 --template specify template (default: default)
198 --createdirs create missing directories
199 -- args following -- are literally passed to openxpki-metaconf
201 This script generates the OpenXPKI configuration files from a set of
202 templates (taken from $TEMPLATEDIR)
203 by filling in values specified in the OpenXPKI meta configuration
204 $OPENXPKICONFDIR/openxpki.conf.
206 Please note that this meta configuration is intended for getting
207 OpenXPKI up and running quickly. Beyond basic configuration there
208 are many configuration parameters that cannot be set by this approach.
210 (For a more advanced setup may be advisable to modify the settings in
211 OpenXPKI's XML configuration files directly and NOT use openxpki-configure.)
212 __EOF