如何自动安装Xcode?
我试图编写一个shell脚本,将我们所有的开发工具和依赖项安装到一台干净的OSX机器上 有人知道自动安装Xcode的最佳方法吗 我这样做是为了:如何自动安装Xcode?,xcode,build-automation,Xcode,Build Automation,我试图编写一个shell脚本,将我们所有的开发工具和依赖项安装到一台干净的OSX机器上 有人知道自动安装Xcode的最佳方法吗 我这样做是为了: 记录开发环境 加快新开发人员的入职流程 遵循一切自动化原则 从Xcode 4.3开始,它以应用程序包的形式提供。第一次启动应用程序时,它将继续安装。由于它是beta版,所以还没有修复,但目前发布后安装包位于名为Contents/Resources/packages的目录中的应用程序包中 因此,根据您的环境,您的安装脚本只需将Xcode.app捆绑包复制
从Xcode 4.3开始,它以应用程序包的形式提供。第一次启动应用程序时,它将继续安装。由于它是beta版,所以还没有修复,但目前发布后安装包位于名为Contents/Resources/packages的目录中的应用程序包中 因此,根据您的环境,您的安装脚本只需将Xcode.app捆绑包复制到应用程序目录中,您的用户就可以在第一次启动它时完成安装。或者,您可以复制捆绑包,然后使用
安装程序(8)
实用程序手动安装附加软件包。有关使用安装程序的更多信息,请参阅。全自动XCode安装
首先,登录,获取适用于您的OSX版本的XCode.dmg版本。您可能希望获得几个版本来支持不同的OSX平台(例如:10.10 Yosemite、10.9 Mavericks等)。将dmg上传到您可以访问的文件主机(例如:Amazon S3、Dropbox、您选择的共享主机提供商等)
更改以下脚本中的下载\u BASE\u URL
,并使用版本号和内部版本号适当重命名DMG,或将其添加到下面的脚本中:
#!/bin/bash
DOWNLOAD_BASE_URL=http://example.com/path/to/xcode/dmgs/
## Figure out OSX version (source: https://www.opscode.com/chef/install.sh)
function detect_platform_version() {
# Matching the tab-space with sed is error-prone
platform_version=$(sw_vers | awk '/^ProductVersion:/ { print $2 }')
major_version=$(echo $platform_version | cut -d. -f1,2)
# x86_64 Apple hardware often runs 32-bit kernels (see OHAI-63)
x86_64=$(sysctl -n hw.optional.x86_64)
if [ $x86_64 -eq 1 ]; then
machine="x86_64"
fi
}
detect_platform_version
# Determine which XCode version to use based on platform version
case $platform_version in
"10.10") XCODE_DMG='XCode-6.1.1-6A2008a.dmg' ;;
"10.9") XCODE_DMG='XCode-5.0.2-5A3005.dmg' ;;
*) XCODE_DMG='XCode-5.0.1-5A2053.dmg' ;;
esac
# Bootstrap XCode from dmg
if [ ! -d "/Applications/Xcode.app" ]; then
echo "INFO: XCode.app not found. Installing XCode..."
if [ ! -e "$XCODE_DMG" ]; then
curl -L -O "${DOWNLOAD_BASE_URL}/${XCODE_DMG}"
fi
hdiutil attach "$XCODE_DMG"
export __CFPREFERENCES_AVOID_DAEMON=1
sudo installer -pkg '/Volumes/XCode/XCode.pkg' -target /
hdiutil detach '/Volumes/XCode'
fi
您可能有兴趣安装XCode命令行工具,并绕过XCode许可协议:
curl -Ls https://gist.github.com/trinitronx/6217746/raw/58456d6675e437cebbf771c60b6005b4491a0980/xcode-cli-tools.sh | sudo bash
# We need to accept the xcodebuild license agreement before building anything works
# Silly Apple...
if [ -x "$(which expect)" ]; then
echo "INFO: GNU expect found! By using this script, you automatically accept the XCode License agreement found here: http://www.apple.com/legal/sla/docs/xcode.pdf"
expect ./bootstrap-scripts/accept-xcodebuild-license.exp
else
echo -e "\x1b[31;1mERROR:\x1b[0m Could not find expect utility (is '$(which expect)' executable?)"
echo -e "\x1b[31;1mWarning:\x1b[0m You have not agreed to the Xcode license.\nBuilds will fail! Agree to the license by opening Xcode.app or running:\n
xcodebuild -license\n\nOR for system-wide acceptance\n
sudo xcodebuild -license"
exit 1
fi
替代方法
另一种选择是使用
使用:
git clone https://gist.github.com/6237049.git
cd 6237049/
# Edit the script with AppleScript Editor to replace your APPLE ID and PASSWORD
osascript Install_XCode.applescript
你可能也对我的答案感兴趣
我建议使用另一种方法,而不是applescript方法。applescript依赖于UI元素层次结构,对于OSX上的App Store应用程序的未来版本,该层次结构可能不会始终保持不变。我只是觉得它很脆弱。通过dmg通过命令行安装XCode可能是最可靠的方法。很多自动下载和安装的东西都过时了。我一直在为另一个项目工作,我认为我有一个很好的解决方案: 以下是下载部分:
好吧,对于浏览此页面的用户,Fastlane的一位作者制作了一个gem来自动完成此过程
#安装命令行工具作为自制软件的依赖项
xcode select--install#将开发目录路径设置为/Library/Developer/CommandLineTools
#安装自制软件
/bin/bash-c“$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
#安装Mas(Mac App Store的命令行界面)
brew安装mas
#搜索仅显示前5个结果的Xcode
mas搜索xcode |头-5
#使用应用程序ID安装Xcode
mas安装497799835#执行搜索时显示的Xcode的appid
sudo xcode select-r#将开发目录路径重置为xcode/Applications/xcode.app/Contents/Developer
#sudoxcodebuild-许可证
#升级所有Apple软件并自动同意任何许可证,必要时重新启动
sudo软件更新--安装--同意许可证-aR
这可能是一个更好的问题。显然,最新版本的xcodebuild
在-license
标志中添加了一个accept
参数-@Anon:太棒了!几年前肯定会有帮助的XD