-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdimage.sh
executable file
·68 lines (54 loc) · 1.19 KB
/
updimage.sh
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
#!/bin/bash
# SPDX-FileCopyrightText: 2023 Rivos Inc.
#
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
d=$(dirname "${BASH_SOURCE[0]}")
tmp=$(mktemp -d)
cleanup() {
rm -rf "$tmp"
}
trap cleanup EXIT
kernel=
modpath=
while getopts k:m:n name ; do
case $name in
k)
kernel="$OPTARG"
;;
m)
modpath="$OPTARG"
;;
?)
exit 1
;;
esac
done
shift $(($OPTIND -1))
imagename=$1
imsz=1
if [[ $modpath ]]; then
imsz=$(du -B 1G -s "$modpath" | awk '{print $1}')
fi
eval "$(guestfish --listen)"
guestfish --remote -- \
add "$imagename" : \
launch : \
mount /dev/sda2 / : \
mount /dev/sda1 /boot/efi
if [[ $kernel ]]; then
guestfish --remote -- \
rm /boot/efi/Image : \
copy-in $kernel /boot/efi/
if [[ $(basename $kernel) != Image ]]; then
guestfish --remote -- mv /boot/efi/$(basename $kernel) /boot/efi/Image
fi
fi
if [[ $modpath ]]; then
guestfish --remote -- copy-in $modpath /lib/
fi
guestfish --remote -- \
sync : \
umount /boot/efi : \
umount / : \
exit