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.

149 lines
3.8 KiB

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