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.

108 lines
2.7 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 - 2009 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. local ext="${1##*.}"
  18. case "$ext" in
  19. sh|exec) echo "exec" ;;
  20. txt|patch|ln|bin)
  21. 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. local filename="${1##*/}"; filename="${filename%.*}"
  30. # rock_substitute will add a leading / for most translations
  31. echo "${filename}" | tr '_%' '/_' | rock_substitute | sed -e 's,^/,,'
  32. }
  33. # apply an overlay dir
  34. overlay_apply() {
  35. local overlaydir= rootfs=
  36. local file= source= target= xtarget= ext=
  37. local type= mode= ref= targetdir=
  38. local patchopt="-p1 --no-backup-if-mismatch -N"
  39. local overwrite=yes echo_status=echo_status
  40. while [ $# -gt 0 ]; do
  41. case "$1" in
  42. -n) overwrite= ;;
  43. -q) echo_status=echo ;;
  44. --) shift; break ;;
  45. -*) echo_warning "overlay_apply: $1: invalid option." ;;
  46. *) break ;;
  47. esac
  48. shift
  49. done
  50. overlaydir="$1" rootfs="${2:-$root}"
  51. for file in "$overlaydir"/*; do
  52. # only consider known overlay types
  53. type=$( overlay_get_type "$file" )
  54. [ -n "$type" ] || continue
  55. # full filename of the target file, and it's directory
  56. target=$( overlay_get_filename "$file" )
  57. xtarget="$rootfs/$target" targetdir="${xtarget%/*}"
  58. if [ -L "$xtarget" -o -e "$xtarget" ]; then
  59. if [ "$overwrite" = yes ]; then
  60. [ "$type" = patch ] || rm -f "$xtarget"
  61. else
  62. $echo_status "skipping $target ($type)"
  63. continue
  64. fi
  65. fi
  66. # final adjustments based on the type
  67. case "$type" in
  68. exec) mode=0755 ;;
  69. *) mode=0644 ;;
  70. esac
  71. [ "$type" = "patch" ] || mkdir -p "$targetdir"
  72. # and finally inject the file
  73. case "$type" in
  74. bin|exec|txt)
  75. $echo_status "injecting $target ($type)"
  76. if [ "$type" = bin ]; then
  77. cp "$file" "$xtarget"
  78. else
  79. cat "$file" | rock_substitute > "$xtarget"
  80. fi
  81. chmod $mode "$xtarget"
  82. ;;
  83. ln) ref=$( cat "$file" | rock_substitute )
  84. $echo_status "injecting $target -> $ref"
  85. ln -snf "$ref" "$xtarget"
  86. ;;
  87. patch)
  88. $echo_status "$(patch $patchopt \
  89. -d "${rootfs}" 2>&1 < $file )"
  90. ;;
  91. esac
  92. [ "$type" = "patch" ] || add_flist "$xtarget"
  93. done
  94. }