1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- if [[ $# -lt 2 ]]; then
- echo "usage: manifest executable path"
- exit -1
- fi
- # 生成比较正经一点的名字, 但需要字典支持
- if [ -f "dictionary.txt" ]; then
- WORDs=(`cat "dictionary.txt" | cut -d ' ' -f1`)
- fi
- function RANDOM_NAME() {
- if [ -n $WORDs ]; then
- local name=
- while [ ${#name} -lt 16 ]; do
- local index=$(($RANDOM%${#WORDs[@]}))
- name="${name}_${WORDs[${index}]}"
- done
- # 删除中划线并且将首字母大写
- echo ${name:1} #| awk -F[-] '{for(i=1;i<=NF;i++) printf toupper(substr($i,1,1)) substr($i,2); printf "\n";}'
- else
- # 生成uuid类型的名字
- echo `openssl rand -hex 8`
- fi
- };
- executable="${1}"
- rootp=`dirname "$executable"`
- manifest="${1}.plist"
- name=`basename "$executable"`
- echo $rootp
- cp=`pwd`
- cd "$rootp"
- shift 1
- printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" > "$manifest"
- printf "<plist version=\"1.0\"><dict>\n" >> "$manifest"
- #if [ -z ${2} ]; then
- # printf " <key>*</key><string>${2}</string>\n" >> "$manifest"
- #fi
- IFS=$'\n'
- OUTPUT="Packaging/"
- DIRECTORY=""
- DIRECTORY_DEEP=0
- DIRECTORY_DEEP_MAX=3
- if [ ! -d "${OUTPUT}" ]; then
- mkdir -p "${OUTPUT}"
- fi
- for var in $*; do
- for file in `find -d "$var"`; do
- # 随机创建目录
- if [[ $DIRECTORY_DEEP -lt $DIRECTORY_DEEP_MAX && $(($RANDOM%10)) -eq 0 ]]; then
- let DIRECTORY_DEEP=DIRECTORY_DEEP+1
- DIRECTORY="${DIRECTORY}$(RANDOM_NAME)/"
- mkdir -p "${OUTPUT}${DIRECTORY}"
- fi
- ext=""
- if [[ `basename $file` =~ "." ]]; then
- ext=".${file##*.}"
- fi
- code="${OUTPUT}${DIRECTORY}$(RANDOM_NAME)${ext}"
- # 随机返回
- if [[ $DIRECTORY_DEEP -gt 0 && $(($RANDOM%10)) -eq 0 ]]; then
- let DIRECTORY_DEEP=DIRECTORY_DEEP-1
- DIRECTORY="`dirname "${DIRECTORY}"`/"
- if [[ ${DIRECTORY} == "./" ]]; then
- DIRECTORY=""
- fi
- fi
- #code=`echo "$name/$file" | md5`
- #while [ -f $code ]; do
- # code=`echo $code | md5`
- #done
- echo mv "$file" "$code"
- mv "$file" "$code"
- if [ ! $? -eq 0 ]; then
- exit -1
- fi
- printf " <key>$file</key><dict><key>path</key><string>$code</string></dict>\n" >> "$manifest"
- done
- done
- printf "</dict></plist>" >> "$manifest"
- cd $cp
|