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.

prerun.sh 1.6 KiB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash -e
  2. IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
  3. NOOBS_DIR="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}"
  4. unmount_image "${IMG_FILE}"
  5. mkdir -p "${STAGE_WORK_DIR}"
  6. cp "${WORK_DIR}/export-image/${IMG_FILENAME}${IMG_SUFFIX}.img" "${STAGE_WORK_DIR}/"
  7. rm -rf "${NOOBS_DIR}"
  8. PARTED_OUT=$(parted -sm "${IMG_FILE}" unit b print)
  9. BOOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^1:' | cut -d':' -f 2 | tr -d B)
  10. BOOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^1:' | cut -d':' -f 4 | tr -d B)
  11. ROOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 2 | tr -d B)
  12. ROOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 4 | tr -d B)
  13. BOOT_DEV=$(losetup --show -f -o "${BOOT_OFFSET}" --sizelimit "${BOOT_LENGTH}" "${IMG_FILE}")
  14. ROOT_DEV=$(losetup --show -f -o "${ROOT_OFFSET}" --sizelimit "${ROOT_LENGTH}" "${IMG_FILE}")
  15. echo "/boot: offset $BOOT_OFFSET, length $BOOT_LENGTH"
  16. echo "/: offset $ROOT_OFFSET, length $ROOT_LENGTH"
  17. mkdir -p "${STAGE_WORK_DIR}/rootfs"
  18. mkdir -p "${NOOBS_DIR}"
  19. mount "$ROOT_DEV" "${STAGE_WORK_DIR}/rootfs"
  20. mount "$BOOT_DEV" "${STAGE_WORK_DIR}/rootfs/boot"
  21. ln -sv "/lib/systemd/system/apply_noobs_os_config.service" "$ROOTFS_DIR/etc/systemd/system/multi-user.target.wants/apply_noobs_os_config.service"
  22. bsdtar --numeric-owner --format gnutar -C "${STAGE_WORK_DIR}/rootfs/boot" -cpf - . | xz -T0 > "${NOOBS_DIR}/boot.tar.xz"
  23. umount "${STAGE_WORK_DIR}/rootfs/boot"
  24. bsdtar --numeric-owner --format gnutar -C "${STAGE_WORK_DIR}/rootfs" --one-file-system -cpf - . | xz -T0 > "${NOOBS_DIR}/root.tar.xz"
  25. unmount_image "${IMG_FILE}"