Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

104 linhas
2.6 KiB

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