No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

114 líneas
2.7 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. BOOTSTRAP_ARGS+=(--arch arm64)
  10. BOOTSTRAP_ARGS+=(--include gnupg)
  11. BOOTSTRAP_ARGS+=(--components "main,contrib,non-free")
  12. #BOOTSTRAP_ARGS+=(--keyring "${STAGE_DIR}/files/raspberrypi.gpg")
  13. BOOTSTRAP_ARGS+=(--exclude=info)
  14. BOOTSTRAP_ARGS+=(--include=ca-certificates)
  15. BOOTSTRAP_ARGS+=("$@")
  16. printf -v BOOTSTRAP_STR '%q ' "${BOOTSTRAP_ARGS[@]}"
  17. capsh $CAPSH_ARG -- -c "'${BOOTSTRAP_CMD}' $BOOTSTRAP_STR" || true
  18. if [ -d "$2/debootstrap" ] && ! rmdir "$2/debootstrap"; then
  19. cp "$2/debootstrap/debootstrap.log" "${STAGE_WORK_DIR}"
  20. log "bootstrap failed: please check ${STAGE_WORK_DIR}/debootstrap.log"
  21. return 1
  22. fi
  23. }
  24. export -f bootstrap
  25. copy_previous(){
  26. if [ ! -d "${PREV_ROOTFS_DIR}" ]; then
  27. echo "Previous stage rootfs not found"
  28. false
  29. fi
  30. mkdir -p "${ROOTFS_DIR}"
  31. rsync -aHAXx --exclude var/cache/apt/archives "${PREV_ROOTFS_DIR}/" "${ROOTFS_DIR}/"
  32. }
  33. export -f copy_previous
  34. unmount(){
  35. if [ -z "$1" ]; then
  36. DIR=$PWD
  37. else
  38. DIR=$1
  39. fi
  40. while mount | grep -q "$DIR"; do
  41. local LOCS
  42. LOCS=$(mount | grep "$DIR" | cut -f 3 -d ' ' | sort -r)
  43. for loc in $LOCS; do
  44. umount "$loc"
  45. done
  46. done
  47. }
  48. export -f unmount
  49. unmount_image(){
  50. sync
  51. sleep 1
  52. LOOP_DEVICE=$(losetup --list | grep "$1" | cut -f1 -d' ')
  53. if [ -n "$LOOP_DEVICE" ]; then
  54. for part in "$LOOP_DEVICE"p*; do
  55. if DIR=$(findmnt -n -o target -S "$part"); then
  56. unmount "$DIR"
  57. fi
  58. done
  59. losetup -d "$LOOP_DEVICE"
  60. fi
  61. }
  62. export -f unmount_image
  63. on_chroot() {
  64. if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/proc)"; then
  65. mount -t proc proc "${ROOTFS_DIR}/proc"
  66. fi
  67. if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/dev)"; then
  68. mount --bind /dev "${ROOTFS_DIR}/dev"
  69. fi
  70. if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/dev/pts)"; then
  71. mount --bind /dev/pts "${ROOTFS_DIR}/dev/pts"
  72. fi
  73. if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/sys)"; then
  74. mount --bind /sys "${ROOTFS_DIR}/sys"
  75. fi
  76. if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/run)"; then
  77. mount -t tmpfs tmpfs "${ROOTFS_DIR}/run"
  78. fi
  79. if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/tmp)"; then
  80. mount -t tmpfs tmpfs "${ROOTFS_DIR}/tmp"
  81. fi
  82. capsh $CAPSH_ARG "--chroot=${ROOTFS_DIR}/" -- -e "$@"
  83. }
  84. export -f on_chroot
  85. update_issue() {
  86. echo -e "Raspberry Pi reference ${IMG_DATE}\nGenerated using ${PI_GEN}, ${PI_GEN_REPO}, ${GIT_HASH}, ${1}" > "${ROOTFS_DIR}/etc/rpi-issue"
  87. }
  88. export -f update_issue
  89. ensure_next_loopdev() {
  90. local loopdev
  91. loopdev="$(losetup -f)"
  92. loopmaj="$(echo "$loopdev" | sed -E 's/.*[^0-9]*?([0-9]+)$/\1/')"
  93. [[ -b "$loopdev" ]] || mknod "$loopdev" b 7 "$loopmaj"
  94. }
  95. export -f ensure_next_loopdev