Homebrew
# 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/Homebrew/Homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
# 应用生效
brew update
brew install mysql
brew services start mysql
# 恢复默认
# 重置brew.git:
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
# 重置homebrew-core.git:
cd "$(brew --repo)/Library/Taps/Homebrew/Homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
# 重置homebrew-bottles(删除下面一行)
'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
# 安装xcode相关的⼀些插件,命令键⼊时界⾯上会弹出是否接受协议,需要⼿动从图形界⾯上同意协议
xcode-select --install
# 验证xcode-select安装是否成功
xcode-select --version
# 管理服务,后台运行的服务主机重启后会自动启动
brew install jenkins-lts
brew services start|stop|restart jenkins-lts
RVM安装
# 下载源码
curl -L https://get.rvm.io | bash -s stable
## 如果无法连接raw.githubusercontent.com ,需要配置hosts
199.232.68.133 raw.githubusercontent.com
# 编译安装
source ~/.rvm/scripts/rvm
# 检测是否安装成功
rvm -v
# 更新⼀下国内源,提升下载rvm管理软件的速度
gem sources --remove https://rubygems.org/
# 如果有的公司屏蔽了taobao域名,可以找别的快点的源替换
gem sources -a https://gems.ruby-china.com/
gem sources -l
#如果发现http://gems.alibaba-inc.com/,也移除掉,此地址不通
Ruby安装
# 安装ruby
rvm install 2.6.3
rvm list
# 如果没有设置默认版本,则设置默认版本
rvm use 2.6.3 --default
# 安装⼀些基础插件
# 如果有设置代理,请⽤如下格式:
# gem install --http-proxy {proxyUrl} cocoapods -v xxx
gem install fastlane
gem install cocoapods -v xxx
gem install cocoapods-deintegrate
# 下⾯三个⾮必须的,安装失败也不要紧
gem install cocoapods-timeconsuming
gem install cocoapods-multithread-installpod
gem install cocoapods-podtarget-optimize
# 查看是否安装完成
gem list
# 确定xcpretty插件可以正常使⽤
# 如果提示错误,不是使⽤的ruby的插件⽽是系统的xcpretty插件,可以直接rm掉系统的插件
xcpretty -v
Cocoapods安装
# 安装基础依赖
sudo gem update --system 2.7.6
# 配置pod环境变量 (注:在公司⽹络下10分钟)
pod setup
#### 注:以下步骤不⽤执⾏ (如果pod setup执⾏成功)====>
# 初始化pod环境
# 注意:这⼀步⾮常慢,可能需要花费两个⼩时。
# 【⽅法1】 # 这是最快也是最直接的⽅法:直接从线上poc的ios打包机⾥拷⻉/Users/<loginname>/.cocoapods/repos/master.zip
# 【⽅法2】 # 注意:这⾥从github上下载的时候,不能直接下载zip包,还是需要使⽤git协议来clone,因为pod 会有更新,需要知道github的仓库源。
# chown -R $(whoami):staff .cocoapods/
# 【⽅法3】 # pod setup默认使⽤https协议来下载,速度很慢,推荐⼿动使⽤git协议来下载。
# mkdir -p ~/.cocoapods/repos/master
# cd ~/.cocoapods/repos/master && git clone git@github.com:CocoaPods/Specs.git
####<====
# 验证是否成功安装
pod --version
# 可选,如果业务需要配置其他的镜像,则通过pod命令添加
# pod repo add XXX git@xxxxxxxxx/specs-mirror.git
Git环境初始化
# 创建⽤户.ssh⽬录
mkdir -p ~/.ssh && cd ~/.ssh/
# 从打包机拷⻉ssh-key(id_rsa和id_rsa.pub⽂件) 或新生成
# 修改ssh_config权限
sudo chmod a+w /etc/ssh/ssh_config
# 保存以后git访问是不弹出权限问题
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config && echo "UserKnownHostsFile=/dev/null" >> /etc/ssh/ssh_config
Supervisor
sudo easy_install pip
sudo pip install supervisor
oclint
brew install oclint
brew install swiftlint
# 使⽤oclint时会遇到⽆法验证oclint开发者(oclint.org)的问题,需要如下配置
## 在 系统设置->安全性与隐私->通⽤ 中打开允许所有来源选项
sudo spctl --master-disable
## 将oclint的包的安全隔离性属性删除掉,这样就不对其进⾏检查了
sudo xattr -r -d com.apple.quarantine /usr/local/Caskroom/oclint
security
# Mac系统中钥匙串相关操作工具,GUI为 keychain
## 存放安全实体的仓库,默认路径为
~/Library/Keychains/
/Library/Keychains/
/Network/Library/Keychains/
/var/Keychains/keychain-2.db
security [-hilqv] [-p prompt] [command] [command options] [command args]
-l security推出前,调用/usr/bin/leaks -nocontext检查执行的命令是否有泄漏
command
list-keychains
dump-keychain
lock-keychain
find-certificate
delete-certificate
find-identity 认证实体(证书+私钥)
cms 编码或解码CMS信息 PKCS#7
create-keychain
例如:
security cms -D -i "$plugin_provision" -o "${plugin_plist}"
# 查看可用ID,用后面的名称签名
security find-identity -v -p codesigning
1) B2CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXFE "iPhone Distribution: XXXXXXXXXXXXX., Ltd."
2) B2CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXFE "iPhone Distribution: XXXXXXXXXXXXX., Ltd."
2 valid identities found
codesign
# 查找Plist文件
IOS_PLIST_FILE=`ruby ~/test/pbxproj.rb get_plist Name.xcodeproj TargetName Debug product`
if [ -f "$IOS_PLIST_FILE" ]; then
echo "find $IOS_PLIST_FILE"
else
IOS_PLIST_FILE=`find ./ -name $buildXcodeSchema-Info.plist`
fi
# 查看BundleID
IOS_ORIGINAL_BUNDLE_ID=`/usr/libexec/PlistBuddy "$IOS_PLIST_FILE" -c "Print CFBundleIdentifier"`
if [ "$IOS_ORIGINAL_BUNDLE_ID"x == '$(PRODUCT_BUNDLE_IDENTIFIER)'x ]; then # 这里的x是防止[]中的变量未定义等导致的语法错误
IOS_ORIGINAL_BUNDLE_ID=`ruby ~/test/pbxproj.rb get_product_bundle_identifier Name.xcodeproj TargetName Debug product`
fi
echo "original bundle identifier is $IOS_ORIGINAL_BUNDLE_ID"
# 设置version
# /usr/libexec/PlistBuddy "$IOS_PLIST_FILE" -c "Set CFBundleVersion $IOS_NEW_BUNDLE_VERSION"
# /usr/libexec/PlistBuddy "$IOS_PLIST_FILE" -c "Set CFBundleShortVersionString $IOS_NEW_SHORT_BUNDLE_VERSION"
# 如果有extension bundle identifier,也要设置extension的两个version
# 查看keychain
set +x
security list-keychains -s $KeychainPath
security unlock-keychain -p $KeychainPassword $KeychainPath
security set-key-partition-list -S apple-tool:,apple: -k $KeychainPassword $KeychainPath
security set-keychain-settings $KeychainPath
set -x
# 设置项目证书
set +e
ruby ~/test/xcodebuild_init.rb Name.xcodeproj $developmentTeamID Debug "$certificateFullName"
set -e
#拷贝dSYM文件
copyAllFrameworkDsyms(){
sourceDirectory=$1
destinationDirectory=$2
for dsym in `ls -l ${sourceDirectory}|grep "^d"|grep ".framework.dSYM$"`
do
`ditto -c -k --keepParent -rsrc ${sourceDirectory}/${dysm} ${destinationDirectory}/${dsym-dYSM.zip}`
done
}
# 打包 archive|build
buildSdkPara=""
if [ "iphonesimulator" ]; then
buildSdkPara="-destination id=187369F4-FE1A-477E-A613-4AFEB301DC24 -sdk iphonesimulator"
fi
set -o pipefail
xcodebuild -scheme TargetName ${workspaceOrProjectFile} ${buildSdkPara} -configuration Debug -UseModernBuildSystem=NO clean archive -archivePath ${output_dir} "CODE_SIGN_IDENTITY=${certificateFullName}" -jobs 4 | tee -a
set -o pipefail
xcodebuild -scheme TargetName ${workspaceOrProjectFile} ${buildSdkPara} -configuration Debug -UseModernBuildSystem=NO clean build "CODE_SIGN_IDENTITY=${certificateFullName}" -jobs 4 | tee -a
# 导出
xcodebuild -exportArchive -exportOptionsPlist "${code_dir}/export_info.plist" -archivePath "${buildDirectory}" -exportPath "${buildDirectory}"
# 签名
man codesign
codesign -s identity [-i identifier] [-r requirements] [-fv] [path ...]
codesign -s 'iPhone Developer: Xx Xx (XXXXXXXX)' Example.app
codesign -s 40位16进制数字即证书的SHA1指纹 Example.app
例如:
/usr/libexec/PlistBuddy -x -c 'Print:Entitlements' "${plugin_plist}" > "${plugin_entitlement}"
/usr/libexec/PlistBuddy -c 'Print:Entitlements:application-identifier' "${plugin_plist}"
/usr/libexec/PlistBuddy -c "Set:CFBundleIdentifier ${bundle_id}" "Info.plist"
codesign --continue -fs $signed_info --entitlements="$plugin_entitlement" "${app_path}"
codesign -v "$PayloadPath/X.app"
# 验证签名
codesign --verify -vvvv ${archivePath}/${appName}
# 查错
regex=`awk -v buildStep="${buildPhaseStep}" -f /tmp/regex_processor.awk /tmp/regex_collection.txt`
grep -E "$regex" -C10 ${logFile} | sed 's/^-------$/== error ==/g' > ${abstractFile}
# 读取描述文件
uuid=`~/test/mobileprovision-read -f "$profile" -o UUID`
appid=`~/test/mobileprovision-read -f "$profile" -o appid`