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.

101 lines
3.1 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 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. initrddir="$build_toolchain/initrd"
  16. rm -rf "$initrddir"
  17. mkdir -p "$initrddir"
  18. INITRD_POSTFLIST_HOOK=
  19. INITRD_FLIST_PACKAGES=
  20. INITRD_FLIST_PATTERN="-e '/\.\(h\|o\|a\|a\..*\|la\|pc\)$/d;' -e '/ usr\/share\/\(doc\|info\|man\)\//d;'"
  21. INITRD_EMPTY_PATTERN="-e '/\.\/lib\/udev\/devices\//d;'"
  22. # weak function, should this package be extracted by flist or not?
  23. initrd_flist_install_filter() { true; }
  24. # source target specific code
  25. #
  26. if [ -f target/$target/build-initramfs.in ]; then
  27. . target/$target/build-initramfs.in
  28. fi
  29. # install what was flisted for stage 1 packages, use $INITRD_FLIST_PATTERN to skip files
  30. #
  31. if [ -z "$INITRD_FLIST_PACKAGES" ]; then
  32. INITRD_FLIST_PACKAGES=$( grep '^X .1' $base/config/$config/packages | cut -d' ' -f5 | tr '\n' ' ' )
  33. fi
  34. echo_status "Populating ${initrddir#$base/} ..."
  35. for pkg_name in $INITRD_FLIST_PACKAGES; do
  36. if initrd_flist_install_filter $pkg_name; then
  37. echo_status "- $pkg_name"
  38. flist="build/${SDECFG_ID}/var/adm/flists/$pkg_name"
  39. eval "sed -e '/ var\/adm/ d;' $INITRD_FLIST_PATTERN '$flist'" | cut -f2- -d' ' |
  40. tar -C "build/${SDECFG_ID}/" -cf- --no-recursion --files-from=- |
  41. tar -C "$initrddir" -xf-
  42. fi
  43. done
  44. # hook
  45. #
  46. [ -z "$INITRD_POSTFLIST_HOOK" ] || eval "$INITRD_POSTFLIST_HOOK"
  47. if [ -r "target/$target/init.sh" ]; then
  48. echo_status "Copying target's /init script."
  49. cp "target/$target/init.sh" "${initrddir}/init"
  50. chmod +x "${initrddir}/init"
  51. fi
  52. # remove empty folder, use $INITRD_EMPTY_PATTERN to skip folders
  53. #
  54. echo_status "Removing empty folders ..."
  55. ( cd "$initrddir"; find . -type d ) | tac | eval "sed -e '/\.\/\(dev\|sys\|proc\|mnt\|tmp\)\$/d;' $INITRD_EMPTY_PATTERN" | while read folder; do
  56. count=$( find "${initrddir}/$folder" | wc -l )
  57. if [ $count -eq 1 ]; then
  58. rm -r "${initrddir}/$folder"
  59. # echo_status "- ${folder} deleted."
  60. fi
  61. done
  62. # sanity check
  63. [ -x "${initrddir}/init" ] || echo_warning "This image is missing an /init file, it wont run."
  64. for x in ${initrddir}/{,usr/}{sbin,bin}/* ${initrddir}/init ${initrddir}/lib/udev/*; do
  65. [ -e "$x" ] || continue
  66. signature="$( file "$x" 2> /dev/null | cut -d' ' -f2- )"
  67. case "$signature" in
  68. directory) continue ;;
  69. ASCII\ English\ text)
  70. continue ;;
  71. *symbolic*|*statically*|*shell*)
  72. continue ;;
  73. esac
  74. echo_warning "evil signature ($signature) on '${x#$initrddir}'."
  75. done
  76. echo_status "Expanded size: $( du -sh "$initrddir" | cut -f1)."
  77. echo_status "Creating ${initrddir#$base/}.img ..."
  78. ( cd "$initrddir"; find * | cpio -o -H newc ) |
  79. gzip -c -9 > "$initrddir.img"
  80. echo_status "Image size: $( du -sh "$initrddir.img" | cut -f1)."