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.

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