Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 RELEASE=${RELEASE:-buster}
  169. export WPA_ESSID
  170. export WPA_PASSWORD
  171. export WPA_COUNTRY
  172. export ENABLE_SSH="${ENABLE_SSH:-0}"
  173. export LOCALE_DEFAULT="${LOCALE_DEFAULT:-en_GB.UTF-8}"
  174. export KEYBOARD_KEYMAP="${KEYBOARD_KEYMAP:-gb}"
  175. export KEYBOARD_LAYOUT="${KEYBOARD_LAYOUT:-English (UK)}"
  176. export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/London}"
  177. export GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"}
  178. export CLEAN
  179. export IMG_NAME
  180. export APT_PROXY
  181. export STAGE
  182. export STAGE_DIR
  183. export STAGE_WORK_DIR
  184. export PREV_STAGE
  185. export PREV_STAGE_DIR
  186. export ROOTFS_DIR
  187. export PREV_ROOTFS_DIR
  188. export IMG_SUFFIX
  189. export NOOBS_NAME
  190. export NOOBS_DESCRIPTION
  191. export EXPORT_DIR
  192. export EXPORT_ROOTFS_DIR
  193. export QUILT_PATCHES
  194. export QUILT_NO_DIFF_INDEX=1
  195. export QUILT_NO_DIFF_TIMESTAMPS=1
  196. export QUILT_REFRESH_ARGS="-p ab"
  197. # shellcheck source=scripts/common
  198. source "${SCRIPT_DIR}/common"
  199. # shellcheck source=scripts/dependencies_check
  200. source "${SCRIPT_DIR}/dependencies_check"
  201. dependencies_check "${BASE_DIR}/depends"
  202. #check username is valid
  203. if [[ ! "$FIRST_USER_NAME" =~ ^[a-z][-a-z0-9_]*$ ]]; then
  204. echo "Invalid FIRST_USER_NAME: $FIRST_USER_NAME"
  205. exit 1
  206. fi
  207. if [[ -n "${APT_PROXY}" ]] && ! curl --silent "${APT_PROXY}" >/dev/null ; then
  208. echo "Could not reach APT_PROXY server: ${APT_PROXY}"
  209. exit 1
  210. fi
  211. if [[ -n "${WPA_PASSWORD}" && ${#WPA_PASSWORD} -lt 8 || ${#WPA_PASSWORD} -gt 63 ]] ; then
  212. echo "WPA_PASSWORD" must be between 8 and 63 characters
  213. exit 1
  214. fi
  215. mkdir -p "${WORK_DIR}"
  216. log "Begin ${BASE_DIR}"
  217. STAGE_LIST=${STAGE_LIST:-${BASE_DIR}/stage*}
  218. for STAGE_DIR in $STAGE_LIST; do
  219. STAGE_DIR=$(realpath "${STAGE_DIR}")
  220. run_stage
  221. done
  222. CLEAN=1
  223. for EXPORT_DIR in ${EXPORT_DIRS}; do
  224. STAGE_DIR=${BASE_DIR}/export-image
  225. # shellcheck source=/dev/null
  226. source "${EXPORT_DIR}/EXPORT_IMAGE"
  227. EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename "${EXPORT_DIR}")/rootfs
  228. run_stage
  229. if [ "${USE_QEMU}" != "1" ]; then
  230. if [ -e "${EXPORT_DIR}/EXPORT_NOOBS" ]; then
  231. # shellcheck source=/dev/null
  232. source "${EXPORT_DIR}/EXPORT_NOOBS"
  233. STAGE_DIR="${BASE_DIR}/export-noobs"
  234. run_stage
  235. fi
  236. fi
  237. done
  238. if [ -x ${BASE_DIR}/postrun.sh ]; then
  239. log "Begin postrun.sh"
  240. cd "${BASE_DIR}"
  241. ./postrun.sh
  242. log "End postrun.sh"
  243. fi
  244. log "End ${BASE_DIR}"