always create required varibales in config file

This commit is contained in:
Praveen Arimbrathodiyil 2017-04-19 15:34:07 +05:30
parent 50856123c5
commit ba96466d12

141
debian/postinst vendored
View file

@ -138,77 +138,96 @@ case "$1" in
cd ${gitlab_app_root} cd ${gitlab_app_root}
# Obtain hostname from debconf db # Obtain hostname from debconf db
echo "Configuring hostname and email..."
db_get gitlab/fqdn db_get gitlab/fqdn
if [ "${RET}" != "" ]; then GITLAB_HOST=$RET
if ! grep GITLAB_HOST ${gitlab_debian_conf_private}; then GITLAB_EMAIL_FROM="no-reply@$GITLAB_HOST"
echo "Configuring hostname and email..." GITLAB_EMAIL_DISPLAY_NAME="Gitlab"
export GITLAB_HOST=${RET} # We need this to configure nginx below GITLAB_EMAIL_REPLY_TO="no-reply@$GITLAB_HOST"
cat <<EOF >> ${gitlab_debian_conf_private} db_get gitlab/user
GITLAB_HOST=${RET} gitlab_user=$RET
GITLAB_EMAIL_FROM="no-reply@${RET}" cp -a -f ${gitlab_debian_conf_private} ${gitlab_debian_conf_private}.tmp
GITLAB_EMAIL_DISPLAY_NAME="Gitlab"
GITLAB_EMAIL_REPLY_TO="no-reply@${RET}" # If the admin deleted or commented some variables but then set
EOF # 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 fi
mkdir -p /etc/gitlab/ssl
nginx_conf_example=${nginx_ssl_conf_example}
# Check if ssl option is selected # Check if letsencrypt option is selected
db_get gitlab/ssl db_get gitlab/letsencrypt
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}
if [ "${RET}" = "true" ]; then 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..." echo "Configuring letsencrypt..."
ln -sf /etc/letsencrypt/live/${GITLAB_HOST}/fullchain.pem \ ln -sf /etc/letsencrypt/live/${GITLAB_HOST}/fullchain.pem \
/etc/gitlab/ssl/gitlab.crt /etc/gitlab/ssl/gitlab.crt
ln -sf /etc/letsencrypt/live/${GITLAB_HOST}/privkey.pem \ ln -sf /etc/letsencrypt/live/${GITLAB_HOST}/privkey.pem \
/etc/gitlab/ssl/gitlab.key /etc/gitlab/ssl/gitlab.key
# Check if certificate is already present # Check if certificate is already present
if [ -e /etc/letsencrypt/live/${GITLAB_HOST}/fullchain.pem ]; then if [ -e /etc/letsencrypt/live/${GITLAB_HOST}/fullchain.pem ]; then
echo "Let's encrypt certificate already present." echo "Let's encrypt certificate already present."
else else
# Port 80 and 443 should be available for letsencrypt # Port 80 and 443 should be available for letsencrypt
if command -v nginx > /dev/null; then if command -v nginx > /dev/null; then
echo "Stopping nginx for letsencrypt..." echo "Stopping nginx for letsencrypt..."
invoke-rc.d nginx stop invoke-rc.d nginx stop
fi fi
letsencrypt -d ${GITLAB_HOST} certonly || { letsencrypt -d ${GITLAB_HOST} certonly || {
echo "letsencrypt auto configuration failed..." echo "letsencrypt auto configuration failed..."
echo "Stop your webserver and try running letsencrypt manually..." echo "Stop your webserver and try running letsencrypt manually..."
echo "letsencrypt -d ${GITLAB_HOST} certonly" echo "letsencrypt -d ${GITLAB_HOST} certonly"
} }
fi
fi fi
fi fi
fi
# Manage tmpfiles.d/gitlab.conf via ucf # Manage tmpfiles.d/gitlab.conf via ucf
test -f ${gitlab_tmpfiles_private} || \ test -f ${gitlab_tmpfiles_private} || \
@ -261,10 +280,6 @@ EOF
echo "Reloading nginx configuration..." echo "Reloading nginx configuration..."
invoke-rc.d nginx reload invoke-rc.d nginx reload
fi fi
else
echo "Failed to retrieve fully qualified domain name"
exit 1
fi
db_stop db_stop
echo "Create database if not present" echo "Create database if not present"