Você não pode selecionar mais de 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.
 
 
 
 
 

275 linhas
6.4 KiB

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