1#!/bin/bash
2#
3# Copyright (C) 2007 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# This script is used by external_updater to replace a package. Don't
18# invoke directly.
19
20set -e
21
22tmp_dir=$1
23external_dir=$2
24
25echo "Entering $tmp_dir..."
26cd $tmp_dir
27
28function CopyIfPresent() {
29  if [ -e $external_dir/$1 ]; then
30    cp -a -n $external_dir/$1 .
31  fi
32}
33
34echo "Copying preserved files..."
35CopyIfPresent "Android.bp"
36CopyIfPresent "Android.mk"
37CopyIfPresent "CleanSpec.mk"
38CopyIfPresent "LICENSE"
39CopyIfPresent "NOTICE"
40cp -a -f -n $external_dir/MODULE_LICENSE_* .
41CopyIfPresent "METADATA"
42CopyIfPresent "TEST_MAPPING"
43CopyIfPresent ".git"
44CopyIfPresent ".gitignore"
45CopyIfPresent "patches"
46CopyIfPresent "post_update.sh"
47CopyIfPresent "OWNERS"
48CopyIfPresent "README.android"
49
50echo "Applying patches..."
51for p in $tmp_dir/patches/*.diff
52do
53  [ -e "$p" ] || continue
54  echo "Applying $p..."
55  patch -p1 -d $tmp_dir < $p;
56done
57
58if [ -f $tmp_dir/post_update.sh ]
59then
60  echo "Running post update script"
61  $tmp_dir/post_update.sh $tmp_dir $external_dir
62fi
63
64echo "Swapping old and new..."
65rm -rf $external_dir
66mv $tmp_dir $external_dir
67
68cd $external_dir
69git add .
70
71exit 0
72