set -e
-
die() {
echo "$@" 1>&2
exit 1
}
-
generate_config_file() {
touch "$2"
chown "root:$username" "$2"
-e "s/__OPACSERVER__/$domain/g" \
-e "s/__INTRASERVER__/$intradomain/g" \
-e "s/__ZEBRA_PASS__/$zebrapwd/g" \
+ -e "s/__ZEBRA_MARC_FORMAT__/$ZEBRA_MARC_FORMAT/g" \
+ -e "s/__ZEBRA_LANGUAGE__/$ZEBRA_LANGUAGE/g" \
-e "s/__DB_NAME__/$mysqldb/g" \
-e "s/__DB_HOST__/$mysqlhost/g" \
-e "s/__DB_USER__/$mysqluser/g" \
"/etc/koha/sites/$1/koha-conf.xml"
}
-
# Set defaults and read config file, if it exists.
DOMAIN=""
INTRAPORT="8080"
INTRAPREFIX=""
INTRASUFFIX=""
DEFAULTSQL=""
+ZEBRA_MARC_FORMAT="marc21"
+ZEBRA_LANGUAGE="en"
if [ -e /etc/koha/koha-sites.conf ]
then
. /etc/koha/koha-sites.conf
fi
+[ $# -ge 2 ] && [ $# -le 6 ] ||
+ die "Usage: $0 [--create-db|--request-db|--populate-db] \
+[--marcflavor marc21|normarc|unimarc] \
+[--zebralang en|fr|nb] instancename"
+
+TEMP=`getopt -o crpm:l: -l create-db,request-db,populate-db,marcflavor:,zebralang: \
+ -n "$0" -- "$@"`
-# Parse command line.
-[ "$#" = 2 ] ||
- die "Usage: $0 [--create-db|--request-db|--populate-db] instancename"
-case "$1" in
- --create-db) op=create ;;
- --request-db) op=request ;;
- --populate-db) op=populate ;;
- *) die "Usage: $0 [--create-db|--request-db|--populate-db] instancename" ;;
-esac
+# Note the quotes around `$TEMP': they are essential!
+eval set -- "$TEMP"
+
+while true ; do
+ case "$1" in
+ -c|--create-db) op=create ; shift ;;
+ -r|--request-db) op=request ; shift ;;
+ -p|--populate-db) op=populate ; shift ;;
+ -m|--marcflavor) ZEBRA_MARC_FORMAT="$2" ; shift 2 ;;
+ -l|--zebralang) ZEBRA_LANGUAGE="$2" ; shift 2 ;;
+ -d|--defaultsql) DEFAULTSQL="$2" ; shift 2 ;;
+ --) shift ; break ;;
+ *) die "Internal error! " ;;
+ esac
+done
+
+name="$1"
-name="$2"
domain="$name$DOMAIN"
if [ "$INTRAPORT" = 80 ] || [ "$INTRAPORT" = "" ]
then
fi
adduser --no-create-home --disabled-login \
--gecos "Koha instance $username" \
+ --home "/var/lib/koha/$name" \
--quiet "$username"
# Create the site-specific directories.
# Generate Zebra database password.
zebrapwd="$(pwgen -1)"
-
# Set up MySQL database for this instance.
if [ "$op" = create ]
then
mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof
-CREATE DATABASE $mysqldb;
-CREATE USER '$mysqluser'@'%' IDENTIFIED BY '$mysqlpwd';
-GRANT ALL PRIVILEGES ON $mysqldb.* TO '$mysqluser';
+CREATE DATABASE \`$mysqldb\`;
+CREATE USER \`$mysqluser\`@'%' IDENTIFIED BY '$mysqlpwd';
+GRANT ALL PRIVILEGES ON \`$mysqldb\`.* TO \`$mysqluser\`;
FLUSH PRIVILEGES;
eof
fi
-
# Generate and install Apache site-available file and log dir.
generate_config_file apache-site.conf.in \
"/etc/apache2/sites-available/$name"
touch "$name-db-request.txt"
chmod 0600 "$name-db-request.txt"
cat > "$name-db-request.txt" << eof
-Please create a database and user on $mysqlhost as follows:
+Please create a MySQL database and user on $mysqlhost as follows:
database name: $mysqldb
database user: $mysqluser
# Start Zebra.
koha-start-zebra "$name"
fi
+
+
+if [ "$op" = request ]
+then
+ koha-disable "$name"
+fi
+
+echo <<eoh
+
+Email for this instance is disabled. When you're ready to enable it, use:
+koha-email-enable $name
+eoh