check varibales are defined before using them

This commit is contained in:
Praveen Arimbrathodiyil 2017-04-17 11:05:50 +05:30
parent 20c77e7cb7
commit 8ed3768bb3

61
debian/postrm vendored
View file

@ -18,8 +18,18 @@ gitlab_debian_defaults=/var/lib/gitlab/gitlab-debian.defaults
# Ensure the menu system is updated # Ensure the menu system is updated
# Read debian specific configuration # Read debian specific configuration
test -f ${gitlab_debian_conf} && . ${gitlab_debian_conf} if [ -f ${gitlab_debian_conf} ]; then . ${gitlab_debian_conf}; fi
test -f ${gitlab_debian_defaults} && . ${gitlab_debian_defaults} if [ -f ${gitlab_debian_defaults}; then . ${gitlab_debian_defaults}; fi
safely_remove() {
CANDIDATE_DIR=$1
if [ -n ${CANDIDATE_DIR} ];then
if [ -e ${CANDIDATE_DIR} ]; then
echo "Removing $i..."
rm -rf ${CANDIDATE_DIR}
fi
fi
}
case "$1" in case "$1" in
remove) remove)
@ -53,10 +63,10 @@ case "$1" in
if [ -e ${gitlab_data_dir}/$i ]; then rm -rf ${gitlab_data_dir}/$i; fi if [ -e ${gitlab_data_dir}/$i ]; then rm -rf ${gitlab_data_dir}/$i; fi
done done
fi fi
if [ -e ${gitlab_log_dir} ]; then rm -rf ${gitlab_log_dir}; fi for i in ${gitlab_log_dir} ${gitlab_cache_path} ${gitlab_pid_path} \
if [ -e ${gitlab_cache_path} ]; then rm -rf ${gitlab_cache_path}; fi ${gitlab_data_dir}; do
if [ -e ${gitlab_pid_path} ]; then rm -rf ${gitlab_pid_path}; fi safely_remove $i
if [ -e ${gitlab_data_dir} ]; then rm -rf ${gitlab_data_dir}; fi done
if [ ! -z "${gitlab_user}" ]; then if [ ! -z "${gitlab_user}" ]; then
# Do only if gitlab_user is set # Do only if gitlab_user is set
if command -v dropdb >/dev/null; then if command -v dropdb >/dev/null; then
@ -70,7 +80,7 @@ case "$1" in
else else
echo "gitlab_user not set. Hence not removing user." echo "gitlab_user not set. Hence not removing user."
fi fi
rm -rf ${gitlab_ssl_path} safely_remove ${gitlab_ssl_path}
fi fi
# Remove my changes to the db. # Remove my changes to the db.
@ -93,32 +103,21 @@ case "$1" in
rm -f ${gitlab_shell_config}$ext rm -f ${gitlab_shell_config}$ext
done done
# remove the configuration file itself for i in ${nginx_site} ${gitlab_debian_conf} ${gitlab_yml} \
if [ -f ${nginx_site} ]; then rm -f ${nginx_site}; fi ${gitlab_tmpfiles} ${gitlab_shell_config}; do
if [ -f ${gitlab_debian_conf} ]; then rm -f ${gitlab_debian_conf}; fi # remove the configuration file itself
if [ -f ${gitlab_yml} ]; then rm -f ${gitlab_yml}; fi safely_remove $i
if [ -f ${gitlab_tmpfiles} ]; then rm -f ${gitlab_tmpfiles}; fi # and finally clear it out from the ucf database
if [ -f ${gitlab_shell_config} ]; then rm -f ${gitlab_shell_config}; fi if which ucf >/dev/null; then
if [ -n "$i" ]; then ucf --purge $i; fi
# and finally clear it out from the ucf database fi
if which ucf >/dev/null; then if which ucfr >/dev/null; then
if [ -n "${nginx_site}" ]; then ucf --purge ${nginx_site}; fi if [ -n "$i" ]; then ucfr --purge gitlab $i; fi
if [ -n "${gitlab_debian_conf}" ]; then ucf --purge ${gitlab_debian_conf}; fi fi
if [ -n "${gitlab_yml}" ]; then ucf --purge ${gitlab_yml}; fi done
if [ -n "${gitlab_tmpfiles}" ]; then ucf --purge ${gitlab_tmpfiles}; fi
if [ -n "${gitlab_shell_config}"; then ucf -purge ${gitlab_shell_config}; fi
fi
if which ucfr >/dev/null; then
if [ -n "${nginx_site}" ]; then ucfr --purge gitlab ${nginx_site}; fi
if [ -n "${gitlab_debian_conf}" ]; then ucfr --purge gitlab ${gitlab_debian_conf}; fi
if [ -n "${gitlab_yml}" ]; then ucfr --purge gitlab ${gitlab_yml}; fi
if [ -n "${gitlab_tmpfiles}" ]; then ucfr --purge gitlab ${gitlab_tmpfiles}; fi
if [ -n "${gitlab_shell_config}" ]; then ucfr -purge gitlab ${gitlab_shell_config}; fi
fi
# remove generated assets # remove generated assets
rm -rf ${gitlab_data_dir}/public/assets if [ -n ${gitlab_data_dir}]; then safely_remove ${gitlab_data_dir}/public/assets; fi
# Remove private copies of configuration files # Remove private copies of configuration files
rm -f ${nginx_site_private} rm -f ${nginx_site_private}