From: Frank Brehm Date: Tue, 28 May 2019 13:24:35 +0000 (+0200) Subject: Checking dirs in bin/backup-pgsql.sh X-Git-Tag: 0.4.1~11^2~1 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=6ba45aa07bcf5d469f914a3643c82d9939bded43;p=pixelpark%2Fpp-admin-tools.git Checking dirs in bin/backup-pgsql.sh --- diff --git a/bin/get-k8s-master-configs b/bin/get-k8s-master-configs index 0905b8d..279d793 100755 --- a/bin/get-k8s-master-configs +++ b/bin/get-k8s-master-configs @@ -241,6 +241,101 @@ error() { echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASENAME}:${RED}ERROR${NORMAL}]: $@" >&2 } +#------------------------------------------------------------------------------ +MKDIR() { + local cmd="mkdir" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd+=" --verbose" + fi + eval ${cmd} "$@" +} + +#------------------------------------------------------------------------------ +CHMOD() { + local cmd="chmod" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd+=" --verbose" + fi + eval ${cmd} "$@" +} + +#------------------------------------------------------------------------------ +CHOWN() { + local cmd="chown" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd+=" --verbose" + fi + eval ${cmd} "$@" +} + +#------------------------------------------------------------------------------ +CHGRP() { + local cmd="chgrp" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd+=" --verbose" + fi + eval ${cmd} "$@" +} + +#------------------------------------------------------------------------------ +check_home_dirs() { + + local my_user_home="$1" + local my_user="$2" + local my_group="$3" + + local k8s_dir="${my_user_home}/${REL_K8S_CFGDIR}" + + debug "Checking directories '${my_user_home}' and '${k8s_dir}' ..." + + if [[ -z "${my_user_home}" ]] ; then + error "Could not evaluate \$HOME of user '${RED}${my_user}${NORMAL}'." + return 6 + fi + + if [[ ! -e "${my_user_home}" ]] ; then + error "Directory '${RED}${my_user_home}${NORMAL}' does not exists." + return 6 + fi + + if [[ ! -d "${my_user_home}" ]] ; then + error "Path '${RED}${my_user_home}${NORMAL}' exists, but is not a directory." + return 6 + fi + + if [[ -e "${k8s_dir}" ]] ; then + MKDIR -p "${k8s_dir}" + else + if [[ ! -d "${k8s_dir}" ]] ; then + error "Path '${RED}${k8s_dir}${NORMAL}' exists, but is not a directory." + return 6 + fi + fi + + local dir_owner=$( stat --printf="%U" "${k8s_dir}" ) + local dir_group=$( stat --printf="%G" "${k8s_dir}" ) + local dir_mode=$( stat --printf="%a" "${k8s_dir}" ) + debug "Directory '${k8s_dir}' current: owner='${dir_owner}', group='${dir_group}', mode='${dir_mode}'" + + if [[ "${dir_owner}" != "${my_user}" ]] ; then + info "Setting owner of '${k8s_dir}' to '${my_user}'." + CHOWN "${my_user}" "${k8s_dir}" + fi + + if [[ "${dir_group}" != "${my_group}" ]] ; then + info "Setting group of '${k8s_dir}' to '${my_group}'." + CHGRP "${my_group}" "${k8s_dir}" + fi + + if [[ "${dir_mode}" != "700" ]] ; then + info "Setting mode of '${k8s_dir}' to 0700." + CHMOD "0700" "${k8s_dir}" + fi + + return 0 + +} + #------------------------------------------------------------------------------ get_config() { @@ -261,8 +356,12 @@ get_config() { debug "URL to get the config: '${url}'." local user_home=$( getent passwd "${user}" | head -n 1 | awk -F: '{print $6}' ) - debug "Home diectory of user '${user}': '${user_home}'" - + debug "Home directory of user '${user}': '${user_home}'" + if check_home_dirs "${user_home}" "${user}" "${group}" ; then + : + else + continue + fi }