manifest.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. if [[ $# -lt 2 ]]; then
  2. echo "usage: manifest executable path"
  3. exit -1
  4. fi
  5. # 生成比较正经一点的名字, 但需要字典支持
  6. if [ -f "dictionary.txt" ]; then
  7. WORDs=(`cat "dictionary.txt" | cut -d ' ' -f1`)
  8. fi
  9. function RANDOM_NAME() {
  10. if [ -n $WORDs ]; then
  11. local name=
  12. while [ ${#name} -lt 16 ]; do
  13. local index=$(($RANDOM%${#WORDs[@]}))
  14. name="${name}_${WORDs[${index}]}"
  15. done
  16. # 删除中划线并且将首字母大写
  17. echo ${name:1} #| awk -F[-] '{for(i=1;i<=NF;i++) printf toupper(substr($i,1,1)) substr($i,2); printf "\n";}'
  18. else
  19. # 生成uuid类型的名字
  20. echo `openssl rand -hex 8`
  21. fi
  22. };
  23. executable="${1}"
  24. rootp=`dirname "$executable"`
  25. manifest="${1}.plist"
  26. name=`basename "$executable"`
  27. echo $rootp
  28. cp=`pwd`
  29. cd "$rootp"
  30. shift 1
  31. printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" > "$manifest"
  32. printf "<plist version=\"1.0\"><dict>\n" >> "$manifest"
  33. #if [ -z ${2} ]; then
  34. # printf " <key>*</key><string>${2}</string>\n" >> "$manifest"
  35. #fi
  36. IFS=$'\n'
  37. OUTPUT="Packaging/"
  38. DIRECTORY=""
  39. DIRECTORY_DEEP=0
  40. DIRECTORY_DEEP_MAX=3
  41. if [ ! -d "${OUTPUT}" ]; then
  42. mkdir -p "${OUTPUT}"
  43. fi
  44. for var in $*; do
  45. for file in `find -d "$var"`; do
  46. # 随机创建目录
  47. if [[ $DIRECTORY_DEEP -lt $DIRECTORY_DEEP_MAX && $(($RANDOM%10)) -eq 0 ]]; then
  48. let DIRECTORY_DEEP=DIRECTORY_DEEP+1
  49. DIRECTORY="${DIRECTORY}$(RANDOM_NAME)/"
  50. mkdir -p "${OUTPUT}${DIRECTORY}"
  51. fi
  52. ext=""
  53. if [[ `basename $file` =~ "." ]]; then
  54. ext=".${file##*.}"
  55. fi
  56. code="${OUTPUT}${DIRECTORY}$(RANDOM_NAME)${ext}"
  57. # 随机返回
  58. if [[ $DIRECTORY_DEEP -gt 0 && $(($RANDOM%10)) -eq 0 ]]; then
  59. let DIRECTORY_DEEP=DIRECTORY_DEEP-1
  60. DIRECTORY="`dirname "${DIRECTORY}"`/"
  61. if [[ ${DIRECTORY} == "./" ]]; then
  62. DIRECTORY=""
  63. fi
  64. fi
  65. #code=`echo "$name/$file" | md5`
  66. #while [ -f $code ]; do
  67. # code=`echo $code | md5`
  68. #done
  69. echo mv "$file" "$code"
  70. mv "$file" "$code"
  71. if [ ! $? -eq 0 ]; then
  72. exit -1
  73. fi
  74. printf " <key>$file</key><dict><key>path</key><string>$code</string></dict>\n" >> "$manifest"
  75. done
  76. done
  77. printf "</dict></plist>" >> "$manifest"
  78. cd $cp