[DRE-commits] [gitlab] 04/04: always create required varibales in config file

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Wed Apr 19 12:51:54 UTC 2017


This is an automated email from the git hooks/post-receive script.

praveen pushed a commit to branch master
in repository gitlab.

commit ba96466d1297f51c6b493620f7ad5932d8a6970c
Author: Praveen Arimbrathodiyil <praveen at debian.org>
Date:   Wed Apr 19 15:34:07 2017 +0530

    always create required varibales in config file
---
 debian/postinst | 143 +++++++++++++++++++++++++++++++-------------------------
 1 file changed, 79 insertions(+), 64 deletions(-)

diff --git a/debian/postinst b/debian/postinst
index f05420d..351b638 100755
--- a/debian/postinst
+++ b/debian/postinst
@@ -138,77 +138,96 @@ case "$1" in
     cd ${gitlab_app_root}
 
     # Obtain hostname from debconf db
+    echo "Configuring hostname and email..."
     db_get gitlab/fqdn
-    if [ "${RET}" != "" ]; then
-      if ! grep GITLAB_HOST ${gitlab_debian_conf_private}; then
-        echo "Configuring hostname and email..."
-        export GITLAB_HOST=${RET} # We need this to configure nginx below
-	cat <<EOF >> ${gitlab_debian_conf_private}
-GITLAB_HOST=${RET} 
-GITLAB_EMAIL_FROM="no-reply@${RET}"
-GITLAB_EMAIL_DISPLAY_NAME="Gitlab"
-GITLAB_EMAIL_REPLY_TO="no-reply@${RET}"
-EOF
+    GITLAB_HOST=$RET
+    GITLAB_EMAIL_FROM="no-reply@$GITLAB_HOST"
+    GITLAB_EMAIL_DISPLAY_NAME="Gitlab"
+    GITLAB_EMAIL_REPLY_TO="no-reply@$GITLAB_HOST"
+    db_get gitlab/user
+    gitlab_user=$RET
+    cp -a -f ${gitlab_debian_conf_private} ${gitlab_debian_conf_private}.tmp
+
+    # If the admin deleted or commented some variables but then set
+    # them via debconf, (re-)add them to the conffile.
+    test -z "$GITLAB_HOST" || grep -Eq '^ *GITLAB_HOST=' ${gitlab_debian_conf_private} || \
+        echo "GITLAB_HOST=" >> ${gitlab_debian_conf_private}
+    test -z "$GITLAB_EMAIL_FROM" || grep -Eq '^ *GITLAB_EMAIL_FROM=' ${gitlab_debian_conf_private} || \
+        echo "GITLAB_EMAIL_FROM=" >> ${gitlab_debian_conf_private}
+    test -z "$GITLAB_EMAIL_DISPLAY_NAME" || grep -Eq '^ *GITLAB_EMAIL_DISPLAY_NAME=' ${gitlab_debian_conf_private} || \
+        echo "GITLAB_EMAIL_DISPLAY_NAME=" >> ${gitlab_debian_conf_private}
+    test -z "$GITLAB_EMAIL_REPLY_TO" || grep -Eq '^ *GITLAB_EMAIL_REPLY_TO=' ${gitlab_debian_conf_private} || \
+        echo "GITLAB_EMAIL_REPLY_TO=" >> ${gitlab_debian_conf_private}
+    test -z "$gitlab_user" || grep -Eq '^ *gitlab_user=' ${gitlab_debian_conf_private} || \
+        echo "gitlab_user=" >> ${gitlab_debian_conf_private}
+    sed -e "s/^ *GITLAB_HOST=.*/GITLAB_HOST=\"$GITLAB_HOST\"/" \
+        -e "s/^ *GITLAB_EMAIL_FROM=.*/GITLAB_EMAIL_FROM=\"$GITLAB_EMAIL_FROM\"/" \
+        -e "s/^ *GITLAB_EMAIL_DISPLAY_NAME=.*/GITLAB_EMAIL_DISPLAY_NAME=\"$GITLAB_EMAIL_DISPLAY_NAME\"/" \
+        -e "s/^ *GITLAB_EMAIL_REPLY_TO=.*/GITLAB_EMAIL_REPLY_TO=\"$GITLAB_EMAIL_REPLY_TO\"/" \
+        -e "s/^ *gitlab_user=.*/gitlab_user=\"$gitlab_user\"/" \
+            < ${gitlab_debian_conf_private} > ${gitlab_debian_conf_private}.tmp
+        mv -f ${gitlab_debian_conf_private}.tmp ${gitlab_debian_conf_private}
+
+    # Check if ssl option is selected
+    db_get gitlab/ssl
+    gl_proto="http"
+
+    # Copy example configurations
+    test -f ${gitlab_yml_private} || \
+    cp ${gitlab_yml_example} ${gitlab_yml_private}
+    test -f ${gitlab_shell_config_private} || \
+    cp ${gitlab_shell_config_example} ${gitlab_shell_config_private}
+
+    # Set gitlab user first time
+    sed -i "s/GITLAB_USER/${gitlab_user}/" ${gitlab_yml_private}
+    # Update gitlab user (its a hack, proper fix is to have gitlab accept GITLAB_USER variable)
+    sed -i "s/^ *user:.* #gitlab_user/    user: $gitlab_user #gitlab_user/" ${gitlab_yml_private}
+
+    if [ "${RET}" = "true" ]; then
+      echo "Configuring nginx with HTTPS..."
+      if ! grep GITLAB_HTTPS ${gitlab_debian_conf_private}; then
+  	  echo GITLAB_HTTPS=${RET} >> ${gitlab_debian_conf_private}
+  	  # Workaround for #813770
+  	  gl_proto="https"
+  	  echo "Configuring gitlab with HTTPS..."
+   	  sed -i "s/#port: 80/port: 443/" ${gitlab_yml_private}
+  	  sed -i "s/https: false/https: true/" ${gitlab_yml_private}
+        echo "Updating gitlab_url in gitlab-shell configuration..."
+        sed -i \
+  	  "s/gitlab_url: http*:\/\/.*/gitlab_url: ${gl_proto}:\/\/${GITLAB_HOST}/"\
+  	  ${gitlab_shell_config_private}
       fi
+      
+      mkdir -p /etc/gitlab/ssl
+      nginx_conf_example=${nginx_ssl_conf_example}
 
-      # Check if ssl option is selected
-      db_get gitlab/ssl
-      gl_proto="http"
-
-      # Copy example configurations
-      test -f ${gitlab_yml_private} || \
-      cp ${gitlab_yml_example} ${gitlab_yml_private}
-      test -f ${gitlab_shell_config_private} || \
-      cp ${gitlab_shell_config_example} ${gitlab_shell_config_private}
-
-      sed -i "s/GITLAB_USER/${gitlab_user}/" ${gitlab_yml_private}
-
+      # Check if letsencrypt option is selected
+      db_get gitlab/letsencrypt
       if [ "${RET}" = "true" ]; then
-        echo "Configuring nginx with HTTPS..."
-        if ! grep GITLAB_HTTPS ${gitlab_debian_conf_private}; then
-	  echo GITLAB_HTTPS=${RET} >> ${gitlab_debian_conf_private}
-	  # Workaround for #813770
-	  gl_proto="https"
-	  echo "Configuring gitlab with HTTPS..."
- 	  sed -i "s/#port: 80/port: 443/" ${gitlab_yml_private}
-	  sed -i "s/https: false/https: true/" ${gitlab_yml_private}
-          echo "Updating gitlab_url in gitlab-shell configuration..."
-          sed -i \
-	  "s/gitlab_url: http*:\/\/.*/gitlab_url: ${gl_proto}:\/\/${GITLAB_HOST}/"\
-	  ${gitlab_shell_config_private}
-
-	fi
-        
-        mkdir -p /etc/gitlab/ssl
-        nginx_conf_example=${nginx_ssl_conf_example}
-
-        # Check if letsencrypt option is selected
-        db_get gitlab/letsencrypt
-        if [ "${RET}" = "true" ]; then
 	  echo "Configuring letsencrypt..."
-          ln -sf /etc/letsencrypt/live/${GITLAB_HOST}/fullchain.pem \
-          /etc/gitlab/ssl/gitlab.crt
-          ln -sf /etc/letsencrypt/live/${GITLAB_HOST}/privkey.pem \
-          /etc/gitlab/ssl/gitlab.key
+        ln -sf /etc/letsencrypt/live/${GITLAB_HOST}/fullchain.pem \
+        /etc/gitlab/ssl/gitlab.crt
+        ln -sf /etc/letsencrypt/live/${GITLAB_HOST}/privkey.pem \
+        /etc/gitlab/ssl/gitlab.key
 	    
-	  # Check if certificate is already present
-	  if [ -e /etc/letsencrypt/live/${GITLAB_HOST}/fullchain.pem ]; then
-	    echo "Let's encrypt certificate already present."
-	  else
-	    # Port 80 and 443 should be available for letsencrypt
-	    if command -v nginx > /dev/null; then
-	      echo "Stopping nginx for letsencrypt..."
-	      invoke-rc.d nginx stop
-	    fi
-
-	    letsencrypt -d ${GITLAB_HOST} certonly || {
+        # Check if certificate is already present
+        if [ -e /etc/letsencrypt/live/${GITLAB_HOST}/fullchain.pem ]; then
+          echo "Let's encrypt certificate already present."
+        else
+          # Port 80 and 443 should be available for letsencrypt
+          if command -v nginx > /dev/null; then
+	    echo "Stopping nginx for letsencrypt..."
+	    invoke-rc.d nginx stop
+	  fi
+
+	  letsencrypt -d ${GITLAB_HOST} certonly || {
 	    echo "letsencrypt auto configuration failed..."
 	    echo "Stop your webserver and try running letsencrypt manually..."
 	    echo "letsencrypt -d ${GITLAB_HOST} certonly" 
-	    }
-	  fi
+	  }
         fi
       fi
+    fi
 
       # Manage tmpfiles.d/gitlab.conf via ucf
       test -f ${gitlab_tmpfiles_private} || \
@@ -261,10 +280,6 @@ EOF
         echo "Reloading nginx configuration..."
         invoke-rc.d nginx reload
       fi
-    else
-      echo "Failed to retrieve fully qualified domain name"
-      exit 1
-    fi
     db_stop
 
     echo "Create database if not present"

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/gitlab.git



More information about the Pkg-ruby-extras-commits mailing list