Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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