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.

102 lines
3.2 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 - 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. #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. # remove empty folder, use $INITRAMFS_EMPTY_PATTERN to skip folders
  51. #
  52. echo_status "Removing empty folders ..."
  53. ( 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
  54. count=$( find "$rootfs/$folder" | wc -l )
  55. if [ $count -eq 1 ]; then
  56. rm -r "$rootfs/$folder"
  57. # echo_status "- ${folder} deleted."
  58. fi
  59. done
  60. # sanity checks
  61. #
  62. [ -x "$rootfs/init" ] || echo_warning "This image is missing an /init file, it wont run."
  63. for x in $rootfs/{,usr/}{sbin,bin}/* $rootfs/init $rootfs/lib/udev/*; do
  64. [ -e "$x" ] || continue
  65. signature="$( file "$x" 2> /dev/null | cut -d' ' -f2- )"
  66. case "$signature" in
  67. directory) continue ;;
  68. ASCII\ English\ text)
  69. continue ;;
  70. *symbolic*|*statically*|*shell*)
  71. continue ;;
  72. *dynamically\ linked*)
  73. [ "$SDECFG_STATIC" == 1 ] || continue ;;
  74. esac
  75. echo_warning "evil signature ($signature) on '${x#$rootfs}'."
  76. done
  77. echo_status "Expanded size: $( du -sh "$rootfs" | cut -f1)."
  78. echo_status "Creating ${rootfs#$base/}.img ..."
  79. ( cd "$rootfs"; find * | cpio -o -H newc ) |
  80. gzip -c -9 > "$rootfs.img"
  81. echo_status "Image size: $( du -sh "$rootfs.img" | cut -f1)."