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.

80 lines
2.1 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. for file in "$overlaydir"/*; do
  40. # only consider known overlay types
  41. type=$( overlay_get_type "$file" )
  42. [ -n "$type" ] || continue
  43. # full filename of the target file, and it's directory
  44. target=$( overlay_get_filename "$file" )
  45. targetdir="$rootfs/$target"; targetdir="${targetdir%/*}"
  46. # final adjustments based on the type
  47. case "$type" in
  48. exec) mode=0755 ;;
  49. *) mode=0644 ;;
  50. esac
  51. # and finally inject the file
  52. case "$type" in
  53. exec|txt)
  54. echo_status "injecting $target ($type)"
  55. mkdir -p "$targetdir"
  56. [ ! -e "$rootfs/$target" ] || rm -f "$rootfs/$target"
  57. cp -f "$file" "$rootfs/$target"
  58. chmod $mode "$rootfs/$target"
  59. ;;
  60. ln) ref=$( cat "$file" )
  61. echo_status "injecting $target -> $ref"
  62. mkdir -p "$targetdir"
  63. ln -snf "$ref" "$rootfs/$target"
  64. ;;
  65. patch)
  66. echo_status "$(patch -p1 -d "${rootfs}" 2>&1 < $file )"
  67. ;;
  68. esac
  69. done
  70. }