69 lines
1.4 KiB
Bash
69 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
log() {
|
|
printf '[make-rootfs] %s\n' "$*"
|
|
}
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Usage: ./make-rootfs.sh [--size <size>] [--base-rootfs <path>]
|
|
|
|
Builds rootfs-docker.ext4 using customize.sh. If --base-rootfs is omitted,
|
|
the first existing file is used:
|
|
./rootfs.ext4
|
|
./ubuntu-noble-rootfs/rootfs.ext4
|
|
./ubuntu-lts/rootfs.ext4
|
|
EOF
|
|
}
|
|
|
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
OUT_ROOTFS="$DIR/rootfs-docker.ext4"
|
|
SIZE_SPEC="6G"
|
|
BASE_ROOTFS=""
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--size)
|
|
SIZE_SPEC="${2:-}"
|
|
shift 2
|
|
;;
|
|
--base-rootfs)
|
|
BASE_ROOTFS="${2:-}"
|
|
shift 2
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
log "unknown option: $1"
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -f "$OUT_ROOTFS" ]]; then
|
|
log "already exists: $OUT_ROOTFS"
|
|
exit 0
|
|
fi
|
|
|
|
if [[ -z "$BASE_ROOTFS" ]]; then
|
|
if [[ -f "$DIR/rootfs.ext4" ]]; then
|
|
BASE_ROOTFS="$DIR/rootfs.ext4"
|
|
elif [[ -f "$DIR/ubuntu-noble-rootfs/rootfs.ext4" ]]; then
|
|
BASE_ROOTFS="$DIR/ubuntu-noble-rootfs/rootfs.ext4"
|
|
elif [[ -f "$DIR/ubuntu-lts/rootfs.ext4" ]]; then
|
|
BASE_ROOTFS="$DIR/ubuntu-lts/rootfs.ext4"
|
|
else
|
|
log "no base rootfs found"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
log "building $OUT_ROOTFS from $BASE_ROOTFS"
|
|
exec "$DIR/customize.sh" "$BASE_ROOTFS" \
|
|
--out "$OUT_ROOTFS" \
|
|
--size "$SIZE_SPEC" \
|
|
--docker
|