1 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # Filename: lib/overlay/overlay-functions.in
5 # Copyright (C) 2007 - 2008 The OpenSDE Project
7 # More information can be found in the files COPYING and README.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; version 2 of the License. A copy of the
12 # GNU General Public License can be found in the file COPYING.
13 # --- SDE-COPYRIGHT-NOTE-END ---
15 # returns the type of overlay based on the extension of the overlay file
22 sh|exec) echo "exec" ;;
23 txt|patch|ln) echo "$ext" ;;
24 *) # and skip anything else
29 # returns the name of a target file based on the name overlay file
31 overlay_get_filename()
33 local filename="${1##*/}"; filename="${filename%.*}"
35 # rock_substitute will add a leading / for most translations
36 echo "${filename}" | tr '_%' '/_' | rock_substitute | sed -e 's,^/,,'
39 # apply an overlay dir
41 local overlaydir="$1" rootfs="${2:-$root}"
42 local file= source= target= ext=
43 local type= mode= ref= targetdir=
45 for file in "$overlaydir"/*; do
46 # only consider known overlay types
47 type=$( overlay_get_type "$file" )
48 [ -n "$type" ] || continue
50 # full filename of the target file, and it's directory
51 target=$( overlay_get_filename "$file" )
52 targetdir="$rootfs/$target"; targetdir="${targetdir%/*}"
54 # final adjustments based on the type
60 # and finally inject the file
63 echo_status "injecting $target ($type)"
65 [ ! -e "$rootfs/$target" ] || rm -f "$rootfs/$target"
66 cp -f "$file" "$rootfs/$target"
67 chmod $mode "$rootfs/$target"
69 ln) ref=$( cat "$file" )
70 echo_status "injecting $target -> $ref"
72 ln -snf "$ref" "$rootfs/$target"
75 echo_status "$(patch -p1 -d "${rootfs}" 2>&1 < $file )"