This repository was archived by the owner on Sep 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·132 lines (114 loc) · 3.32 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·132 lines (114 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh -
#
# Copyright 2023 OK Ryoko
# SPDX-License-Identifier: BSD-2-Clause
#
# SYNOPSIS:
#
# ./build.sh [-a ARCH] [-h] [-k] [-r REPO] VERSION
#
# DESCRIPTION:
#
# Create a Chimera Linux container image in local storage, printing the ID of
# the new image to standard output
#
# OPTIONS:
#
# -a ARCH Use the provided architecture instead of the automatically detected
# architecture. Supported values are aarch64, ppc64, ppc64le, riscv64
# and x86_64.
#
# -h Print synopsis to standard output and exit
#
# -k Keep the working container
#
# -r REPO Use this repository name instead of the default (localhost/chimera)
#
# -u Fetch the rootfs tarball checksums unconditionally
#
# NOTES:
#
# Requires an Internet connection and depends on the availability of the curl
# and Buildah programs
#
# Creates a directory named 'dist' in the working directory in which download
# artifacts will be stored for future runs
set -o errexit
set -o nounset
usage() {
printf 'usage: %s [-a ARCHITECTURE] [-h] [-k] [-r REPOSITORY] [-u] VERSION\n' "$0"
}
while getopts 'a:hkr:u' opt; do
case "${opt}" in
a)
arch="${OPTARG}"
;;
h)
usage
exit 0
;;
k)
keep='1'
;;
r)
repository="${OPTARG}"
;;
u)
update='1'
;;
?)
usage
exit 2
;;
esac
done
shift $((OPTIND-1))
readonly chimera_version="${1:?$(usage && exit 2)}"
readonly arch="${arch:-"$(uname -m)"}"
readonly keep="${keep:-0}"
readonly repository="${repository:-localhost/chimera}"
readonly update="${update:-0}"
mkdir -p 'dist'
cd 'dist'
readonly url_base="https://repo.chimera-linux.org/live/${chimera_version}"
readonly checksums='sha256sums.txt'
readonly tarball="chimera-linux-${arch}-ROOTFS-${chimera_version}-bootstrap.tar.gz"
if ! [ -f "${checksums}" ] || ! [ -f "${tarball}" ] || [ "${update}" = '1' ]; then
curl --show-error --silent "${url_base}/${checksums}" | grep 'bootstrap' >> "${checksums}"
sort -k 2 -u "${checksums}" > "${checksums}-"
mv -f "${checksums}-" "${checksums}"
fi
if ! [ -f "${tarball}" ]; then
curl --remote-name --show-error --silent "${url_base}/${tarball}"
fi
sha256sum --check --ignore-missing --status "${checksums}"
export BUILDAH_FORMAT='oci'
ctr="$(buildah from scratch)"
# shellcheck disable=SC2317
defer() {
if [ "${keep}" = '0' ]; then
buildah rm "${ctr}" > '/dev/null'
fi
}
trap defer EXIT
buildah add --quiet "${ctr}" "${tarball}" '/'
readonly ref="${repository}:${chimera_version}-${arch}"
readonly label_documentation='https://chimera-linux.org/docs/'
readonly label_url='https://chimera-linux.org/'
readonly label_title='Chimera Linux Base Container'
readonly label_description="Image containing a bootstrapped environment for containers based on Chimera Linux ${chimera_version}"
buildah config \
--annotation=- \
--arch "${arch}" \
--cmd '/bin/sh' \
--label "org.opencontainers.image.created=$(date --rfc-3339=ns --utc)" \
--label "org.opencontainers.image.url=${label_url}" \
--label "org.opencontainers.image.documentation=${label_documentation}" \
--label "org.opencontainers.image.version=${chimera_version}" \
--label "org.opencontainers.image.ref.name=${ref}" \
--label "org.opencontainers.image.title=${label_title}" \
--label "org.opencontainers.image.description=${label_description}" \
--os 'linux' \
"${ctr}"
buildah commit --quiet "${ctr}" "${ref}"
exit 0