项目使用新的规范,需要将之前的工程重新修改,写一shell脚本,输入老工程名,新工程名来替换里面需要替换的部分
#!/bin/bash
if [ $# -ne 2 ] ;
then
echo "please enter an old project name and a new project name!"
else
old_name=$1
new_name=$2
len=$(expr length "${new_name}")
let "len = len - 3"
pro_name=$(echo ${new_name}|cut -c1-$len)
workflow_name=$(echo ${new_name}|cut -c1-$len)"-wf"
echo "DEBUG: old name is: "${old_name}", new name is: "${new_name}", workflow name is: "${workflow_name}
echo "DEBUG: rename project name..."
mv ${old_name} ${new_name}
cd ${new_name}
echo "DEBUG: rename properties"
mv ${old_name}.properties ${new_name}.properties
sed -i "s:bd-wh/bd-wh-common:bd-wh-common-cd:g" ${new_name}.properties
sed -i "s:bd-wh/${old_name}:${new_name}:g" ${new_name}.properties
echo "DEBUG: replace runjob.sh"
sed -i "s:bd-wh/bd-wh-common:bd-wh-common-cd:g" runJob.sh
sed -i "s:bd-wh/${old_name}:${new_name}:g" runJob.sh
sed -i "s:${old_name}.properties:${new_name}.properties:g" runJob.sh
echo "DEBUG: replace coordinator.xml"
sed -i "s:${old_name}-cd:${new_name}:g" coordinator.xml
sed -i "s:${old_name}.dataset:${new_name}-dataset:g" coordinator.xml
datasets_begin=$(grep -n "<datasets>" coordinator.xml | cut -d ":" -f 1)
datasets_end=$(grep -n "</datasets>" coordinator.xml | cut -d ":" -f 1)
let "dataset_begin = datasets_begin + 1"
let "dataset_end = datasets_end - 1"
echo "DEBUG: delete dataset dataset_begin: "${dataset_begin}", dataset_end: "${dataset_end}
sed -i ${dataset_begin},${dataset_end}d coordinator.xml
common_dataset='\ \ \ \ <include>${hdfs_address_prefix}/bd-wh-common-cd/datasets.xml</include>'
sed -i "${datasets_begin}a${common_dataset}" coordinator.xml
echo "DEBUG: replace workflow.xml"
sed -i "s:${old_name}-wf:${workflow_name}:g" workflow*.xml
sed -i "s:${old_name}:${pro_name}:g" workflow*.xml
echo "DEBUG: replace putShell.sh"
sed -i "s:bd-wh/::g" putShell.sh
reRunJob=reRunJob.sh
if [ -f "${reRunJob}" ]; then
echo "DEBUG: replace reRunJob.sh"
sed -i "s:bd-wh/${old_name}/${old_name}:${new_name}/${new_name}:g" ${reRunJob}
fi
echo "DEBUG: dos2unix ..."
dos2unix *.*
echo "DEBUG: checking ..."
grep -ER "bd-wh|bd-wh-common|${old_name}" .
echo "DEBUG: checked."
#sed -i "s:bd-wh/${old_name}:${new_name}:g" `grep 'bd-wh.${old_name}' -rl ${cpath}`
fi