Files
yinmeng-android/gen_move_dir_ktx.sh

58 lines
1.7 KiB
Bash
Raw Normal View History

#!/bin/bash
# 遍历当前文件下所有子目录生成dir_mapping对应的K -> V
# 过滤条件:需包含的路径&&
include_path=("src/" "java/" "ktx")
# 过滤条件:不能包含的路径||
exclude_path=("src/test" "src/androidTest")
# 过滤条件:判断是否需要混淆(包中包含这些文件)
file_extensions=("java" "kt")
# 决定了输出位置K输出这个路径后的路径
start_path="java/"
# 混淆后的包前缀(随机获取)
package_array=("app.yinm.ktx.")
touch move_dir.txt
find_include=""
for a in "${include_path[@]}"; do
find_include+=" -path \"*$a*\""
done
find_exclude=""
for b in "${exclude_path[@]}"; do
find_exclude+=" -not -path \"*$b*\""
done
# 构造文件扩展名参数
file_ext_args=()
for ext in "${file_extensions[@]}"; do
file_ext_args+=("-o" "-name" "*.$ext")
done
# 删除第一个 -o
file_ext_args=("${file_ext_args[@]:1}")
# 将 file_ext_args 转换为字符串
file_ext_args_str=$(IFS=" "; echo "${file_ext_args[*]}")
# 使用find命令遍历子目录找到符合条件的目录
eval "find . -type d $find_include $find_exclude -exec sh -c 'test -n \"\$(find "{}" -maxdepth 1 -type f \( $file_ext_args_str \))\"' \; -print" | while IFS= read -r dir; do
if [[ "$dir" == *"$start_path"* ]]; then
key=$(echo "$dir" | awk -F "$start_path" '{print $NF}' | tr '/' '.')
else
key=$(echo "$dir" | tr '/' '.')
fi
value=$(echo "$key" | md5 | sed 's/[0-9]//g')
random_index=$((RANDOM % ${#package_array[@]}))
random_package=${package_array[$random_index]}
move_dir="\"$key\" : \"$random_package$value\","
echo $move_dir
echo $move_dir >> move_dir.txt
done