You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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