#! /bin/sh _DIRNAME=$(dirname $0) _CUR_PATH=$(cd ${_DIRNAME}; pwd) . ${_CUR_PATH}/update_version.conf MATEINFO_HOME=/opt/mateinfo YMAL_Dir=$(date --date= +%Y%m%d) # 替换文件中某个字符串 # 参数1:原始字符 # 参数2:目标字符 # 参数3:文件路径 # yaml模板在${MATEINFO_HOME}/ict_env/ # 更新在${MATEINFO_HOME}/ict_env/history_yaml/ # 每次更新时yaml文件以当前时间为准 # 执行过程:更新版本时先从模板中建立以当前时间为准的yaml文件,执行完以后保存在/opt/mateinfo/history_yaml/$YMAL_Dir目录中 function _replace_param() { local src_word=$1 local dst_word=$2 local file_path=$3 if [ $(echo ${src_word} | grep "image" | wc -l) -gt 0 -o $(echo ${dst_word} | grep "image" | wc -l) -gt 0 ] then { sed -i "s/${src_word}/${dst_word}/g" ${file_path} } else { sed -i "s+${src_word}+${dst_word}+g" ${file_path} } fi } function main() { cd /opt/mateinfo/ict_env/history_yaml/ict_plateform && rm -rf $YMAL_Dir && mkdir $YMAL_Dir cp -f ${MATEINFO_HOME}/ict_env/ict_plateform/* $YMAL_Dir/ _replace_param "@{APP_VERSION}" ${APP_VERSION} $YMAL_Dir/app.yaml _replace_param "@{BATCH_VERSION}" ${BATCH_VERSION} $YMAL_Dir/batch.yaml _replace_param "@{WSERSION}" ${WSERSION} $YMAL_Dir/ws.yaml #cd $YMAL_Dir #kubectl apply -f ./ } main [email protected] 2>&1 cat update_version.conf #VERSION APP_VERSION=app:2n15415485115d BATCH_VERSION=batch:2nd WS_VERSION=ws:1211881 TOMCAT_VERSION=tomcat:323265 CAS_VERSION=cas:158987 SERVICECREATOR_VERSION=servicecreator:781215991 ________________________________________________________ 目录结构: [[email protected] ict_plateform]# ls app.yaml batch.yaml cas.yaml servicecreator.yaml tomcat.yaml ws.yaml(模板)) [[email protected] ict_plateform]# pwd /opt/mateinfo/ict_env/ict_plateform [[email protected] ict_plateform]# cat /opt/mateinfo/ict_env/history_yaml/ict_plateform/20180304/batch.yaml (更新)