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.

121 lines
3.0 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 - 2012 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|rm)
  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 [ "$type" != rm -a "$overwrite" != yes ]; then
  60. $echo_status "skipping $target ($type)"
  61. continue
  62. fi
  63. if [ "$type" = patch ]; then
  64. :
  65. elif [ ! -d "$xtarget/" ]; then
  66. rm -f "$xtarget"
  67. else
  68. rm -rf "$xtarget"
  69. fi
  70. fi
  71. # final adjustments based on the type
  72. case "$type" in
  73. exec) mode=0755 ;;
  74. *) mode=0644 ;;
  75. esac
  76. [ "$type" = "patch" ] || mkdir -p "$targetdir"
  77. # and finally inject the file
  78. case "$type" in
  79. bin|exec|txt)
  80. $echo_status "injecting $target ($type)"
  81. if [ "$type" = bin ]; then
  82. cp "$file" "$xtarget"
  83. else
  84. cat "$file" | rock_substitute > "$xtarget"
  85. fi
  86. chmod $mode "$xtarget"
  87. ;;
  88. ln) ref=$( cat "$file" | rock_substitute )
  89. $echo_status "injecting $target -> $ref"
  90. ln -snf "$ref" "$xtarget"
  91. ;;
  92. rm)
  93. $echo_status "removing $target"
  94. ;;
  95. patch)
  96. $echo_status "overlay: patching $target"
  97. rock_substitute "$file" | patch $patchopt "$xtarget"
  98. ;;
  99. esac
  100. # flist hackery... needed?
  101. case "$type" in
  102. patch|rm) ;;
  103. *) add_flist "$xtarget" ;;
  104. esac
  105. done
  106. }