Skip to content

Instantly share code, notes, and snippets.

@Neeeo Neeeo/release.sh
Last active Jun 14, 2017

Embed
What would you like to do?
APP 多发打包脚本 Demo 参考,好些地方需要改成对应工程内容
#!/bin/bash
#error message sent to builderror
builderror="Build/error_log"
exec 2>$builderror
if [[ $# -lt 1 ]]; then
exit -1
fi
if [[ $1 = '-f' ]]; then
conf=$2
app_version_string=$3
app_version=$3
if [[ $# -eq 4 ]]; then
app_version=$4
fi
else
app_version_string=$1
app_version=$1
if [[ $# -eq 2 ]]; then
app_version=$2
fi
fi
if [[ -z $app_version_string || $app_version_string =~ \d+(\.\d+)* ]]; then
echo -e "\033[0;31mapp short version is wrong:$app_version_string\033[0m"
exit -1
fi
if [[ -z !$app_version || $app_version =~ \d+(\.\d+)* ]]; then
echo -e "\033[0;31mapp version is wrong:${app_version}\033[0m"
exit -1
fi
if [[ $conf ]]; then
list=($conf)
else
list=`ls *.conf`
fi
build(){
echo ">>>>>>>>>>>>>>>>>>>>>>>>>"
if [[ !(-s $1) ]]; then
echo "file dont exist:$1" 1>&2
return
fi
echo "clean variables"
app_id=''
app_name=''
app_bundle_id=''
app_product_name=''
app_scheme=''
app_icon_path=''
qq_id=''
weibo_key=''
weibo_secret=''
umeng_key=''
ga_key=''
apple_id=''
provisioning_profile_uuid=''
. ./$1
info_file='${YOUR_PROJECT_FOLDER}/Info.plist'
constant_file='${YOUR_PROJECT_FOLDER}/MBConstants_mb.m'
project_file='${YOUR_PROJECT}.xcodeproj/project.pbxproj'
appDelegate_file='${YOUR_PROJECT_FOLDER}/AppDelegate.m'
google_file='${YOUR_PROJECT_FOLDER}/GoogleService-Info.plist'
echo "using conf:$1"
echo "backup files:"
echo "> ${info_file}.bp"
echo "> ${constant_file}.bp"
echo "> ${project_file}.bp"
echo "> ${appDelegate_file}.bp"
cp $info_file ${info_file}.bp
cp $constant_file ${constant_file}.bp
cp $project_file ${project_file}.bp
cp $appDelegate_file ${appDelegate_file}.bp
if [[ $app_icon_path ]]; then
echo "copy icons from:${app_icon_path}"
cp -R ${app_icon_path} ${YOUR_PROJECT_FOLDER}/Assets.xcassets/AppIcon.appiconset
fi
echo "sync match"
match --git_branch ${apple_id} -y appstore -a ${app_bundle_id} -u ${apple_id} -r ${YOUR_CERTIFICATES_REPO}
echo ">> start building"
echo ">> editing file:${appDelegate_file}"
if [[ $umeng_key ]]; then
echo "changing umeng key to:${umeng_key}"
sed -i '' "s/${YOUR_UMENG_KEY}/${umeng_key}/" $appDelegate_file
fi
if [[ $ga_key ]]; then
echo "changing ga key to: ${ga_key}"
sed -i '' "s/${YOUR_GA_KEY}/${ga_key}/" $appDelegate_file
echo ">> editing file:${google_file}"
sed -i '' "s/${YOUR_GA_KEY}/${ga_key}/" $google_file
fi
sed -i '' "s/${YOUR_BUNDLE_ID}/${app_bundle_id}/" $google_file
echo ">> editing file:${info_file}"
echo "changing app id to:${app_id}"
/usr/libexec/PlistBuddy -c "Set :AppStoreID ${app_id}" $info_file
echo "set app version string:${app_version_string}"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${app_version_string}" $info_file
echo "set app version:${app_version}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${app_version}" $info_file
echo "changing app name to:$app_name"
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName ${app_name}" $info_file
if [[ $app_scheme ]]; then
echo "chaning app scheme to:${app_scheme}"
/usr/libexec/PlistBuddy -c "Set :CFBundleURLTypes:0:CFBundleURLSchemes:1 ${app_scheme}" $info_file
fi
if [[ $weibo_key ]]; then
echo "changing weibo scheme to:wb${weibo_key}"
/usr/libexec/PlistBuddy -c "Set :CFBundleURLTypes:2:CFBundleURLSchemes:0 wb${weibo_key}" $info_file
fi
if [[ $qq_id ]]; then
echo "changing qq scheme to:tencent${qq_id}"
/usr/libexec/PlistBuddy -c "Set :CFBundleURLTypes:3:CFBundleURLSchemes:0 tencent${qq_id}" $info_file
fi
if [[ $app_scheme ]]; then
echo "changing alipay scheme to:${app_scheme}"
sed -i '' "s/${YOUR_APP_SCHEME}/${app_scheme}/" $constant_file
fi
if [[ $qq_id ]]; then
echo "changing qq id to:${qq_id}"
sed -i '' "s/${YOUR_QQ_ID}/${qq_id}/" $constant_file
fi
if [[ $weibo_key ]]; then
echo "changing weibo key to:${weibo_key}"
sed -i '' "s/${YOUR_WEIBO_KEY}/${weibo_key}/" $constant_file
fi
if [[ $weibo_secret ]]; then
echo "changing weibo secret to:${weibo_secret}"
sed -i '' "s/${YOUR_WEIWEB_SECRET}/${weibo_secret}/" $constant_file
fi
echo "changing app name to:${app_name}"
sed -i '' "s/${YOUR_APP_NAME}/${app_name}/" $constant_file
echo "> editing project file"
echo "changing target name to: ${app_product_name}"
sed -i '' "s/PRODUCT_NAME = .*\";$/PRODUCT_NAME = ${app_product_name};/" $project_file
echo "changing bundle id to: ${app_bundle_id}"
sed -i '' "s/PRODUCT_BUNDLE_IDENTIFIER = .*;/PRODUCT_BUNDLE_IDENTIFIER = ${app_bundle_id};/" $project_file
echo "changing CODE_SIGN_IDENTITY to: auto"
sed -i '' "s/CODE_SIGN_IDENTITY = .*\"/CODE_SIGN_IDENTITY = \"iPhone Distribution\"/" $project_file
sed -i '' "s/CODE_SIGN_IDENTITY\[sdk=iphoneos\*\].*;/CODE_SIGN_IDENTITY[sdk=iphoneos*]\" = \"iPhone Distribution\";/" $project_file
echo "changing provisioning profile to:${provisioning_profile_uuid}"
sed -i '' "s/PROVISIONING_PROFILE = .*\"/PROVISIONING_PROFILE = \"${provisioning_profile_uuid}\"/" $project_file
ipa_path='Build/'
ipa_name=${app_product_name}_${app_version_string}
echo ">> run gym"
gym --scheme "${YOUR_TARGET_SCHEME}" --clean true --configuration "Release" --output_directory ${ipa_path} --use_legacy_build_api true --output_name $ipa_name --include_symbols true
echo ">> done build $1"
echo ">> create Deliverfile"
echo "submission_information({
add_id_info_uses_idfa:true,
add_id_info_serves_ads:true,
add_id_info_limits_tracking:true,
export_compliance_uses_encryption:false,
export_compliance_encryption_updated:false})" > Deliverfile
echo ">> deliver ipa"
deliver -u ${apple_id} -a ${app_bundle_id} -i ${ipa_path}${ipa_name}.ipa -z ${app_version_string} --submit_for_review -f
echo ">> restore files"
echo ">> build finish app:${app_name}"
cp ${info_file}.bp $info_file
cp ${constant_file}.bp $constant_file
cp ${project_file}.bp $project_file
cp ${appDelegate_file}.bp $appDelegate_file
rm ${info_file}.bp
rm ${constant_file}.bp
rm ${project_file}.bp
rm ${appDelegate_file}.bp
rm Deliverfile
git checkout ${YOUR_PROJECT_FOLDER}/Assets.xcassets/AppIcon.appiconset/*
git checkout $google_file
}
echo ">> app version string:$app_version_string"
echo ">> app version:$app_version"
for i in $list; do
build $i
done
#print error message
err=$(<${builderror})
if [[ $err ]]; then
echo -e "\033[0;31m\c"
echo "Build Error Message:"
echo "----------------------------"
printf "$err\n"
echo "----------------------------"
echo -e "\033[0m\c"
fi
rm $builderror
echo -e ">>:\033[0;32;1mAll Build Done\033[0m"
echo "conf list:${list}"
app_id=''
app_name=''
app_bundle_id=''
app_product_name=''
app_scheme=''
app_icon_path=''
qq_id=''
weibo_key=''
weibo_secret=''
umeng_key=''
ga_key=''
apple_id=''
provisioning_profile_uuid=''
@RainFlying

This comment has been minimized.

Copy link

RainFlying commented Mar 18, 2017

\d is not part of ERE regular expression. Bash '=~' uses ERE regular expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.