OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.2 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/overlay/overlay-functions.in
  5. # Copyright (C) 2007 - 2008 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  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 ---
  14. # returns the type of overlay based on the extension of the overlay file
  15. #
  16. overlay_get_type()
  17. {
  18. local ext="${1##*.}"
  19. case "$ext" in
  20. sh|exec) echo "exec" ;;
  21. txt|patch|ln) echo "$ext" ;;
  22. *) # and skip anything else
  23. ;;
  24. esac
  25. }
  26. # returns the name of a target file based on the name overlay file
  27. #
  28. overlay_get_filename()
  29. {
  30. local filename="${1##*/}"; filename="${filename%.*}"
  31. # rock_substitute will add a leading / for most translations
  32. echo "${filename}" | tr '_%' '/_' | rock_substitute | sed -e 's,^/,,'
  33. }
  34. # apply an overlay dir
  35. overlay_apply() {
  36. local overlaydir="$1" rootfs="${2:-$root}"
  37. local file= source= target= ext=
  38. local type= mode= ref= targetdir=
  39. local patchopt="-p1 --no-backup-if-mismatch -N"
  40. for file in "$overlaydir"/*; do
  41. # only consider known overlay types
  42. type=$( overlay_get_type "$file" )
  43. [ -n "$type" ] || continue
  44. # full filename of the target file, and it's directory
  45. target=$( overlay_get_filename "$file" )
  46. targetdir="$rootfs/$target"; targetdir="${targetdir%/*}"
  47. # final adjustments based on the type
  48. case "$type" in
  49. exec) mode=0755 ;;
  50. *) mode=0644 ;;
  51. esac
  52. # and finally inject the file
  53. case "$type" in
  54. exec|txt)
  55. echo_status "injecting $target ($type)"
  56. mkdir -p "$targetdir"
  57. [ ! -L "$rootfs/$target" ] || rm -f "$rootfs/$target"
  58. cat "$file" | rock_substitute > "$rootfs/$target"
  59. chmod $mode "$rootfs/$target"
  60. ;;
  61. ln) ref=$( cat "$file" | rock_substitute )
  62. echo_status "injecting $target -> $ref"
  63. mkdir -p "$targetdir"
  64. ln -snf "$ref" "$rootfs/$target"
  65. ;;
  66. patch)
  67. echo_status "$(patch $patchopt \
  68. -d "${rootfs}" 2>&1 < $file )"
  69. ;;
  70. esac
  71. done
  72. }