#!/bin/bash # Ver: 1.3 by Endial Fang (endial@126.com) # # 应用通用业务处理函数 . /usr/local/lib/libcommon.sh # 通用函数库 . /usr/local/lib/libfile.sh . /usr/local/lib/libfs.sh . /usr/local/lib/liblog.sh . /usr/local/lib/libos.sh . /usr/local/lib/libservice.sh . /usr/local/lib/libvalidations.sh # 检测应用相应的配置文件是否存在,如果不存在,则从默认配置文件目录拷贝一份 # 默认配置文件路径:/etc/${APP_NAME} # 目标配置文件路径:/srv/conf/${APP_NAME} # 参数: # $1 - 目标路径 # $2 - 源路径 # $* - 基础路径下的文件及目录列表,以" "分割 # 例子: # ensure_config_file_exist /etc/${APP_NAME} conf.d server.conf app_ensure_config_file_exist() { local -r dist_path="${1:?dist paths is missing}" local -r base_path="${2:?source paths is missing}" local f="" shift 2 debug "List to check in ${base_path}: $@" while [ "$#" -gt 0 ]; do f="${1}" debug " Process \"${f}\"" if [ -d "${base_path}/${f}" ]; then [[ ! -d "${dist_path}/${f}" ]] && debug " Create directory: ${dist_path}/${f}" && mkdir -p "${dist_path}/${f}" [[ ! -z $(ls -A "${base_path}/${f}") ]] && app_ensure_config_file_exist "${dist_path}/${f}" "${base_path}/${f}" $(ls -A "${base_path}/${f}") else [[ ! -e "${dist_path}/${f}" ]] && debug " Copy: ${base_path}/${f} to ${dist_path}" && cp "${base_path}/${f}" "${dist_path}" fi shift done }