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.
 
 
 
 
 

120 lines
3.4 KiB

  1. #!/bin/bash -e
  2. IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
  3. INFO_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.info"
  4. sed -i 's/^update_initramfs=.*/update_initramfs=all/' "${ROOTFS_DIR}/etc/initramfs-tools/update-initramfs.conf"
  5. on_chroot << EOF
  6. update-initramfs -u
  7. if [ -x /etc/init.d/fake-hwclock ]; then
  8. /etc/init.d/fake-hwclock stop
  9. fi
  10. if hash hardlink 2>/dev/null; then
  11. hardlink -t /usr/share/doc
  12. fi
  13. EOF
  14. if [ -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.config" ]; then
  15. chmod 700 "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.config"
  16. fi
  17. rm -f "${ROOTFS_DIR}/usr/bin/qemu-arm-static"
  18. if [ "${USE_QEMU}" != "1" ]; then
  19. if [ -e "${ROOTFS_DIR}/etc/ld.so.preload.disabled" ]; then
  20. mv "${ROOTFS_DIR}/etc/ld.so.preload.disabled" "${ROOTFS_DIR}/etc/ld.so.preload"
  21. fi
  22. fi
  23. rm -f "${ROOTFS_DIR}/etc/network/interfaces.dpkg-old"
  24. rm -f "${ROOTFS_DIR}/etc/apt/sources.list~"
  25. rm -f "${ROOTFS_DIR}/etc/apt/trusted.gpg~"
  26. rm -f "${ROOTFS_DIR}/etc/passwd-"
  27. rm -f "${ROOTFS_DIR}/etc/group-"
  28. rm -f "${ROOTFS_DIR}/etc/shadow-"
  29. rm -f "${ROOTFS_DIR}/etc/gshadow-"
  30. rm -f "${ROOTFS_DIR}/etc/subuid-"
  31. rm -f "${ROOTFS_DIR}/etc/subgid-"
  32. rm -f "${ROOTFS_DIR}"/var/cache/debconf/*-old
  33. rm -f "${ROOTFS_DIR}"/var/lib/dpkg/*-old
  34. rm -f "${ROOTFS_DIR}"/usr/share/icons/*/icon-theme.cache
  35. rm -f "${ROOTFS_DIR}/var/lib/dbus/machine-id"
  36. true > "${ROOTFS_DIR}/etc/machine-id"
  37. ln -nsf /proc/mounts "${ROOTFS_DIR}/etc/mtab"
  38. find "${ROOTFS_DIR}/var/log/" -type f -exec cp /dev/null {} \;
  39. rm -f "${ROOTFS_DIR}/root/.vnc/private.key"
  40. rm -f "${ROOTFS_DIR}/etc/vnc/updateid"
  41. update_issue "$(basename "${EXPORT_DIR}")"
  42. install -m 644 "${ROOTFS_DIR}/etc/rpi-issue" "${ROOTFS_DIR}/boot/firmware/issue.txt"
  43. cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE"
  44. {
  45. if [ -f "$ROOTFS_DIR/usr/share/doc/raspberrypi-kernel/changelog.Debian.gz" ]; then
  46. firmware=$(zgrep "firmware as of" \
  47. "$ROOTFS_DIR/usr/share/doc/raspberrypi-kernel/changelog.Debian.gz" | \
  48. head -n1 | sed -n 's|.* \([^ ]*\)$|\1|p')
  49. printf "\nFirmware: https://github.com/raspberrypi/firmware/tree/%s\n" "$firmware"
  50. kernel="$(curl -s -L "https://github.com/raspberrypi/firmware/raw/$firmware/extra/git_hash")"
  51. printf "Kernel: https://github.com/raspberrypi/linux/tree/%s\n" "$kernel"
  52. uname="$(curl -s -L "https://github.com/raspberrypi/firmware/raw/$firmware/extra/uname_string7")"
  53. printf "Uname string: %s\n" "$uname"
  54. fi
  55. printf "\nPackages:\n"
  56. dpkg -l --root "$ROOTFS_DIR"
  57. } >> "$INFO_FILE"
  58. mkdir -p "${DEPLOY_DIR}"
  59. rm -f "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}.*"
  60. rm -f "${DEPLOY_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
  61. mv "$INFO_FILE" "$DEPLOY_DIR/"
  62. if [ "${USE_QCOW2}" = "0" ] && [ "${NO_PRERUN_QCOW2}" = "0" ]; then
  63. ROOT_DEV="$(mount | grep "${ROOTFS_DIR} " | cut -f1 -d' ')"
  64. unmount "${ROOTFS_DIR}"
  65. zerofree "${ROOT_DEV}"
  66. unmount_image "${IMG_FILE}"
  67. else
  68. unload_qimage
  69. make_bootable_image "${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.qcow2" "$IMG_FILE"
  70. fi
  71. case "${DEPLOY_COMPRESSION}" in
  72. zip)
  73. pushd "${STAGE_WORK_DIR}" > /dev/null
  74. zip -"${COMPRESSION_LEVEL}" \
  75. "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}.zip" "$(basename "${IMG_FILE}")"
  76. popd > /dev/null
  77. ;;
  78. gz)
  79. pigz --force -"${COMPRESSION_LEVEL}" "$IMG_FILE" --stdout > \
  80. "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}.img.gz"
  81. ;;
  82. xz)
  83. xz --compress --force --threads 0 --memlimit-compress=50% -"${COMPRESSION_LEVEL}" \
  84. --stdout "$IMG_FILE" > "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}.img.xz"
  85. ;;
  86. none | *)
  87. cp "$IMG_FILE" "$DEPLOY_DIR/"
  88. ;;
  89. esac