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.

build.sh 6.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #!/bin/bash -e
  2. # shellcheck disable=SC2119
  3. run_sub_stage()
  4. {
  5. log "Begin ${SUB_STAGE_DIR}"
  6. pushd "${SUB_STAGE_DIR}" > /dev/null
  7. for i in {00..99}; do
  8. if [ -f "${i}-debconf" ]; then
  9. log "Begin ${SUB_STAGE_DIR}/${i}-debconf"
  10. on_chroot << EOF
  11. debconf-set-selections <<SELEOF
  12. $(cat "${i}-debconf")
  13. SELEOF
  14. EOF
  15. log "End ${SUB_STAGE_DIR}/${i}-debconf"
  16. fi
  17. if [ -f "${i}-packages-nr" ]; then
  18. log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr"
  19. PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages-nr")"
  20. if [ -n "$PACKAGES" ]; then
  21. on_chroot << EOF
  22. apt-get install --no-install-recommends -y $PACKAGES
  23. EOF
  24. fi
  25. log "End ${SUB_STAGE_DIR}/${i}-packages-nr"
  26. fi
  27. if [ -f "${i}-packages" ]; then
  28. log "Begin ${SUB_STAGE_DIR}/${i}-packages"
  29. PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages")"
  30. if [ -n "$PACKAGES" ]; then
  31. on_chroot << EOF
  32. apt-get install -y $PACKAGES
  33. EOF
  34. fi
  35. log "End ${SUB_STAGE_DIR}/${i}-packages"
  36. fi
  37. if [ -d "${i}-patches" ]; then
  38. log "Begin ${SUB_STAGE_DIR}/${i}-patches"
  39. pushd "${STAGE_WORK_DIR}" > /dev/null
  40. if [ "${CLEAN}" = "1" ]; then
  41. rm -rf .pc
  42. rm -rf ./*-pc
  43. fi
  44. QUILT_PATCHES="${SUB_STAGE_DIR}/${i}-patches"
  45. SUB_STAGE_QUILT_PATCH_DIR="$(basename "$SUB_STAGE_DIR")-pc"
  46. mkdir -p "$SUB_STAGE_QUILT_PATCH_DIR"
  47. ln -snf "$SUB_STAGE_QUILT_PATCH_DIR" .pc
  48. quilt upgrade
  49. if [ -e "${SUB_STAGE_DIR}/${i}-patches/EDIT" ]; then
  50. echo "Dropping into bash to edit patches..."
  51. bash
  52. fi
  53. RC=0
  54. quilt push -a || RC=$?
  55. case "$RC" in
  56. 0|2)
  57. ;;
  58. *)
  59. false
  60. ;;
  61. esac
  62. popd > /dev/null
  63. log "End ${SUB_STAGE_DIR}/${i}-patches"
  64. fi
  65. if [ -x ${i}-run.sh ]; then
  66. log "Begin ${SUB_STAGE_DIR}/${i}-run.sh"
  67. ./${i}-run.sh
  68. log "End ${SUB_STAGE_DIR}/${i}-run.sh"
  69. fi
  70. if [ -f ${i}-run-chroot.sh ]; then
  71. log "Begin ${SUB_STAGE_DIR}/${i}-run-chroot.sh"
  72. on_chroot < ${i}-run-chroot.sh
  73. log "End ${SUB_STAGE_DIR}/${i}-run-chroot.sh"
  74. fi
  75. done
  76. popd > /dev/null
  77. log "End ${SUB_STAGE_DIR}"
  78. }
  79. run_stage(){
  80. log "Begin ${STAGE_DIR}"
  81. STAGE="$(basename "${STAGE_DIR}")"
  82. pushd "${STAGE_DIR}" > /dev/null
  83. unmount "${WORK_DIR}/${STAGE}"
  84. STAGE_WORK_DIR="${WORK_DIR}/${STAGE}"
  85. ROOTFS_DIR="${STAGE_WORK_DIR}"/rootfs
  86. if [ ! -f SKIP_IMAGES ]; then
  87. if [ -f "${STAGE_DIR}/EXPORT_IMAGE" ]; then
  88. EXPORT_DIRS="${EXPORT_DIRS} ${STAGE_DIR}"
  89. fi
  90. fi
  91. if [ ! -f SKIP ]; then
  92. if [ "${CLEAN}" = "1" ]; then
  93. if [ -d "${ROOTFS_DIR}" ]; then
  94. rm -rf "${ROOTFS_DIR}"
  95. fi
  96. fi
  97. if [ -x prerun.sh ]; then
  98. log "Begin ${STAGE_DIR}/prerun.sh"
  99. ./prerun.sh
  100. log "End ${STAGE_DIR}/prerun.sh"
  101. fi
  102. for SUB_STAGE_DIR in "${STAGE_DIR}"/*; do
  103. if [ -d "${SUB_STAGE_DIR}" ] &&
  104. [ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then
  105. run_sub_stage
  106. fi
  107. done
  108. fi
  109. unmount "${WORK_DIR}/${STAGE}"
  110. PREV_STAGE="${STAGE}"
  111. PREV_STAGE_DIR="${STAGE_DIR}"
  112. PREV_ROOTFS_DIR="${ROOTFS_DIR}"
  113. popd > /dev/null
  114. log "End ${STAGE_DIR}"
  115. }
  116. if [ "$(id -u)" != "0" ]; then
  117. echo "Please run as root" 1>&2
  118. exit 1
  119. fi
  120. BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  121. export BASE_DIR
  122. if [ -f config ]; then
  123. # shellcheck disable=SC1091
  124. source config
  125. fi
  126. while getopts "c:" flag
  127. do
  128. case "$flag" in
  129. c)
  130. EXTRA_CONFIG="$OPTARG"
  131. # shellcheck disable=SC1090
  132. source "$EXTRA_CONFIG"
  133. ;;
  134. *)
  135. ;;
  136. esac
  137. done
  138. export PI_GEN=${PI_GEN:-pi-gen}
  139. export PI_GEN_REPO=${PI_GEN_REPO:-https://github.com/RPi-Distro/pi-gen}
  140. if [ -z "${IMG_NAME}" ]; then
  141. echo "IMG_NAME not set" 1>&2
  142. exit 1
  143. fi
  144. export USE_QEMU="${USE_QEMU:-0}"
  145. export IMG_DATE="${IMG_DATE:-"$(date +%Y-%m-%d)"}"
  146. export IMG_FILENAME="${IMG_FILENAME:-"${IMG_DATE}-${IMG_NAME}"}"
  147. export ZIP_FILENAME="${ZIP_FILENAME:-"image_${IMG_DATE}-${IMG_NAME}"}"
  148. export SCRIPT_DIR="${BASE_DIR}/scripts"
  149. export WORK_DIR="${WORK_DIR:-"${BASE_DIR}/work/${IMG_DATE}-${IMG_NAME}"}"
  150. export DEPLOY_DIR=${DEPLOY_DIR:-"${BASE_DIR}/deploy"}
  151. export DEPLOY_ZIP="${DEPLOY_ZIP:-1}"
  152. export LOG_FILE="${WORK_DIR}/build.log"
  153. export HOSTNAME=${HOSTNAME:-raspberrypi}
  154. export FIRST_USER_NAME=${FIRST_USER_NAME:-pi}
  155. export FIRST_USER_PASS=${FIRST_USER_PASS:-raspberry}
  156. export WPA_ESSID
  157. export WPA_PASSWORD
  158. export WPA_COUNTRY
  159. export ENABLE_SSH="${ENABLE_SSH:-0}"
  160. export LOCALE_DEFAULT="${LOCALE_DEFAULT:-en_GB.UTF-8}"
  161. export KEYBOARD_KEYMAP="${KEYBOARD_KEYMAP:-gb}"
  162. export KEYBOARD_LAYOUT="${KEYBOARD_LAYOUT:-English (UK)}"
  163. export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/London}"
  164. export GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"}
  165. export CLEAN
  166. export IMG_NAME
  167. export APT_PROXY
  168. export STAGE
  169. export STAGE_DIR
  170. export STAGE_WORK_DIR
  171. export PREV_STAGE
  172. export PREV_STAGE_DIR
  173. export ROOTFS_DIR
  174. export PREV_ROOTFS_DIR
  175. export IMG_SUFFIX
  176. export NOOBS_NAME
  177. export NOOBS_DESCRIPTION
  178. export EXPORT_DIR
  179. export EXPORT_ROOTFS_DIR
  180. export QUILT_PATCHES
  181. export QUILT_NO_DIFF_INDEX=1
  182. export QUILT_NO_DIFF_TIMESTAMPS=1
  183. export QUILT_REFRESH_ARGS="-p ab"
  184. # shellcheck source=scripts/common
  185. source "${SCRIPT_DIR}/common"
  186. # shellcheck source=scripts/dependencies_check
  187. source "${SCRIPT_DIR}/dependencies_check"
  188. dependencies_check "${BASE_DIR}/depends"
  189. #check username is valid
  190. if [[ ! "$FIRST_USER_NAME" =~ ^[a-z][-a-z0-9_]*$ ]]; then
  191. echo "Invalid FIRST_USER_NAME: $FIRST_USER_NAME"
  192. exit 1
  193. fi
  194. if [[ -n "${APT_PROXY}" ]] && ! curl --silent "${APT_PROXY}" >/dev/null ; then
  195. echo "Could not reach APT_PROXY server: ${APT_PROXY}"
  196. exit 1
  197. fi
  198. mkdir -p "${WORK_DIR}"
  199. log "Begin ${BASE_DIR}"
  200. STAGE_LIST=${STAGE_LIST:-${BASE_DIR}/stage*}
  201. for STAGE_DIR in $STAGE_LIST; do
  202. STAGE_DIR=$(realpath "${STAGE_DIR}")
  203. run_stage
  204. done
  205. CLEAN=1
  206. for EXPORT_DIR in ${EXPORT_DIRS}; do
  207. STAGE_DIR=${BASE_DIR}/export-image
  208. # shellcheck source=/dev/null
  209. source "${EXPORT_DIR}/EXPORT_IMAGE"
  210. EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename "${EXPORT_DIR}")/rootfs
  211. run_stage
  212. if [ "${USE_QEMU}" != "1" ]; then
  213. if [ -e "${EXPORT_DIR}/EXPORT_NOOBS" ]; then
  214. # shellcheck source=/dev/null
  215. source "${EXPORT_DIR}/EXPORT_NOOBS"
  216. STAGE_DIR="${BASE_DIR}/export-noobs"
  217. run_stage
  218. fi
  219. fi
  220. done
  221. if [ -x ${BASE_DIR}/postrun.sh ]; then
  222. log "Begin postrun.sh"
  223. cd "${BASE_DIR}"
  224. ./postrun.sh
  225. log "End postrun.sh"
  226. fi
  227. log "End ${BASE_DIR}"