|
| 1 | +#!/usr/bin/bash |
| 2 | + |
| 3 | +function error() |
| 4 | +{ |
| 5 | + MSG="$1" |
| 6 | + echo -e "\e[31;40m[ERROR]\e[0m $MSG" |
| 7 | +} |
| 8 | + |
| 9 | +function info() |
| 10 | +{ |
| 11 | + MSG="$1" |
| 12 | + echo -e "\e[32;40m[INFO]\e[0m $MSG" |
| 13 | +} |
| 14 | + |
| 15 | +function clean() |
| 16 | +{ |
| 17 | + sudo rm -fr build images streams focal.arm64.yaml resolute.arm64.yaml focal.amd64.yaml resolute.amd64.yaml |
| 18 | +} |
| 19 | + |
| 20 | +function usage() |
| 21 | +{ |
| 22 | + echo "Usage: $0 image" |
| 23 | + exit 0 |
| 24 | +} |
| 25 | + |
| 26 | + |
| 27 | +function build_image() |
| 28 | +{ |
| 29 | + TARGET_CODE=$1 |
| 30 | + TARGET_VARIANT=$2 |
| 31 | + TARGET_ARCH=$3 |
| 32 | + OUTPUT_DIR="build/${TARGET_CODE}-${TARGET_ARCH}" |
| 33 | + mkdir -p build |
| 34 | + sudo distrobuilder build-incus "${TARGET_CODE}.${TARGET_ARCH}.yaml" "$OUTPUT_DIR" |
| 35 | + printf "ubuntu\n${TARGET_CODE}\n${TARGET_VARIANT}\n${TARGET_ARCH}\n\n" | sudo incus-simplestreams generate-metadata "$OUTPUT_DIR/incus.tar.xz" |
| 36 | +} |
| 37 | + |
| 38 | +function build_all_images() |
| 39 | +{ |
| 40 | + for code in focal resolute; do |
| 41 | + for arch in amd64 arm64; do |
| 42 | + if [ -f "build/${code}-${arch}/rootfs.squashfs" ] && [ -f "build/${code}-${arch}/incus.tar.xz" ]; then |
| 43 | + info "skip ${code} ${arch}" |
| 44 | + continue |
| 45 | + fi |
| 46 | + info "generate ${code}.${arch}.yaml" |
| 47 | + rm -f ${code}.${arch}.yaml |
| 48 | + case $arch in |
| 49 | + arm64) |
| 50 | + sed -e "s/architecture: amd64/architecture: ${arch}/g" \ |
| 51 | + -e "s/focal-amd64/${code}-arm64/g" \ |
| 52 | + -e "s/release: focal/release: ${code}/g" \ |
| 53 | + -e 's,url: http://ftp.riken.jp/Linux/ubuntu,url: https://linux.yz.yamagata-u.ac.jp/pub/linux/ubuntu-ports/,' \ |
| 54 | + template.yaml > ${code}.${arch}.yaml |
| 55 | + ;; |
| 56 | + amd64) |
| 57 | + sed -e "s/architecture: amd64/architecture: ${arch}/g" \ |
| 58 | + -e "s/release: focal/release: ${code}/g" \ |
| 59 | + -e "s/focal-amd64/${code}-amd64/g" \ |
| 60 | + template.yaml > ${code}.${arch}.yaml |
| 61 | + ;; |
| 62 | + esac |
| 63 | + case $code in |
| 64 | + focal) |
| 65 | + build_image ${code} 20.04 ${arch} |
| 66 | + ;; |
| 67 | + resolute) |
| 68 | + build_image ${code} 26.04 ${arch} |
| 69 | + ;; |
| 70 | + esac |
| 71 | + done |
| 72 | + done |
| 73 | +} |
| 74 | + |
| 75 | +case $1 in |
| 76 | + clean) |
| 77 | + clean |
| 78 | + ;; |
| 79 | + image) |
| 80 | + build_all_images |
| 81 | + ;; |
| 82 | + *) |
| 83 | + usage |
| 84 | + ;; |
| 85 | +esac |
0 commit comments