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.

143 lines
4.0 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: target/share/initramfs/build.sh
  5. # Copyright (C) 2007 - 2011 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. #Description: Initial ramfs image (cpio.gz)
  15. rootfs="$build_toolchain/initrd"
  16. rm -rf "$rootfs"
  17. mkdir -p "$rootfs"
  18. # Hooks
  19. #
  20. INITRAMFS_POSTINSTALL_HOOK=
  21. INITRAMFS_POSTOVERLAY_HOOK=
  22. # Lists
  23. #
  24. INITRAMFS_INSTALL_PACKAGES=
  25. INITRAMFS_INSTALL_PATTERN="-e '/ var\/adm/ d;' \
  26. -e '/\.\(h\|o\|a\|a\..*\|la\|pc\)$/d;' -e '/\/aclocal\//d;' \
  27. -e '/ usr\/share\/\(doc\|info\|man\)\//d;' -e'/ opt\/[^\/]*\/\(doc\|info\|man\)\//d;' -e '/\/gtk-doc\//d;'"
  28. INITRAMFS_EMPTY_PATTERN="-e '/\.\/lib\/udev\/devices\//d;'"
  29. # source library, and the target specific overlay
  30. #
  31. . "target/share/initramfs.in"
  32. if [ -f target/$target/build-initramfs.in ]; then
  33. . target/$target/build-initramfs.in
  34. fi
  35. # install what was flisted for stage 1 packages, use $INITRAMFS_INSTALL_PATTERN to skip files
  36. #
  37. [ -n "$INITRAMFS_INSTALL_PACKAGES" ] || INITRAMFS_INSTALL_PACKAGES=$( initramfs_list_stage1 )
  38. echo_status "Populating ${rootfs#$base/} ..."
  39. for pkg_name in $INITRAMFS_INSTALL_PACKAGES; do
  40. if initramfs_install "$pkg_name" "build/$SDECFG_ID" "$rootfs"; then
  41. echo_status "- $pkg_name"
  42. eval "initramfs_install_flist '$pkg_name' 'build/$SDECFG_ID' '$rootfs' $( initramfs_install_pattern "$pkg_name" "$INITRAMFS_INSTALL_PATTERN" )"
  43. fi
  44. done
  45. # hook $INITRAMFS_POSTINSTALL_HOOK
  46. #
  47. [ -z "$INITRAMFS_POSTINSTALL_HOOK" ] || eval "$INITRAMFS_POSTINSTALL_HOOK"
  48. # Apply overlay
  49. [ ! -d "target/$target/initramfs" ] || initramfs_install_overlay "target/$target/initramfs" "$rootfs"
  50. # hook $INITRAMFS_POSTOVERLAY_HOOK
  51. #
  52. [ -z "$INITRAMFS_POSTOVERLAY_HOOK" ] || eval "$INITRAMFS_POSTOVERLAY_HOOK"
  53. # remove empty directories, use $INITRAMFS_EMPTY_PATTERN to skip directories
  54. #
  55. echo_status "Removing empty directories ..."
  56. ( cd "$rootfs"; find . -type d ) | tac | eval "sed -e '/\.\/\(dev\|sys\|proc\|mnt\|srv\|tmp\|root\|var\)\(\|\/.*\)$/d;' $INITRAMFS_EMPTY_PATTERN" | while read folder; do
  57. count=$( find "$rootfs/$folder" | wc -l )
  58. if [ $count -eq 1 ]; then
  59. rm -r "$rootfs/$folder"
  60. # echo_status "- ${folder} deleted."
  61. fi
  62. done
  63. echo_status "Checking for broken symlinks ..."
  64. ( cd "$rootfs"; find . -type l | cut -c2- ) | while read link; do
  65. x="$link"
  66. case "$link" in
  67. /dev/*) continue ;;
  68. esac
  69. while true; do
  70. target=$( readlink "$rootfs$x" )
  71. case "$target" in
  72. /proc/*)
  73. continue 2
  74. ;;
  75. /*)
  76. ;;
  77. *)
  78. # relatives turned into absolute
  79. target="${x%/*}/${target}"
  80. esac
  81. [ -L "$rootfs$target" ] || break 1
  82. x="$target"
  83. done
  84. if [ ! -e "$rootfs$target" ]; then
  85. echo_warning "- $link is broken ($target), deleting."
  86. rm -f "$rootfs$link"
  87. fi
  88. done
  89. # ldconfig
  90. #
  91. if [ -s "$rootfs/etc/ld.so.conf" ]; then
  92. echo_status "Running ldconfig ..."
  93. ldconfig -r "$rootfs"
  94. fi
  95. # sanity checks
  96. #
  97. [ -x "$rootfs/init" ] || echo_warning "This image is missing an /init file, it wont run."
  98. for x in $rootfs/{,usr/}{sbin,bin}/* $rootfs/init $rootfs/lib/udev/*; do
  99. [ -e "$x" ] || continue
  100. signature="$( file "$x" 2> /dev/null | cut -d' ' -f2- )"
  101. case "$signature" in
  102. directory) continue ;;
  103. ASCII\ English\ text)
  104. continue ;;
  105. *symbolic*|*statically*|*shell*)
  106. continue ;;
  107. *dynamically\ linked*)
  108. [ "$SDECFG_STATIC" == 1 ] || continue ;;
  109. esac
  110. echo_warning "evil signature ($signature) on '${x#$rootfs}'."
  111. done
  112. echo_status "Expanded size: $( du -sh "$rootfs" | cut -f1)."
  113. echo_status "Creating ${rootfs#$base/}.img ..."
  114. ( cd "$rootfs"; find . | cpio -o -H newc ) |
  115. gzip -c -9 > "$rootfs.img"
  116. echo_status "Image size: $( du -sh "$rootfs.img" | cut -f1)."