Skip to content
This repository was archived by the owner on Oct 26, 2019. It is now read-only.

Commit d474100

Browse files
committed
Merge branch 'RPi-Distro-master' into dev
2 parents 6df2631 + e8032a2 commit d474100

34 files changed

Lines changed: 261 additions & 215 deletions

File tree

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ A simple example for building Hassbian:
8989
=======
9090
* `USE_QEMU` (Default: `"0"`)
9191

92-
This enable the Qemu mode and set filesystem and image suffix if set to 1.
92+
Setting to '1' enables the QEMU mode - creating an image that can be mounted via QEMU for an emulated
93+
environment. These images include "-qemu" in the image file name.
9394

9495

9596
A simple example for building Raspbian:
@@ -117,7 +118,7 @@ The following process is followed to build images:
117118
There are a number of different files and directories which can be used to
118119
control different parts of the build process:
119120

120-
- **00-run.sh** - A unix shell script. Needs to be made executable for it to run
121+
- **00-run.sh** - A unix shell script. Needs to be made executable for it to run.
121122

122123
- **00-run-chroot.sh** - A unix shell script which will be run in the chroot
123124
of the image build directory. Needs to be made executable for it to run.
@@ -129,9 +130,12 @@ The following process is followed to build images:
129130
separated, per line.
130131

131132
- **00-packages-nr** - As 00-packages, except these will be installed using
132-
the ```--no-install-recommends -y``` parameters to apt-get
133+
the ```--no-install-recommends -y``` parameters to apt-get.
133134

134-
- **00-patches** - A directory containing patch files to be applied
135+
- **00-patches** - A directory containing patch files to be applied, using quilt.
136+
If a file named 'EDIT' is present in the directory, the build process will
137+
be interrupted with a bash session, allowing an opportunity to create/revise
138+
the patches.
135139

136140
* If the stage directory contains files called "EXPORT_NOOBS" or "EXPORT_IMAGE" then
137141
add this stage to a list of images to generate
@@ -158,6 +162,12 @@ continue:
158162
CONTINUE=1 ./build-docker.sh
159163
```
160164

165+
After successful build, the build container is by default removed. This may be undesired when making incremental changes to a customized build. To prevent the build script from remove the container add
166+
167+
```bash
168+
PRESERVE_CONTAINER=1 ./build-docker.sh
169+
```
170+
161171
There is a possibility that even when running from a docker container, the
162172
installation of `qemu-user-static` will silently fail when building the image
163173
because `binfmt-support` _must be enabled on the underlying kernel_. An easy
@@ -225,14 +235,14 @@ If you wish to build up to a specified stage (such as building up to stage 2
225235
for a lite system), place an empty file named `SKIP` in each of the `./stage`
226236
directories you wish not to include.
227237
228-
Then remove the `EXPORT*` files from `./stage4` (if building up to stage 2) or
229-
from `./stage2` (if building a minimal system).
238+
Then add an empty file named `SKIP_IMAGES` to `./stage4` (if building up to stage 2) or
239+
to `./stage2` (if building a minimal system).
230240
231241
```bash
232242
# Example for building a lite system
233243
echo "IMG_NAME='Raspbian'" > config
234244
touch ./stage3/SKIP ./stage4/SKIP ./stage5/SKIP
235-
rm stage4/EXPORT* stage5/EXPORT*
245+
touch ./stage4/SKIP_IMAGES ./stage5/SKIP_IMAGES
236246
sudo ./build.sh # or ./build-docker.sh
237247
```
238248

build-docker.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fi
2121

2222
CONTAINER_NAME=${CONTAINER_NAME:-pigen_work}
2323
CONTINUE=${CONTINUE:-0}
24+
PRESERVE_CONTAINER=${PRESERVE_CONTAINER:-0}
2425

2526
if [ "$*" != "" ] || [ -z "${IMG_NAME}" ]; then
2627
if [ -z "${IMG_NAME}" ]; then
@@ -33,6 +34,7 @@ Usage:
3334
Optional environment arguments: ( =<default> )
3435
CONTAINER_NAME=pigen_work set a name for the build container
3536
CONTINUE=1 continue from a previously started container
37+
PRESERVE_CONTAINER=1 keep build container even on successful build
3638
EOF
3739
exit 1
3840
fi
@@ -55,7 +57,7 @@ if [ "$CONTAINER_EXISTS" != "" ]; then
5557
trap "echo 'got CTRL+C... please wait 5s'; $DOCKER stop -t 5 ${CONTAINER_NAME}_cont" SIGINT SIGTERM
5658
time $DOCKER run --rm --privileged \
5759
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
58-
-e IMG_NAME=${IMG_NAME}\
60+
-e IMG_NAME="${IMG_NAME}"\
5961
pi-gen \
6062
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
6163
cd /pi-gen; ./build.sh;
@@ -64,7 +66,7 @@ if [ "$CONTAINER_EXISTS" != "" ]; then
6466
else
6567
trap "echo 'got CTRL+C... please wait 5s'; $DOCKER stop -t 5 ${CONTAINER_NAME}" SIGINT SIGTERM
6668
time $DOCKER run --name "${CONTAINER_NAME}" --privileged \
67-
-e IMG_NAME=${IMG_NAME}\
69+
-e IMG_NAME="${IMG_NAME}"\
6870
"${config_file[@]}" \
6971
pi-gen \
7072
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
@@ -75,6 +77,10 @@ fi
7577
echo "copying results from deploy/"
7678
$DOCKER cp "${CONTAINER_NAME}":/pi-gen/deploy .
7779
ls -lah deploy
78-
$DOCKER rm -v $CONTAINER_NAME
80+
81+
# cleanup
82+
if [ "$PRESERVE_CONTAINER" != "1" ]; then
83+
$DOCKER rm -v $CONTAINER_NAME
84+
fi
7985

8086
echo "Done! Your image(s) should be in deploy/"

build.sh

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
11
#!/bin/bash -e
2-
2+
# shellcheck disable=SC2119,SC1091
33
run_sub_stage()
44
{
55
log "Begin ${SUB_STAGE_DIR}"
6-
pushd ${SUB_STAGE_DIR} > /dev/null
6+
pushd "${SUB_STAGE_DIR}" > /dev/null
77
for i in {00..99}; do
8-
if [ -f ${i}-debconf ]; then
8+
if [ -f "${i}-debconf" ]; then
99
log "Begin ${SUB_STAGE_DIR}/${i}-debconf"
1010
on_chroot << EOF
1111
debconf-set-selections <<SELEOF
12-
`cat ${i}-debconf`
12+
$(cat "${i}-debconf")
1313
SELEOF
1414
EOF
15+
1516
log "End ${SUB_STAGE_DIR}/${i}-debconf"
1617
fi
17-
if [ -f ${i}-packages-nr ]; then
18+
if [ -f "${i}-packages-nr" ]; then
1819
log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr"
19-
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < ${i}-packages-nr)"
20+
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages-nr")"
2021
if [ -n "$PACKAGES" ]; then
2122
on_chroot << EOF
2223
apt-get install --no-install-recommends -y $PACKAGES
2324
EOF
2425
fi
2526
log "End ${SUB_STAGE_DIR}/${i}-packages-nr"
2627
fi
27-
if [ -f ${i}-packages ]; then
28+
if [ -f "${i}-packages" ]; then
2829
log "Begin ${SUB_STAGE_DIR}/${i}-packages"
29-
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < ${i}-packages)"
30+
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages")"
3031
if [ -n "$PACKAGES" ]; then
3132
on_chroot << EOF
3233
apt-get install -y $PACKAGES
3334
EOF
3435
fi
3536
log "End ${SUB_STAGE_DIR}/${i}-packages"
3637
fi
37-
if [ -d ${i}-patches ]; then
38+
if [ -d "${i}-patches" ]; then
3839
log "Begin ${SUB_STAGE_DIR}/${i}-patches"
39-
pushd ${STAGE_WORK_DIR} > /dev/null
40+
pushd "${STAGE_WORK_DIR}" > /dev/null
4041
if [ "${CLEAN}" = "1" ]; then
4142
rm -rf .pc
42-
rm -rf *-pc
43+
rm -rf ./*-pc
4344
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-
if [ -e ${SUB_STAGE_DIR}/${i}-patches/EDIT ]; then
45+
QUILT_PATCHES="${SUB_STAGE_DIR}/${i}-patches"
46+
SUB_STAGE_QUILT_PATCH_DIR="$(basename "$SUB_STAGE_DIR")-pc"
47+
mkdir -p "$SUB_STAGE_QUILT_PATCH_DIR"
48+
ln -snf "$SUB_STAGE_QUILT_PATCH_DIR" .pc
49+
if [ -e "${SUB_STAGE_DIR}/${i}-patches/EDIT" ]; then
4950
echo "Dropping into bash to edit patches..."
5051
bash
5152
fi
@@ -80,20 +81,20 @@ EOF
8081

8182
run_stage(){
8283
log "Begin ${STAGE_DIR}"
83-
STAGE=$(basename ${STAGE_DIR})
84-
pushd ${STAGE_DIR} > /dev/null
85-
unmount ${WORK_DIR}/${STAGE}
86-
STAGE_WORK_DIR=${WORK_DIR}/${STAGE}
87-
ROOTFS_DIR=${STAGE_WORK_DIR}/rootfs
84+
STAGE="$(basename "${STAGE_DIR}")"
85+
pushd "${STAGE_DIR}" > /dev/null
86+
unmount "${WORK_DIR}/${STAGE}"
87+
STAGE_WORK_DIR="${WORK_DIR}/${STAGE}"
88+
ROOTFS_DIR="${STAGE_WORK_DIR}"/rootfs
8889
if [ ! -f SKIP_IMAGES ]; then
89-
if [ -f ${STAGE_DIR}/EXPORT_IMAGE ]; then
90+
if [ -f "${STAGE_DIR}/EXPORT_IMAGE" ]; then
9091
EXPORT_DIRS="${EXPORT_DIRS} ${STAGE_DIR}"
9192
fi
9293
fi
9394
if [ ! -f SKIP ]; then
9495
if [ "${CLEAN}" = "1" ]; then
95-
if [ -d ${ROOTFS_DIR} ]; then
96-
rm -rf ${ROOTFS_DIR}
96+
if [ -d "${ROOTFS_DIR}" ]; then
97+
rm -rf "${ROOTFS_DIR}"
9798
fi
9899
fi
99100
if [ -x prerun.sh ]; then
@@ -102,16 +103,16 @@ run_stage(){
102103
log "End ${STAGE_DIR}/prerun.sh"
103104
fi
104105
for SUB_STAGE_DIR in ${STAGE_DIR}/*; do
105-
if [ -d ${SUB_STAGE_DIR} ] &&
106-
[ ! -f ${SUB_STAGE_DIR}/SKIP ]; then
106+
if [ -d "${SUB_STAGE_DIR}" ] &&
107+
[ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then
107108
run_sub_stage
108109
fi
109110
done
110111
fi
111-
unmount ${WORK_DIR}/${STAGE}
112-
PREV_STAGE=${STAGE}
113-
PREV_STAGE_DIR=${STAGE_DIR}
114-
PREV_ROOTFS_DIR=${ROOTFS_DIR}
112+
unmount "${WORK_DIR}/${STAGE}"
113+
PREV_STAGE="${STAGE}"
114+
PREV_STAGE_DIR="${STAGE_DIR}"
115+
PREV_ROOTFS_DIR="${ROOTFS_DIR}"
115116
popd > /dev/null
116117
log "End ${STAGE_DIR}"
117118
}
@@ -131,15 +132,17 @@ if [ -z "${IMG_NAME}" ]; then
131132
exit 1
132133
fi
133134

134-
export USE_QEMU=${USE_QEMU:-0}
135-
export IMG_DATE=${IMG_DATE:-"$(date +%Y-%m-%d)"}
135+
export USE_QEMU="${USE_QEMU:-0}"
136+
export IMG_DATE="${IMG_DATE:-"$(date +%Y-%m-%d)"}"
136137

137-
export BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
138+
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
138139
export SCRIPT_DIR="${BASE_DIR}/scripts"
139-
export WORK_DIR=${WORK_DIR:-"${BASE_DIR}/work/${IMG_DATE}-${IMG_NAME}"}
140+
export WORK_DIR="${WORK_DIR:-"${BASE_DIR}/work/${IMG_DATE}-${IMG_NAME}"}"
140141
export DEPLOY_DIR=${DEPLOY_DIR:-"${BASE_DIR}/deploy"}
141142
export LOG_FILE="${WORK_DIR}/build.log"
142143

144+
export BASE_DIR
145+
143146
export CLEAN
144147
export IMG_NAME
145148
export APT_PROXY
@@ -162,29 +165,33 @@ export QUILT_NO_DIFF_INDEX=1
162165
export QUILT_NO_DIFF_TIMESTAMPS=1
163166
export QUILT_REFRESH_ARGS="-p ab"
164167

165-
source ${SCRIPT_DIR}/common
166-
source ${SCRIPT_DIR}/dependencies_check
168+
# shellcheck source=scripts/common
169+
source "${SCRIPT_DIR}/common"
170+
# shellcheck source=scripts/dependencies_check
171+
source "${SCRIPT_DIR}/dependencies_check"
167172

168173

169-
dependencies_check ${BASE_DIR}/depends
174+
dependencies_check "${BASE_DIR}/depends"
170175

171-
mkdir -p ${WORK_DIR}
176+
mkdir -p "${WORK_DIR}"
172177
log "Begin ${BASE_DIR}"
173178

174-
for STAGE_DIR in ${BASE_DIR}/stage*; do
179+
for STAGE_DIR in "${BASE_DIR}/stage"*; do
175180
run_stage
176181
done
177182

178183
CLEAN=1
179184
for EXPORT_DIR in ${EXPORT_DIRS}; do
180185
STAGE_DIR=${BASE_DIR}/export-image
186+
# shellcheck source=/dev/null
181187
source "${EXPORT_DIR}/EXPORT_IMAGE"
182-
EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename ${EXPORT_DIR})/rootfs
188+
EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename "${EXPORT_DIR}")/rootfs
183189
run_stage
184190
if [ "${USE_QEMU}" != "1" ]; then
185-
if [ -e ${EXPORT_DIR}/EXPORT_NOOBS ]; then
186-
source ${EXPORT_DIR}/EXPORT_NOOBS
187-
STAGE_DIR=${BASE_DIR}/export-noobs
191+
if [ -e "${EXPORT_DIR}/EXPORT_NOOBS" ]; then
192+
# shellcheck source=/dev/null
193+
source "${EXPORT_DIR}/EXPORT_NOOBS"
194+
STAGE_DIR="${BASE_DIR}/export-noobs"
188195
run_stage
189196
fi
190197
fi
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash -e
22

3-
if [ ! -x ${ROOTFS_DIR}/usr/bin/qemu-arm-static ]; then
4-
cp /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/
3+
if [ ! -x "${ROOTFS_DIR}/usr/bin/qemu-arm-static" ]; then
4+
cp /usr/bin/qemu-arm-static "${ROOTFS_DIR}/usr/bin/"
55
fi

export-image/02-network/01-run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash -e
22

3-
install -m 644 files/resolv.conf ${ROOTFS_DIR}/etc/
3+
install -m 644 files/resolv.conf "${ROOTFS_DIR}/etc/"

export-image/03-set-partuuid/00-run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
IMG_FILE="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.img"
44

5-
IMGID="$(dd if=${IMG_FILE} skip=440 bs=1 count=4 2>/dev/null | xxd -e | cut -f 2 -d' ')"
5+
IMGID="$(dd if="${IMG_FILE}" skip=440 bs=1 count=4 2>/dev/null | xxd -e | cut -f 2 -d' ')"
66

77
BOOT_PARTUUID="${IMGID}-01"
88
ROOT_PARTUUID="${IMGID}-02"
99

10-
sed -i "s/BOOTDEV/PARTUUID=${BOOT_PARTUUID}/" ${ROOTFS_DIR}/etc/fstab
11-
sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" ${ROOTFS_DIR}/etc/fstab
10+
sed -i "s/BOOTDEV/PARTUUID=${BOOT_PARTUUID}/" "${ROOTFS_DIR}/etc/fstab"
11+
sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" "${ROOTFS_DIR}/etc/fstab"
1212

13-
sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" ${ROOTFS_DIR}/boot/cmdline.txt
13+
sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" "${ROOTFS_DIR}/boot/cmdline.txt"

0 commit comments

Comments
 (0)