Simplify entrypoint Gerrit script

Before this change the modification of the gerrit.config
was happening in different places and there were
several conditional statements.

Now the logic is more linear:
1. Populate gerrit.config and secure.config
2. Init, if needed
3. Run Gerrit

This refactoring will be particular useful later on when adding further
logic to handle, for example, the different init phases of master and slave.

Change-Id: I49e0e4c46e6aa73510dfb80bc763fdc288ddbecd
Feature: Issue 12554
diff --git a/gerrit/entrypoint.sh b/gerrit/entrypoint.sh
index a442c20..ac397ed 100755
--- a/gerrit/entrypoint.sh
+++ b/gerrit/entrypoint.sh
@@ -1,20 +1,15 @@
 #!/bin/bash -e
 
+/tmp/setup_gerrit.py
+git config -f /var/gerrit/etc/gerrit.config gerrit.canonicalWebUrl "${CANONICAL_WEB_URL:-http://$HOSTNAME}"
+git config -f /var/gerrit/etc/gerrit.config httpd.listenUrl "${HTTPD_LISTEN_URL:-http://*:8080/}"
+
 if [ ! -d /var/gerrit/git/All-Projects.git ] || [ "$1" == "init" ]
 then
   rm -fr /var/gerrit/plugins/*
   echo "Initializing Gerrit site ..."
-  java -jar /var/gerrit/bin/gerrit.war init --batch --install-all-plugins -d /var/gerrit
-  java -jar /var/gerrit/bin/gerrit.war reindex -d /var/gerrit
-  git config -f /var/gerrit/etc/gerrit.config --add container.javaOptions "-Djava.security.egd=file:/dev/./urandom"
+  java -jar /var/gerrit/bin/gerrit.war init --batch --no-auto-start --install-all-plugins -d /var/gerrit
 fi
 
-git config -f /var/gerrit/etc/gerrit.config gerrit.canonicalWebUrl "${CANONICAL_WEB_URL:-http://$HOSTNAME}"
-git config -f /var/gerrit/etc/gerrit.config httpd.listenUrl "${HTTPD_LISTEN_URL:-http://*:8080/}"
-
-if [ "$1" != "init" ]
-then
-  /tmp/setup_gerrit.py
-  echo "Running Gerrit ..."
-  exec /var/gerrit/bin/gerrit.sh run
-fi
+echo "Running Gerrit ..."
+exec /var/gerrit/bin/gerrit.sh run