B) Use keystone config files from source; move to /etc/keystone

* Put all config files in /etc/keystone
* keystone.conf rewritten
* logging.conf.sample rewritten to logging.conf
* default_catalog.templates copied from devstack/files
* iniset() now properly adds options that do not previously exist

Fixed to re-configure the catalog templated backend; sql is the
default in trunk now but DevStack needs a bit more work before
it can use it.

Change-Id: Ic7060ef897e47495cd08ca3786e49fdebadf6723
diff --git a/functions b/functions
index ecfda05..5114de1 100644
--- a/functions
+++ b/functions
@@ -184,7 +184,7 @@
 
 
 # Comment an option in an INI file
-# optset config-file section option
+# iniset config-file section option
 function inicomment() {
     local file=$1
     local section=$2
@@ -194,7 +194,7 @@
 
 
 # Get an option from an INI file
-# optget config-file section option
+# iniget config-file section option
 function iniget() {
     local file=$1
     local section=$2
@@ -206,16 +206,25 @@
 
 
 # Set an option in an INI file
-# This is NOT a complete option setter, it assumes that the section and
-# option already exist in the INI file.  If the section does not exist,
-# nothing happens.
-# optset config-file section option value
+# iniset config-file section option value
 function iniset() {
     local file=$1
     local section=$2
     local option=$3
     local value=$4
-    sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" $file
+    if ! grep -q "^\[$section\]" $file; then
+        # Add section at the end
+        echo -e "\n[$section]" >>$file
+    fi
+    if [[ -z "$(iniget $file $section $option)" ]]; then
+        # Add it
+        sed -i -e "/^\[$section\]/ a\\
+$option = $value
+" $file
+    else
+        # Replace it
+        sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" $file
+    fi
 }