* Added Docker support - replaced necessity for devicemapper (through kpartx) by using parted and losetup with offsets - added Dockerfile - added dependency for parted and grep - added hints to README.md - common: loop through unmounts, fix shellcheck warnings * stage2: use debconf instead of console-setup patch. Fixes #41pull/46/head
@ -0,0 +1,3 @@ | |||
output/ | |||
work/ | |||
deploy/ |
@ -0,0 +1,12 @@ | |||
FROM debian:jessie | |||
RUN apt-get -y update && \ | |||
apt-get -y install \ | |||
git vim parted \ | |||
quilt realpath qemu-user-static debootstrap zerofree pxz zip dosfstools \ | |||
bsdtar libcap2-bin rsync grep \ | |||
&& rm -rf /var/lib/apt/lists/* | |||
COPY . /pi-gen/ | |||
VOLUME [ "/pi-gen/work", "/pi-gen/deploy"] |
@ -0,0 +1,73 @@ | |||
#!/bin/bash -e | |||
DOCKER="docker" | |||
set +e | |||
$DOCKER ps >/dev/null 2>&1 | |||
if [ $? != 0 ]; then | |||
DOCKER="sudo docker" | |||
fi | |||
if ! $DOCKER ps >/dev/null; then | |||
echo "error connecting to docker:" | |||
$DOCKER ps | |||
exit 1 | |||
fi | |||
set -e | |||
config_mount= | |||
if [ -f config ]; then | |||
config_mount="-v $(pwd)/config:/pi-gen/config:ro" | |||
source config | |||
fi | |||
CONTAINER_NAME=${CONTAINER_NAME:-pigen_work} | |||
CONTINUE=${CONTINUE:-0} | |||
if [ "$*" != "" ] || [ -z "${IMG_NAME}" ]; then | |||
if [ -z "${IMG_NAME}" ]; then | |||
echo "IMG_NAME not set in 'build'" 1>&2 | |||
echo 1>&2 | |||
fi | |||
cat >&2 <<EOF | |||
Usage: | |||
build-docker.sh [options] | |||
Optional environment arguments: ( =<default> ) | |||
CONTAINER_NAME=pigen_work set a name for the build container | |||
CONTINUE=0 continue from a previously started container | |||
EOF | |||
exit 1 | |||
fi | |||
CONTAINER_EXISTS=$($DOCKER ps -a --filter name="$CONTAINER_NAME" -q) | |||
CONTAINER_RUNNING=$($DOCKER ps --filter name="$CONTAINER_NAME" -q) | |||
if [ "$CONTAINER_RUNNING" != "" ]; then | |||
echo "The build is already running in container $CONTAINER_NAME. Aborting." | |||
exit 1 | |||
fi | |||
if [ "$CONTAINER_EXISTS" != "" ] && [ "$CONTINUE" != "1" ]; then | |||
echo "Container $CONTAINER_NAME already exists and you did not specify CONTINUE=1. Aborting." | |||
echo "You can delete the existing container like this:" | |||
echo " docker rm $CONTAINER_NAME" | |||
exit 1 | |||
fi | |||
$DOCKER build -t pi-gen . | |||
if [ "$CONTAINER_EXISTS" != "" ]; then | |||
trap "echo 'got CTRL+C... please wait 5s';docker stop -t 5 ${CONTAINER_NAME}_cont" SIGINT SIGTERM | |||
time $DOCKER run --rm --privileged \ | |||
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \ | |||
pi-gen \ | |||
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static && | |||
cd /pi-gen; ./build.sh; | |||
rsync -av work/*/build.log deploy/" & | |||
wait | |||
else | |||
trap "echo 'got CTRL+C... please wait 5s'; docker stop -t 5 ${CONTAINER_NAME}" SIGINT SIGTERM | |||
$DOCKER run --name "${CONTAINER_NAME}" --privileged \ | |||
-v $(pwd)/deploy:/pi-gen/deploy \ | |||
${config_mount} \ | |||
pi-gen \ | |||
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static && | |||
cd /pi-gen; ./build.sh && | |||
rsync -av work/*/build.log deploy/" & | |||
wait | |||
fi | |||
echo "Done! Your image(s) should be in deploy/" |
@ -1,8 +1,12 @@ | |||
quilt | |||
parted | |||
realpath | |||
qemu-arm-static:qemu-user-static | |||
debootstrap | |||
kpartx zerofree | |||
zerofree | |||
pxz zip | |||
mkdosfs:dosfstools | |||
capsh:libcap2-bin | |||
bsdtar | |||
grep | |||
rsync |
@ -1,10 +1,11 @@ | |||
log (){ | |||
date +"[%T] [email protected]" | tee -a ${LOG_FILE} | |||
date +"[%T] [email protected]" | tee -a "${LOG_FILE}" | |||
} | |||
export -f log | |||
bootstrap(){ | |||
local ARCH=$(dpkg --print-architecture) | |||
local ARCH | |||
ARCH=$(dpkg --print-architecture) | |||
export http_proxy=${APT_PROXY} | |||
@ -22,12 +23,12 @@ bootstrap(){ | |||
export -f bootstrap | |||
copy_previous(){ | |||
if [ ! -d ${PREV_ROOTFS_DIR} ]; then | |||
if [ ! -d "${PREV_ROOTFS_DIR}" ]; then | |||
echo "Previous stage rootfs not found" | |||
false | |||
fi | |||
mkdir -p ${ROOTFS_DIR} | |||
rsync -aHAXx ${PREV_ROOTFS_DIR}/ ${ROOTFS_DIR}/ | |||
mkdir -p "${ROOTFS_DIR}" | |||
rsync -aHAXx "${PREV_ROOTFS_DIR}/" "${ROOTFS_DIR}/" | |||
} | |||
export -f copy_previous | |||
@ -38,10 +39,11 @@ unmount(){ | |||
DIR=$1 | |||
fi | |||
while mount | grep -q $DIR; do | |||
local LOCS=`mount | grep $DIR | cut -f 3 -d ' ' | sort -r` | |||
while mount | grep -q "$DIR"; do | |||
local LOCS | |||
LOCS=$(mount | grep "$DIR" | cut -f 3 -d ' ' | sort -r) | |||
for loc in $LOCS; do | |||
umount $loc | |||
umount "$loc" | |||
done | |||
done | |||
} | |||
@ -50,42 +52,47 @@ export -f unmount | |||
unmount_image(){ | |||
sync | |||
sleep 1 | |||
local LOOP_DEV=$(losetup -j ${1} | cut -f1 -d':') | |||
if [ -n "${LOOP_DEV}" ]; then | |||
local MOUNTED_DIR=$(mount | grep $(basename ${LOOP_DEV}) | head -n 1 | cut -f 3 -d ' ') | |||
if [ -n "${MOUNTED_DIR}" ]; then | |||
unmount $(dirname ${MOUNTED_DIR}) | |||
local LOOP_DEVICES | |||
LOOP_DEVICES=$(losetup -j "${1}" | cut -f1 -d':') | |||
for LOOP_DEV in ${LOOP_DEVICES}; do | |||
if [ -n "${LOOP_DEV}" ]; then | |||
local MOUNTED_DIR | |||
MOUNTED_DIR=$(mount | grep "$(basename "${LOOP_DEV}")" | head -n 1 | cut -f 3 -d ' ') | |||
if [ -n "${MOUNTED_DIR}" ] && [ "${MOUNTED_DIR}" != "/" ]; then | |||
unmount "$(dirname "${MOUNTED_DIR}")" | |||
fi | |||
sleep 1 | |||
losetup -d "${LOOP_DEV}" | |||
fi | |||
sleep 1 | |||
kpartx -ds ${LOOP_DEV} | |||
losetup -d ${LOOP_DEV} | |||
fi | |||
done | |||
} | |||
export -f unmount_image | |||
on_chroot() { | |||
if ! mount | grep -q `realpath ${ROOTFS_DIR}/proc`; then | |||
mount -t proc proc ${ROOTFS_DIR}/proc | |||
if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/proc)"; then | |||
mount -t proc proc "${ROOTFS_DIR}/proc" | |||
fi | |||
if ! mount | grep -q `realpath ${ROOTFS_DIR}/dev`; then | |||
mount --bind /dev ${ROOTFS_DIR}/dev | |||
if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/dev)"; then | |||
mount --bind /dev "${ROOTFS_DIR}/dev" | |||
fi | |||
if ! mount | grep -q `realpath ${ROOTFS_DIR}/dev/pts`; then | |||
mount --bind /dev/pts ${ROOTFS_DIR}/dev/pts | |||
if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/dev/pts)"; then | |||
mount --bind /dev/pts "${ROOTFS_DIR}/dev/pts" | |||
fi | |||
if ! mount | grep -q `realpath ${ROOTFS_DIR}/sys`; then | |||
mount --bind /sys ${ROOTFS_DIR}/sys | |||
if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/sys)"; then | |||
mount --bind /sys "${ROOTFS_DIR}/sys" | |||
fi | |||
capsh --drop=cap_setfcap --chroot=${ROOTFS_DIR}/ -- "[email protected]" | |||
capsh --drop=cap_setfcap "--chroot=${ROOTFS_DIR}/" -- "[email protected]" | |||
} | |||
export -f on_chroot | |||
update_issue() { | |||
local GIT_HASH=$(git rev-parse HEAD) | |||
echo -e "Raspberry Pi reference ${IMG_DATE}\nGenerated using pi-gen, https://github.com/RPi-Distro/pi-gen, ${GIT_HASH}, ${1}" > ${ROOTFS_DIR}/etc/rpi-issue | |||
local GIT_HASH | |||
GIT_HASH=$(git rev-parse HEAD) | |||
echo -e "Raspberry Pi reference ${IMG_DATE}\nGenerated using pi-gen, https://github.com/RPi-Distro/pi-gen, ${GIT_HASH}, ${1}" > "${ROOTFS_DIR}/etc/rpi-issue" | |||
} | |||
export -f update_issue | |||
@ -1,17 +0,0 @@ | |||
Index: jessie-stage2/rootfs/etc/default/console-setup | |||
=================================================================== | |||
--- jessie-stage2.orig/rootfs/etc/default/console-setup | |||
+++ jessie-stage2/rootfs/etc/default/console-setup | |||
@@ -6,9 +6,9 @@ ACTIVE_CONSOLES="/dev/tty[1-6]" | |||
CHARMAP="UTF-8" | |||
-CODESET="Lat15" | |||
-FONTFACE="Fixed" | |||
-FONTSIZE="8x16" | |||
+CODESET="guess" | |||
+FONTFACE="" | |||
+FONTSIZE="" | |||
VIDEOMODE= | |||
@ -1,6 +1,5 @@ | |||
01-useradd.diff | |||
02-swap.diff | |||
03-console-setup.diff | |||
04-inputrc.diff | |||
05-path.diff | |||
06-rc_local.diff | |||