Homebrew

  1. # 替换brew.git:
  2. cd "$(brew --repo)"
  3. git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
  4. # 替换homebrew-core.git:
  5. cd "$(brew --repo)/Library/Taps/Homebrew/Homebrew-core"
  6. git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
  7. # 替换homebrew-bottles:
  8. echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
  9. source ~/.zshrc
  10. # 应用生效
  11. brew update
  12. brew install mysql
  13. brew services start mysql
  14. # 恢复默认
  15. # 重置brew.git:
  16. cd "$(brew --repo)"
  17. git remote set-url origin https://github.com/Homebrew/brew.git
  18. # 重置homebrew-core.git:
  19. cd "$(brew --repo)/Library/Taps/Homebrew/Homebrew-core"
  20. git remote set-url origin https://github.com/Homebrew/homebrew-core.git
  21. # 重置homebrew-bottles(删除下面一行)
  22. 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
  23. source ~/.zshrc
  24. # 安装xcode相关的⼀些插件,命令键⼊时界⾯上会弹出是否接受协议,需要⼿动从图形界⾯上同意协议
  25. xcode-select --install
  26. # 验证xcode-select安装是否成功
  27. xcode-select --version
  28. # 管理服务,后台运行的服务主机重启后会自动启动
  29. brew install jenkins-lts
  30. brew services start|stop|restart jenkins-lts

RVM安装

  1. # 下载源码
  2. curl -L https://get.rvm.io | bash -s stable
  3. ## 如果无法连接raw.githubusercontent.com ,需要配置hosts
  4. 199.232.68.133 raw.githubusercontent.com
  5. # 编译安装
  6. source ~/.rvm/scripts/rvm
  7. # 检测是否安装成功
  8. rvm -v
  9. # 更新⼀下国内源,提升下载rvm管理软件的速度
  10. gem sources --remove https://rubygems.org/
  11. # 如果有的公司屏蔽了taobao域名,可以找别的快点的源替换
  12. gem sources -a https://gems.ruby-china.com/
  13. gem sources -l
  14. #如果发现http://gems.alibaba-inc.com/,也移除掉,此地址不通

Ruby安装

  1. # 安装ruby
  2. rvm install 2.6.3
  3. rvm list
  4. # 如果没有设置默认版本,则设置默认版本
  5. rvm use 2.6.3 --default
  6. # 安装⼀些基础插件
  7. # 如果有设置代理,请⽤如下格式:
  8. # gem install --http-proxy {proxyUrl} cocoapods -v xxx
  9. gem install fastlane
  10. gem install cocoapods -v xxx
  11. gem install cocoapods-deintegrate
  12. # 下⾯三个⾮必须的,安装失败也不要紧
  13. gem install cocoapods-timeconsuming
  14. gem install cocoapods-multithread-installpod
  15. gem install cocoapods-podtarget-optimize
  16. # 查看是否安装完成
  17. gem list
  18. # 确定xcpretty插件可以正常使⽤
  19. # 如果提示错误,不是使⽤的ruby的插件⽽是系统的xcpretty插件,可以直接rm掉系统的插件
  20. xcpretty -v

Cocoapods安装

  1. # 安装基础依赖
  2. sudo gem update --system 2.7.6
  3. # 配置pod环境变量 (注:在公司⽹络下10分钟)
  4. pod setup
  5. #### 注:以下步骤不⽤执⾏ (如果pod setup执⾏成功)====>
  6. # 初始化pod环境
  7. # 注意:这⼀步⾮常慢,可能需要花费两个⼩时。
  8. # 【⽅法1】 # 这是最快也是最直接的⽅法:直接从线上poc的ios打包机⾥拷⻉/Users/<loginname>/.cocoapods/repos/master.zip
  9. # 【⽅法2】 # 注意:这⾥从github上下载的时候,不能直接下载zip包,还是需要使⽤git协议来clone,因为pod 会有更新,需要知道github的仓库源。
  10. # chown -R $(whoami):staff .cocoapods/
  11. # 【⽅法3】 # pod setup默认使⽤https协议来下载,速度很慢,推荐⼿动使⽤git协议来下载。
  12. # mkdir -p ~/.cocoapods/repos/master
  13. # cd ~/.cocoapods/repos/master && git clone git@github.com:CocoaPods/Specs.git
  14. ####<====
  15. # 验证是否成功安装
  16. pod --version
  17. # 可选,如果业务需要配置其他的镜像,则通过pod命令添加
  18. # pod repo add XXX git@xxxxxxxxx/specs-mirror.git

Git环境初始化

  1. # 创建⽤户.ssh⽬录
  2. mkdir -p ~/.ssh && cd ~/.ssh/
  3. # 从打包机拷⻉ssh-key(id_rsa和id_rsa.pub⽂件) 或新生成
  4. # 修改ssh_config权限
  5. sudo chmod a+w /etc/ssh/ssh_config
  6. # 保存以后git访问是不弹出权限问题
  7. echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config && echo "UserKnownHostsFile=/dev/null" >> /etc/ssh/ssh_config

Supervisor

  1. sudo easy_install pip
  2. sudo pip install supervisor

oclint

  1. brew install oclint
  2. brew install swiftlint
  3. # 使⽤oclint时会遇到⽆法验证oclint开发者(oclint.org)的问题,需要如下配置
  4. ## 在 系统设置->安全性与隐私->通⽤ 中打开允许所有来源选项
  5. sudo spctl --master-disable
  6. ## 将oclint的包的安全隔离性属性删除掉,这样就不对其进⾏检查了
  7. sudo xattr -r -d com.apple.quarantine /usr/local/Caskroom/oclint

security

  1. # Mac系统中钥匙串相关操作工具,GUI为 keychain
  2. ## 存放安全实体的仓库,默认路径为
  3. ~/Library/Keychains/
  4. /Library/Keychains/
  5. /Network/Library/Keychains/
  6. /var/Keychains/keychain-2.db
  7. security [-hilqv] [-p prompt] [command] [command options] [command args]
  8. -l security推出前,调用/usr/bin/leaks -nocontext检查执行的命令是否有泄漏
  9. command
  10. list-keychains
  11. dump-keychain
  12. lock-keychain
  13. find-certificate
  14. delete-certificate
  15. find-identity 认证实体(证书+私钥)
  16. cms 编码或解码CMS信息 PKCS#7
  17. create-keychain
  18. 例如:
  19. security cms -D -i "$plugin_provision" -o "${plugin_plist}"
  20. # 查看可用ID,用后面的名称签名
  21. security find-identity -v -p codesigning
  22. 1) B2CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXFE "iPhone Distribution: XXXXXXXXXXXXX., Ltd."
  23. 2) B2CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXFE "iPhone Distribution: XXXXXXXXXXXXX., Ltd."
  24. 2 valid identities found

codesign

  1. # 查找Plist文件
  2. IOS_PLIST_FILE=`ruby ~/test/pbxproj.rb get_plist Name.xcodeproj TargetName Debug product`
  3. if [ -f "$IOS_PLIST_FILE" ]; then
  4. echo "find $IOS_PLIST_FILE"
  5. else
  6. IOS_PLIST_FILE=`find ./ -name $buildXcodeSchema-Info.plist`
  7. fi
  8. # 查看BundleID
  9. IOS_ORIGINAL_BUNDLE_ID=`/usr/libexec/PlistBuddy "$IOS_PLIST_FILE" -c "Print CFBundleIdentifier"`
  10. if [ "$IOS_ORIGINAL_BUNDLE_ID"x == '$(PRODUCT_BUNDLE_IDENTIFIER)'x ]; then # 这里的x是防止[]中的变量未定义等导致的语法错误
  11. IOS_ORIGINAL_BUNDLE_ID=`ruby ~/test/pbxproj.rb get_product_bundle_identifier Name.xcodeproj TargetName Debug product`
  12. fi
  13. echo "original bundle identifier is $IOS_ORIGINAL_BUNDLE_ID"
  14. # 设置version
  15. # /usr/libexec/PlistBuddy "$IOS_PLIST_FILE" -c "Set CFBundleVersion $IOS_NEW_BUNDLE_VERSION"
  16. # /usr/libexec/PlistBuddy "$IOS_PLIST_FILE" -c "Set CFBundleShortVersionString $IOS_NEW_SHORT_BUNDLE_VERSION"
  17. # 如果有extension bundle identifier,也要设置extension的两个version
  18. # 查看keychain
  19. set +x
  20. security list-keychains -s $KeychainPath
  21. security unlock-keychain -p $KeychainPassword $KeychainPath
  22. security set-key-partition-list -S apple-tool:,apple: -k $KeychainPassword $KeychainPath
  23. security set-keychain-settings $KeychainPath
  24. set -x
  25. # 设置项目证书
  26. set +e
  27. ruby ~/test/xcodebuild_init.rb Name.xcodeproj $developmentTeamID Debug "$certificateFullName"
  28. set -e
  29. #拷贝dSYM文件
  30. copyAllFrameworkDsyms(){
  31. sourceDirectory=$1
  32. destinationDirectory=$2
  33. for dsym in `ls -l ${sourceDirectory}|grep "^d"|grep ".framework.dSYM$"`
  34. do
  35. `ditto -c -k --keepParent -rsrc ${sourceDirectory}/${dysm} ${destinationDirectory}/${dsym-dYSM.zip}`
  36. done
  37. }
  38. # 打包 archive|build
  39. buildSdkPara=""
  40. if [ "iphonesimulator" ]; then
  41. buildSdkPara="-destination id=187369F4-FE1A-477E-A613-4AFEB301DC24 -sdk iphonesimulator"
  42. fi
  43. set -o pipefail
  44. xcodebuild -scheme TargetName ${workspaceOrProjectFile} ${buildSdkPara} -configuration Debug -UseModernBuildSystem=NO clean archive -archivePath ${output_dir} "CODE_SIGN_IDENTITY=${certificateFullName}" -jobs 4 | tee -a
  45. set -o pipefail
  46. xcodebuild -scheme TargetName ${workspaceOrProjectFile} ${buildSdkPara} -configuration Debug -UseModernBuildSystem=NO clean build "CODE_SIGN_IDENTITY=${certificateFullName}" -jobs 4 | tee -a
  47. # 导出
  48. xcodebuild -exportArchive -exportOptionsPlist "${code_dir}/export_info.plist" -archivePath "${buildDirectory}" -exportPath "${buildDirectory}"
  49. # 签名
  50. man codesign
  51. codesign -s identity [-i identifier] [-r requirements] [-fv] [path ...]
  52. codesign -s 'iPhone Developer: Xx Xx (XXXXXXXX)' Example.app
  53. codesign -s 4016进制数字即证书的SHA1指纹 Example.app
  54. 例如:
  55. /usr/libexec/PlistBuddy -x -c 'Print:Entitlements' "${plugin_plist}" > "${plugin_entitlement}"
  56. /usr/libexec/PlistBuddy -c 'Print:Entitlements:application-identifier' "${plugin_plist}"
  57. /usr/libexec/PlistBuddy -c "Set:CFBundleIdentifier ${bundle_id}" "Info.plist"
  58. codesign --continue -fs $signed_info --entitlements="$plugin_entitlement" "${app_path}"
  59. codesign -v "$PayloadPath/X.app"
  60. # 验证签名
  61. codesign --verify -vvvv ${archivePath}/${appName}
  62. # 查错
  63. regex=`awk -v buildStep="${buildPhaseStep}" -f /tmp/regex_processor.awk /tmp/regex_collection.txt`
  64. grep -E "$regex" -C10 ${logFile} | sed 's/^-------$/== error ==/g' > ${abstractFile}
  65. # 读取描述文件
  66. uuid=`~/test/mobileprovision-read -f "$profile" -o UUID`
  67. appid=`~/test/mobileprovision-read -f "$profile" -o appid`