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 ".git"
43CopyIfPresent ".gitignore"
44CopyIfPresent "patches"
45CopyIfPresent "post_update.sh"
46CopyIfPresent "OWNERS"
47
48echo "Applying patches..."
49for p in $tmp_dir/patches/*.diff
50do
51  [ -e "$p" ] || continue
52  echo "Applying $p..."
53  patch -p1 -d $tmp_dir < $p;
54done
55
56if [ -f $tmp_dir/post_update.sh ]
57then
58  echo "Running post update script"
59  $tmp_dir/post_update.sh $tmp_dir $external_dir
60fi
61
62echo "Swapping old and new..."
63rm -rf $external_dir
64mv $tmp_dir $external_dir
65
66exit 0
67