|
1 | 1 | # coding: utf-8
|
2 | 2 |
|
3 | 3 | # A script to setup developer's workstation for developing with NativeScript
|
4 |
| -# To run it against PRODUCTION branch (recommended) use |
5 |
| -# ruby -e "$(curl -fsSL https://raw.githubusercontent.com/NativeScript/nativescript-cli/production/setup/native-script.rb)" |
6 |
| -# To run it against MASTER branch (usually only developers of NativeScript need to) use |
7 |
| -# ruby -e "$(curl -fsSL https://raw.githubusercontent.com/NativeScript/nativescript-cli/master/setup/native-script.rb)" |
| 4 | +# To run it against PRODUCTION branch (only one supported with self-elevation) use |
| 5 | +# sudo ruby -e "$(curl -fsSL https://raw.githubusercontent.com/NativeScript/nativescript-cli/production/setup/native-script.rb)" |
8 | 6 |
|
9 | 7 | # Only the user can manually download and install Xcode from App Store
|
| 8 | +unless Process.uid == 0 |
| 9 | + # Execute as root |
| 10 | + puts "This scripts needs sudo permissions" |
| 11 | + exec('sudo ruby -e "$(curl -fsSL https://raw.githubusercontent.com/NativeScript/nativescript-cli/production/setup/native-script.rb)"') |
| 12 | +end |
| 13 | + |
10 | 14 | puts "NativeScript requires Xcode."
|
11 | 15 | puts "If you do not have Xcode installed, download and install it from App Store and run it once to complete its setup."
|
12 | 16 | puts "Do you have Xcode installed? (y/n)"
|
13 | 17 |
|
14 | 18 | xcode = gets.chomp
|
15 | 19 |
|
16 |
| -if xcode == "n" || xcode == "N" |
| 20 | +if xcode.downcase == "n" |
17 | 21 | exit
|
18 | 22 | end
|
19 | 23 |
|
|
22 | 26 | exit
|
23 | 27 | end
|
24 | 28 |
|
25 |
| -puts "You need to accept the Xcode license agreement to be able to use the Xcode command-line tools. (You might need to provide your password.)" |
26 |
| -system('sudo xcodebuild -license') |
| 29 | +puts "You need to accept the Xcode license agreement to be able to use the Xcode command-line tools." |
| 30 | +system('xcodebuild -license') |
| 31 | + |
| 32 | +# Help with installing other dependencies |
| 33 | +$answer = "" |
| 34 | + |
| 35 | +def execute(script, warning_message, run_as_root = false) |
| 36 | + if run_as_root |
| 37 | + result = system(script) |
| 38 | + else |
| 39 | + result = system("sudo su " + ENV['SUDO_USER'] + " -c '" + script + "'") |
| 40 | + end |
| 41 | + |
| 42 | + if result.nil? |
| 43 | + STDERR.puts "ERROR: " + script + " execution FAILED" |
| 44 | + exit 1 |
| 45 | + end |
| 46 | + |
| 47 | + unless result |
| 48 | + STDERR.puts "WARNING: " + warning_message |
| 49 | + end |
| 50 | +end |
27 | 51 |
|
28 |
| -# Install all other dependencies |
29 |
| -puts "Installing Homebrew... (You might need to provide your password.)" |
30 |
| -system('ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"') |
| 52 | +def install(program_name, message, script, run_as_root = false, show_all_option = true) |
| 53 | + if $answer != "a" |
| 54 | + puts "Allow the script to install " + program_name + "?" |
| 55 | + if show_all_option |
| 56 | + puts "Note that if you type all you won't be prompted for subsequent installations" |
| 57 | + end |
| 58 | + |
| 59 | + loop do |
| 60 | + puts show_all_option ? "(Y)es/(N)o/(A)ll" : "(Y)es/(N)o" |
| 61 | + $answer = gets.chomp.downcase |
| 62 | + is_answer_yn = $answer == "y" || $answer == "n" |
| 63 | + break if show_all_option ? is_answer_yn || $answer == "a" : is_answer_yn |
| 64 | + end |
| 65 | + |
| 66 | + if $answer == "n" |
| 67 | + puts "You have chosen not to install " + program_name + ". Some features of NativeScript may not work correctly if you haven't already installed it" |
| 68 | + return |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + puts message |
| 73 | + execute(script, program_name + " not installed", run_as_root) |
| 74 | +end |
| 75 | + |
| 76 | +# Actually installing all other dependencies |
| 77 | +install("Homebrew", "Installing Homebrew...", 'ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</dev/null', false, false) |
31 | 78 |
|
32 | 79 | if !(`brew --version`.include? "git revision")
|
33 | 80 | puts "Homebrew is not installed or not configured properly. Download it from http://brew.sh/, install, set it up and run this script again."
|
34 | 81 | exit
|
35 | 82 | end
|
36 | 83 |
|
37 |
| -puts "Installing CocoaPods... This might take some time, please, be patient. (You might need to provide your password.)" |
38 |
| -system('sudo gem install cocoapods') |
39 |
| - |
40 |
| -puts "Installing Homebrew Cask... (You might need to provide your password.)" |
41 |
| -system('brew install caskroom/cask/brew-cask') |
| 84 | +install("Java SE Development Kit", "Installing the Java SE Development Kit... This might take some time, please, be patient. (You will be prompted for your password)", 'brew cask install java', false, false) |
| 85 | +execute('echo "export JAVA_HOME=$(/usr/libexec/java_home)" >> ~/.profile', "Unable to set JAVA_HOME") |
42 | 86 |
|
43 |
| -puts "Installing the Java SE Development Kit... This might take some time, please, be patient. (You might need to provide your password.)" |
44 |
| -system('brew cask install java') |
45 |
| -system('echo "export JAVA_HOME=$(/usr/libexec/java_home)" >> ~/.profile') |
| 87 | +install("Android SDK", "Installing Android SDK", 'brew install android-sdk') |
| 88 | +execute('echo "export ANDROID_HOME=/usr/local/opt/android-sdk" >> ~/.profile', "Unable to set ANDROID_HOME") |
46 | 89 |
|
47 |
| -puts "Installing Android SDK" |
48 |
| -system('brew install android-sdk') |
49 |
| -system('echo "export ANDROID_HOME=/usr/local/opt/android-sdk" >> ~/.profile') |
| 90 | +# the -p flag is set in order to ensure zero status code even if the directory exists |
| 91 | +execute("mkdir -p ~/.cocoapods", "There was a problem in creating ~/.cocoapods directory") |
| 92 | +install("CocoaPods", "Installing CocoaPods... This might take some time, please, be patient.", 'gem install cocoapods -V', true) |
50 | 93 |
|
51 | 94 | puts "Configuring your system for Android development... This might take some time, please, be patient."
|
52 |
| -system "echo yes | /usr/local/opt/android-sdk/tools/android update sdk --filter tools,platform-tools,android-23,build-tools-23.0.2,extra-android-m2repository --all --no-ui" |
| 95 | +# Note that multiple license acceptances may be required, hence the multiple y answers |
| 96 | +# the android tool will introduce a --accept-license option in subsequent releases |
| 97 | +execute("(for i in {1..5}; do echo y; sleep 4; done) | /usr/local/opt/android-sdk/tools/android update sdk --filter tools,platform-tools,android-23,build-tools-23.0.2,extra-android-m2repository --all --no-ui", |
| 98 | + "There seem to be some problems with the Android configuration") |
53 | 99 |
|
54 | 100 | puts "The ANDROID_HOME and JAVA_HOME environment variables have been added to your .profile. Restart the terminal to use them."
|
0 commit comments