-
Notifications
You must be signed in to change notification settings - Fork 169
/
cmd-offline-update
executable file
·99 lines (87 loc) · 2.17 KB
/
cmd-offline-update
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
#!/usr/bin/bash
# Given a disk image and a coreos-assembler build, use supermin
# to update the disk image to the target OSTree commit "offline".
# Concretely for example if used on a pristine disk image, Ignition
# will not have run.
#
# Example usage to upgrade *from* RHCOS 4.6 to a just-built 4.8 OSTree tree,
# then do a kola basic run on it.
#
# cd /path/to/rhcos-4.8
# cp --reflink=auto /path/to/rhcos-4.6.0-x86_64-qemu.qcow2 tmp/
# cosa offline-update tmp/rhcos-4.6.0-x86_64-qemu.qcow2
# kola run -p qemu -b rhcos --qemu-image tmp/rhcos-4.6.0-x86_64-qemu.qcow2 basic
set -euo pipefail
dn=$(dirname "$0")
# shellcheck source=src/cmdlib.sh
. "${dn}"/cmdlib.sh
print_help() {
cat 1>&2 <<EOF
Usage: coreos-assembler offline-update --help
coreos-assembler offline-update [--build ID] [--commit COMMIT] DISK
In-place update DISK to the OSTree commit from the provided build.
EOF
}
rc=0
build=
commit=
options=$(getopt --options h --longoptions help,build,commit: -- "$@") || rc=$?
[ $rc -eq 0 ] || {
print_help
exit 1
}
eval set -- "$options"
while true; do
case "$1" in
-h | --help)
print_help
exit 0
;;
--build)
build=$2
shift
;;
--commit)
commit=$2
shift
;;
--)
shift
break
;;
-*)
fatal "$0: unrecognized option: $1"
;;
*)
break
;;
esac
shift
done
if [ $# -gt 1 ]; then
print_help
fatal "Too many arguments passed"
fi
if [ $# -eq 0 ]; then
print_help
fatal "Missing required argument"
fi
disk=$(realpath "$1")
shift
workdir=$(pwd)
TMPDIR=${workdir}/tmp
if [ -z "${commit}" ]; then
if [ -z "${build}" ]; then
build=$(get_latest_build)
if [ -z "${build}" ]; then
fatal "No build found."
fi
fi
builddir=$(get_build_dir "$build")
if [ ! -d "${builddir}" ]; then
fatal "Build dir ${builddir} does not exist."
fi
commit=$(json_key ostree-commit)
fi
runvm -drive if=virtio,id=target,format=qcow2,file="${disk}" -- \
/usr/lib/coreos-assembler/offline-update-impl "${workdir}/tmp/repo" "${commit}" "1"