|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: lib/overlay/overlay-functions.in # Copyright (C) 2007 - 2008 The OpenSDE Project # # More information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END ---
# returns the type of overlay based on the extension of the overlay file # overlay_get_type() { local ext="${1##*.}"
case "$ext" in sh|exec) echo "exec" ;; txt|patch|ln) echo "$ext" ;; *) # and skip anything else ;; esac }
# returns the name of a target file based on the name overlay file # overlay_get_filename() { local filename="${1##*/}"; filename="${filename%.*}"
# rock_substitute will add a leading / for most translations echo "${filename}" | tr '_%' '/_' | rock_substitute | sed -e 's,^/,,' }
# apply an overlay dir overlay_apply() { local overlaydir="$1" rootfs="${2:-$root}" local file= source= target= ext= local type= mode= ref= targetdir=
for file in "$overlaydir"/*; do # only consider known overlay types type=$( overlay_get_type "$file" ) [ -n "$type" ] || continue
# full filename of the target file, and it's directory target=$( overlay_get_filename "$file" ) targetdir="$rootfs/$target"; targetdir="${targetdir%/*}"
# final adjustments based on the type case "$type" in exec) mode=0755 ;; *) mode=0644 ;; esac
# and finally inject the file case "$type" in exec|txt) echo_status "injecting $target ($type)" mkdir -p "$targetdir" [ ! -L "$rootfs/$target" ] || rm -f "$rootfs/$target" cat "$file" | rock_substitute > "$rootfs/$target" chmod $mode "$rootfs/$target" ;; ln) ref=$( cat "$file" | rock_substitute ) echo_status "injecting $target -> $ref" mkdir -p "$targetdir" ln -snf "$ref" "$rootfs/$target" ;; patch) echo_status "$(patch -p1 -d "${rootfs}" 2>&1 < $file )" ;; esac done }
|