Clean up local variable usage - Backends

Combines cleanup for mysql, postgresql and rpc

Change-Id: I37b928a669146671c946fc1ccb8e3ef1a27a3891
diff --git a/lib/databases/postgresql b/lib/databases/postgresql
index 6e85d6e..fb6d304 100644
--- a/lib/databases/postgresql
+++ b/lib/databases/postgresql
@@ -42,11 +42,12 @@
 }
 
 function configure_database_postgresql {
+    local pg_conf pg_dir pg_hba root_roles
     echo_summary "Configuring and starting PostgreSQL"
     if is_fedora; then
-        PG_HBA=/var/lib/pgsql/data/pg_hba.conf
-        PG_CONF=/var/lib/pgsql/data/postgresql.conf
-        if ! sudo [ -e $PG_HBA ]; then
+        pg_hba=/var/lib/pgsql/data/pg_hba.conf
+        pg_conf=/var/lib/pgsql/data/postgresql.conf
+        if ! sudo [ -e $pg_hba ]; then
             if ! [[ $DISTRO =~ (rhel6) ]]; then
                 sudo postgresql-setup initdb
             else
@@ -54,25 +55,25 @@
             fi
         fi
     elif is_ubuntu; then
-        PG_DIR=`find /etc/postgresql -name pg_hba.conf|xargs dirname`
-        PG_HBA=$PG_DIR/pg_hba.conf
-        PG_CONF=$PG_DIR/postgresql.conf
+        pg_dir=`find /etc/postgresql -name pg_hba.conf|xargs dirname`
+        pg_hba=$pg_dir/pg_hba.conf
+        pg_conf=$pg_dir/postgresql.conf
     elif is_suse; then
-        PG_HBA=/var/lib/pgsql/data/pg_hba.conf
-        PG_CONF=/var/lib/pgsql/data/postgresql.conf
+        pg_hba=/var/lib/pgsql/data/pg_hba.conf
+        pg_conf=/var/lib/pgsql/data/postgresql.conf
         # initdb is called when postgresql is first started
-        sudo [ -e $PG_HBA ] || start_service postgresql
+        sudo [ -e $pg_hba ] || start_service postgresql
     else
         exit_distro_not_supported "postgresql configuration"
     fi
     # Listen on all addresses
-    sudo sed -i "/listen_addresses/s/.*/listen_addresses = '*'/" $PG_CONF
+    sudo sed -i "/listen_addresses/s/.*/listen_addresses = '*'/" $pg_conf
     # Set max_connections
-    sudo sed -i "/max_connections/s/.*/max_connections = $MAX_DB_CONNECTIONS/" $PG_CONF
+    sudo sed -i "/max_connections/s/.*/max_connections = $MAX_DB_CONNECTIONS/" $pg_conf
     # Do password auth from all IPv4 clients
-    sudo sed -i "/^host/s/all\s\+127.0.0.1\/32\s\+ident/$DATABASE_USER\t0.0.0.0\/0\tpassword/" $PG_HBA
+    sudo sed -i "/^host/s/all\s\+127.0.0.1\/32\s\+ident/$DATABASE_USER\t0.0.0.0\/0\tpassword/" $pg_hba
     # Do password auth for all IPv6 clients
-    sudo sed -i "/^host/s/all\s\+::1\/128\s\+ident/$DATABASE_USER\t::0\/0\tpassword/" $PG_HBA
+    sudo sed -i "/^host/s/all\s\+::1\/128\s\+ident/$DATABASE_USER\t::0\/0\tpassword/" $pg_hba
     restart_service postgresql
 
     # Create the role if it's not here or else alter it.
@@ -86,14 +87,14 @@
 
 function install_database_postgresql {
     echo_summary "Installing postgresql"
-    PGPASS=$HOME/.pgpass
-    if [[ ! -e $PGPASS ]]; then
-        cat <<EOF > $PGPASS
+    local pgpass=$HOME/.pgpass
+    if [[ ! -e $pgpass ]]; then
+        cat <<EOF > $pgpass
 *:*:*:$DATABASE_USER:$DATABASE_PASSWORD
 EOF
-        chmod 0600 $PGPASS
+        chmod 0600 $pgpass
     else
-        sed -i "s/:root:\w\+/:root:$DATABASE_PASSWORD/" $PGPASS
+        sed -i "s/:root:\w\+/:root:$DATABASE_PASSWORD/" $pgpass
     fi
     if is_ubuntu; then
         install_package postgresql