blob: 68f8f99ee0985fac12633272d424e60865a238dd [file] [log] [blame]
#usage: bash replace_keyword.sh [PROJECTS...], postfix 'prj' not needed
#example: bash replace_keyword.sh MERCURY_FPGA_HOSTED
cd ../../
cp tools/project/replace_keyword.sh .
declare -A rename_list replace_list
#module_list=(config make/projects tools build)
#module_list=(work/slk work/lk work/linux-4.4 config work/base-files make/projects work/custom tools build work/bootloader_lte)
#rename_list=([mercury]=mt6298 [MERCURY]=MT6298)
#replace_list=([mercury]=mt6298 [MERCURY]=MT6298)
#module_list+=(work/slk work/lk work/linux-4.4 config work/base-files make/projects work/custom tools build work/bootloader_lte work/busybox work/slk)
module_list=(make work/mloader)
rename_list=([mercury]=mt6298 [MERCURY]=MT6298)
replace_list=([mercury]=mt6298 [MERCURY]=MT6298 [gen97p]=gen98 [GEN97P]=GEN98)
# rename folders under $1 with naming $2 to $3
function rename_folder {
retry=0
ret=0
echo -e "\033[0;32m"rename folders under $1 from $2 to $3 "\033[0m"
#retry for multiple matches, e.g., AAA/mercury/BBB/mercury/
while [ "$retry" != "5" ]; do
find $1 -execdir rename "s/$2/$3/" '{}' \+
ret=$?
if [ "$ret" == "0" ]; then
break
fi
retry=$((retry + 1))
echo ret=$ret, retry=$retry
done
}
# replace all content under folder $1 from $2 to $3
function replace_keyword {
echo -e "\033[0;32m"replace keyword $2 to $3 under folder $1"\033[0m"
grep -rl --exclude-dir=".git" $2 $1 | xargs sed -i "s/$2/$3/g"
}
function parse_module {
echo parse make/projects/$1.prj
module_list+=(`grep "p4:" make/projects/$1.prj | awk '{print "work/"$1}'`)
}
for proj in $@ ; do
parse_module "${proj}"
done
echo remove duplicate elements...
sorted_module_list=($(echo "${module_list[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
for module in "${!sorted_module_list[@]}"; do
for key in "${!rename_list[@]}"; do
rename_folder ${sorted_module_list[$module]} $key ${rename_list[$key]}
done
for key in "${!replace_list[@]}"; do
replace_keyword ${sorted_module_list[$module]} $key ${replace_list[$key]}
done
done
#uncomment to rollback
: '
for module in "${!sorted_module_list[@]}"; do
for key in "${!rename_list[@]}"; do
rename_folder ${sorted_module_list[$module]} ${rename_list[$key]} $key
done
for key in "${!replace_list[@]}"; do
replace_keyword ${sorted_module_list[$module]} ${replace_list[$key]} $key
done
done
'
#replace old build script with modified ones
cp build/* .
#restore this script since it may also be modified
mv replace_keyword.sh tools/project/.