#! /bin/bash
#       Licensed to the Apache Software Foundation (ASF) under one
#       or more contributor license agreements.  See the NOTICE file
#       distributed with this work for additional information
#       regarding copyright ownership.  The ASF licenses this file
#       to you under the Apache License, Version 2.0 (the
#       "License"); you may not use this file except in compliance
#       with the License.  You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#       Unless required by applicable law or agreed to in writing,
#       software distributed under the License is distributed on an
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.
#
ROOT="$( cd "$( dirname "$0" )/.." && pwd )"
cmd=`android list target`
if [[ $? != 0 ]]; then
    echo "The command \"android\" failed. Make sure you have the latest Android SDK installed, and the \"android\" command (inside the tools/ folder) added to your path."
    exit 2
elif [[ ! $cmd =~ "android-18" ]]; then
    echo "Please install Android target 18 (the Android 4.3 SDK). Make sure you have the latest Android tools installed as well. Run \"android\" from your command-line to install/update any missing SDKs or tools."
    exit 2
else
    cmd="android update project -p $ROOT -t android-18 1> /dev/null 2>&1"
    eval $cmd
    if [[ $? != 0 ]]; then
        echo "Error updating the Cordova library to work with your Android environment."
        exit 2
    fi
fi