Burrow Raspberry Pi Image
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.

98 lines
2.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. log (){
  2. date +"[%T] [email protected]" | tee -a "${LOG_FILE}"
  3. }
  4. export -f log
  5. bootstrap(){
  6. local ARCH
  7. ARCH=$(dpkg --print-architecture)
  8. export http_proxy=${APT_PROXY}
  9. if [ "$ARCH" != "armhf" ]; then
  10. local BOOTSTRAP_CMD=qemu-debootstrap
  11. else
  12. local BOOTSTRAP_CMD=debootstrap
  13. fi
  14. capsh --drop=cap_setfcap -- -c "${BOOTSTRAP_CMD} --components=main,contrib,non-free \
  15. --arch armhf \
  16. --keyring "${STAGE_DIR}/files/raspberrypi.gpg" \
  17. $1 $2 $3" || rmdir "$2/debootstrap"
  18. }
  19. export -f bootstrap
  20. copy_previous(){
  21. if [ ! -d "${PREV_ROOTFS_DIR}" ]; then
  22. echo "Previous stage rootfs not found"
  23. false
  24. fi
  25. mkdir -p "${ROOTFS_DIR}"
  26. rsync -aHAXx --exclude var/cache/apt/archives "${PREV_ROOTFS_DIR}/" "${ROOTFS_DIR}/"
  27. }
  28. export -f copy_previous
  29. unmount(){
  30. if [ -z "$1" ]; then
  31. DIR=$PWD
  32. else
  33. DIR=$1
  34. fi
  35. while mount | grep -q "$DIR"; do
  36. local LOCS
  37. LOCS=$(mount | grep "$DIR" | cut -f 3 -d ' ' | sort -r)
  38. for loc in $LOCS; do
  39. umount "$loc"
  40. done
  41. done
  42. }
  43. export -f unmount
  44. unmount_image(){
  45. sync
  46. sleep 1
  47. local LOOP_DEVICES
  48. LOOP_DEVICES=$(losetup -j "${1}" | cut -f1 -d':')
  49. for LOOP_DEV in ${LOOP_DEVICES}; do
  50. if [ -n "${LOOP_DEV}" ]; then
  51. local MOUNTED_DIR
  52. MOUNTED_DIR=$(mount | grep "$(basename "${LOOP_DEV}")" | head -n 1 | cut -f 3 -d ' ')
  53. if [ -n "${MOUNTED_DIR}" ] && [ "${MOUNTED_DIR}" != "/" ]; then
  54. unmount "$(dirname "${MOUNTED_DIR}")"
  55. fi
  56. sleep 1
  57. losetup -d "${LOOP_DEV}"
  58. fi
  59. done
  60. }
  61. export -f unmount_image
  62. on_chroot() {
  63. if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/proc)"; then
  64. mount -t proc proc "${ROOTFS_DIR}/proc"
  65. fi
  66. if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/dev)"; then
  67. mount --bind /dev "${ROOTFS_DIR}/dev"
  68. fi
  69. if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/dev/pts)"; then
  70. mount --bind /dev/pts "${ROOTFS_DIR}/dev/pts"
  71. fi
  72. if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/sys)"; then
  73. mount --bind /sys "${ROOTFS_DIR}/sys"
  74. fi
  75. capsh --drop=cap_setfcap "--chroot=${ROOTFS_DIR}/" -- "[email protected]"
  76. }
  77. export -f on_chroot
  78. update_issue() {
  79. local GIT_HASH
  80. GIT_HASH=$(git rev-parse HEAD)
  81. echo -e "Raspberry Pi reference ${IMG_DATE}\nGenerated using pi-gen, https://github.com/RPi-Distro/pi-gen, ${GIT_HASH}, ${1}" > "${ROOTFS_DIR}/etc/rpi-issue"
  82. }
  83. export -f update_issue