blob: 87d1474ab7b5987d4ec5110e188ee41974287879 (
plain)
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
|
#!/bin/bash
set -euo pipefail
cleanup() {
if [[ -n "${WORKDIR:-}" && -d "${WORKDIR:-}" ]]; then
rm -rf "${WORKDIR}"
fi
}
if [[ "$#" -ne 1 ]]; then
echo "Usage: $0 <path-to-iso>"
exit 2
fi
ISO=$1
if [[ ! -f "$ISO" ]]; then
echo "E: ISO file not found: $ISO"
exit 2
fi
# ensure clean working directory
cleanup
if ! command -v xorriso >/dev/null 2>&1; then
echo "E: missing dependency: xorriso"
echo " Install xorriso (recommended) or run inside the vyos-build container."
exit 2
fi
if ! command -v unsquashfs >/dev/null 2>&1; then
echo "E: missing dependency: unsquashfs"
echo " Install squashfs-tools or run inside the vyos-build container."
exit 2
fi
if ! command -v jq >/dev/null 2>&1; then
echo "E: missing dependency: jq"
echo " Install jq or run inside the vyos-build container."
exit 2
fi
WORKDIR="$(mktemp -d -t iso-to-oci.XXXXXXXXXX)"
trap cleanup EXIT
ROOTFS="${WORKDIR}/iso"
UNSQUASHFS="${WORKDIR}/unsquashfs"
mkdir -p "${ROOTFS}/live" "${UNSQUASHFS}"
echo "I: extracting ISO metadata"
xorriso -osirrox on -indev "${ISO}" -extract /version.json "${ROOTFS}/version.json" >/dev/null 2>&1
echo "I: extracting squashfs image"
xorriso -osirrox on -indev "${ISO}" -extract /live/filesystem.squashfs "${ROOTFS}/live/filesystem.squashfs" >/dev/null 2>&1
# create directory, unpack squashfs filesystem, get ISO version
echo "I: extracting squashfs content"
unsquashfs -follow -dest "${UNSQUASHFS}/" "${ROOTFS}/live/filesystem.squashfs" >/dev/null 2>&1
VERSION="$(jq --raw-output .version "${ROOTFS}/version.json")"
# fix locales for correct system configuration loading
sed -i 's/^LANG=.*$/LANG=C.UTF-8/' "${UNSQUASHFS}/etc/default/locale"
# optional step: Decrease docker image size by deleting not necessary files for container
rm -rf "${UNSQUASHFS}/boot"
rm -rf "${UNSQUASHFS}/lib/firmware/"
rm -rf "${UNSQUASHFS}/usr/lib/x86_64-linux-gnu/libwireshark.so*"
rm -rf "${UNSQUASHFS}/lib/modules/*-vyos"
rm -rf "${UNSQUASHFS}/root/.gnupg"
# delete features not supported in container - only remove the node.def files,
# this is sufficient to not make the feature pop up on the CLI
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/container"
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/console"
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/option/kernel"
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/option/startup-beep"
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/option/root-partition-auto-resize"
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/option/reboot-on-panic"
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/option/performance"
# create a symbolic link to the configuration
ln -s /opt/vyatta/etc/config "${UNSQUASHFS}/config"
# create docker image
echo "I: generate OCI container image vyos-$VERSION.tar"
tar -C "${UNSQUASHFS}" -c . -f "vyos-${VERSION}.tar"
echo "I: to import the previously generated OCI image to your local images run:"
echo ""
echo " docker import vyos-$VERSION.tar vyos:$VERSION --change 'CMD ["/sbin/init"]'"
echo ""
cleanup
|