Skip to content

Commit

Permalink
change scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchengfang committed Feb 18, 2013
1 parent 19e67f0 commit f9921c3
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 43 deletions.
75 changes: 47 additions & 28 deletions ipa-build
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,81 @@

#--------------------------------------------
# 功能:为xcode工程打ipa包
# 使用说明:第一个参数为xcode工程根路径,第二个参数是编译配置(可选,默认为Release)
# 作者:ccf
# E-mail:[email protected]
# 创建日期:2012/09/24
#--------------------------------------------
# 修改日期:2013/02/18
# 修改人:ccf
# 修改内容:打包方式改为使用xcrun命令,并修改第二个参数
#--------------------------------------------



#参数判断
if [ $# != 2 ] && [ $# != 1 ];then
echo "Number of params error! Need one or two params!"
echo "1.path of project(necessary) 2.name of ipa file(optional)"
echo "1.path of project(necessary) 2.Build Configurations one of Debug, AdHoc,Release, Distribution (Release is default)"
exit
elif [ ! -d $1 ];then
echo "Params Error!! The first param must be a dictionary."
exit
fi

build_config=Release

if [ $# = 2 ];then
build_config=$2
if [ $build_config != Debug ] && [ $build_config != AdHoc ] && [ $build_config != Release ] && [ $build_config != Distribution ];then
echo "Error! The Second Param must be one of Debug, AdHoc,Release or Distribution"
exit
fi
fi


#工程绝对路径
cd $1
project_path=$(pwd)
#build文件夹路径
build_path=${project_path}/build

#工程配置文件路径
project_name=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}')
project_infoplist_path=${project_path}/${project_name}/${project_name}-Info.plist
#取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" ${project_infoplist_path})
#取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${project_infoplist_path})
#取bundle Identifier前缀
#bundlePrefix=$(/usr/libexec/PlistBuddy -c "print CFBundleIdentifier" `find . -name "*-Info.plist"` | awk -F$ '{print $1}')


#IPA名称
if [ $# = 2 ];then
ipa_name=$2
fi


#编译工程
cd $project_path
xcodebuild || exit
xcodebuild -configuration ${build_config} || exit

#打包
#进入build路径
cd $build_path
target_name=$(basename ./Release-iphoneos/*.app | awk -F. '{print $1}')
if [ $# = 1 ];then
ipa_name="${target_name}_${bundleShortVersion}_build${bundleVersion}_$(date +"%Y%m%d")"
fi

#创建ipa-build文件夹
if [ -d ./ipa-build ];then
rm -rf ipa-build
fi
mkdir -p ipa-build/Payload
cp -r ./Release-iphoneos/*.app ./ipa-build/Payload/
cd ipa-build
zip -r ${ipa_name}.ipa *
rm -rf Payload
mkdir ipa-build


#生成的app文件目录
appdirname=Release-iphoneos
if [ $build_config = Debug ];then
appdirname=Debug-iphoneos
fi

#app文件名称
appname=$(basename ./${appdirname}/*.app)
#通过app文件名获得工程target名字
target_name=$(echo $appname | awk -F. '{print $1}')
#app文件中Info.plist文件路径
app_infoplist_path=${build_path}/${appdirname}/${appname}/Info.plist
#取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" ${app_infoplist_path})
#取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${app_infoplist_path})

#IPA名称
ipa_name="${target_name}_${bundleShortVersion}_${build_config}${bundleVersion}_$(date +"%Y%m%d")"
echo $ipa_name

#xcrun打包
xcrun -sdk iphoneos PackageApplication -v ./${appdirname}/*.app -o ${build_path}/ipa-build/${ipa_name}.ipa

60 changes: 45 additions & 15 deletions ipa-publish
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
# 修改人:ccf
# 修改内容:去掉打包的部分脚本,只保留生成协议文件部分,以后此脚本依赖ipa-build脚本
#--------------------------------------------
# 修改日期:2013/02/18
# 修改人:ccf
# 修改内容:添加通过sftp上传到服务器的功能
#--------------------------------------------



#须配置内容 start

#发布应用的url地址
pulish_url="http://webfrogs.github.com/urls/"
pulish_url="http://192.168.81.236/test"

#可配置内容 end

Expand Down Expand Up @@ -60,27 +65,49 @@ fi
#build文件夹路径
build_path=${project_path}/build

#工程配置文件路径
project_name=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}')
project_infoplist_path=${project_path}/${project_name}/${project_name}-Info.plist
#切换到tmp文件夹
cd /tmp
#创建临时文件夹
tmpfoldername=ipa_tmp
if [ -d ./${tmpfoldername} ];then
rm -rf ${tmpfoldername}
fi
mkdir ${tmpfoldername}

cd ${tmpfoldername}
#拷贝ipa到临时文件夹中
cp ${build_path}/ipa-build/*.ipa ./tmp.zip
#将ipa解压
unzip tmp.zip
#app文件中Info.plist文件路径
app_infoplist_path=$(pwd)/Payload/*.app/Info.plist
#取版本号
#bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" ${app_infoplist_path})
#取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${project_infoplist_path})
#取bundle Identifier前缀
bundlePrefix=$(/usr/libexec/PlistBuddy -c "print CFBundleIdentifier" `find . -name "*-Info.plist"` | awk -F$ '{print $1}')

#生成发布文件

#拷贝ipa
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${app_infoplist_path})
#取bundleIdentifier
bundleIdentifier=$(/usr/libexec/PlistBuddy -c "print CFBundleIdentifier" ${app_infoplist_path})
#取CFBundleName
target_name=$(/usr/libexec/PlistBuddy -c "print CFBundleName" ${app_infoplist_path})
#取CFBundleDisplayName
display_name=$(/usr/libexec/PlistBuddy -c "print CFBundleDisplayName" ${app_infoplist_path})

#删除临时文件夹
cd ..
rm -rf ${tmpfoldername}

#进入到工程build路径下
cd $build_path
target_name=$(basename ./Release-iphoneos/*.app | awk -F. '{print $1}')

if [ $# = 1 ];then
ipa_name="${target_name}"
ipa_name="${display_name}"
fi

if [ -d ./$target_name ];then
rm -rf $target_name
fi
mkdir $target_name
#拷贝ipa
cp ./ipa-build/*.ipa ./$target_name/${target_name}.ipa
cp ../[email protected] ./$target_name/${target_name}_logo.png
cd $target_name
Expand All @@ -99,7 +126,7 @@ cat << EOF > index.html
<br>
<p align=center>
<font size="8">
<a href="itms-services://?action=download-manifest&url=${pulish_url}${target_name}.plist">点击这里安装</a>
<a href="itms-services://?action=download-manifest&url=${pulish_url}/${target_name}/${target_name}.plist">点击这里安装</a>
</font>
</p>
Expand Down Expand Up @@ -143,7 +170,7 @@ cat << EOF > ${target_name}.plist
</array><key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>${bundlePrefix}${target_name}</string>
<string>${bundleIdentifier}</string>
<key>bundle-version</key>
<string>${bundleVersion}</string>
<key>kind</key>
Expand All @@ -159,3 +186,6 @@ cat << EOF > ${target_name}.plist
</plist>
EOF

#调用upload脚本来将文件上传到服务器
~/shell/upload $target_name
56 changes: 56 additions & 0 deletions upload
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/expect -f

#--------------------------------------------
# 功能:先在服务器指定路径下新建文件夹,并将脚本所在路径下所有文件通过sftp协议上传到该文件夹中。
# 使用说明:命令后带一个参数,表示在服务器中新建文件夹的名字。注意:目前该脚本无参数验证功能,必须有该参数,否则脚本运行结果会发生错误
# 作者:ccf
# E-mail:[email protected]
# 创建日期:2013/02/17
#--------------------------------------------


#参数设置
set filefolder [lindex $argv 0]
set host 192.168.*.*
set username root
set password ***
set hostfilepath /usr/


#sftp连接
spawn sftp $username@$host

#第一次sftp时需输入yes
expect {
"(yes/no)?" {send "yes\r"; exp_continue}
"password:" {send "$password\r"}
}

#切换到所要放置的目录下
expect "sftp>"
send "cd $hostfilepath\r"

#判断文件夹是否已经存在,若不存在,则新建。之后进入到文件夹中
expect "sftp>"
send "ls $filefolder\r"
expect {
"No such file or directory" {send "mkdir $filefolder\r"; exp_continue}
"sftp>" {send "cd $filefolder\r"}
}

#删除文件夹中所有文件
expect "sftp>"
send "rm *\r"

#将当前路径下所有文件上传
expect "sftp>"
send "put ./*\r"

#退出sftp
expect "sftp>"
send "bye\r"

interact



0 comments on commit f9921c3

Please sign in to comment.