# --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: lib/overlay/overlay-functions.in # Copyright (C) 2007 - 2009 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|bin) 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= rootfs= local file= source= target= xtarget= ext= local type= mode= ref= targetdir= local patchopt="-p1 --no-backup-if-mismatch -N" local overwrite=yes echo_status=echo_status while [ $# -gt 0 ]; do case "$1" in -n) overwrite= ;; -q) echo_status=echo ;; --) shift; break ;; -*) echo_warning "overlay_apply: $1: invalid option." ;; *) break ;; esac shift done overlaydir="$1" rootfs="${2:-$root}" 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" ) xtarget="$rootfs/$target" targetdir="${xtarget%/*}" if [ -L "$xtarget" -o -e "$xtarget" ]; then if [ "$overwrite" = yes ]; then [ "$type" = patch ] || rm -f "$xtarget" else $echo_status "skipping $target ($type)" continue fi fi # final adjustments based on the type case "$type" in exec) mode=0755 ;; *) mode=0644 ;; esac [ "$type" = "patch" ] || mkdir -p "$targetdir" # and finally inject the file case "$type" in bin|exec|txt) $echo_status "injecting $target ($type)" if [ "$type" = bin ]; then cp "$file" "$xtarget" else cat "$file" | rock_substitute > "$xtarget" fi chmod $mode "$xtarget" ;; ln) ref=$( cat "$file" | rock_substitute ) $echo_status "injecting $target -> $ref" ln -snf "$ref" "$xtarget" ;; patch) $echo_status "$(patch $patchopt \ -d "${rootfs}" 2>&1 < $file )" ;; esac [ "$type" = "patch" ] || add_flist "$xtarget" done }