Merge lp:~pwlars/curtinator/curtinator-ng-merge into lp:~roadmr/curtinator/trunk

Proposed by Paul Larson
Status: Merged
Merged at revision: 9
Proposed branch: lp:~pwlars/curtinator/curtinator-ng-merge
Merge into: lp:~roadmr/curtinator/trunk
Diff against target: 189 lines (+65/-29)
4 files modified
README (+1/-1)
data/libvirt.xml (+1/-1)
data/preseed.txt (+7/-4)
scripts/curtinator (+56/-23)
To merge this branch: bzr merge lp:~pwlars/curtinator/curtinator-ng-merge
Reviewer Review Type Date Requested Status
Daniel Manrique Approve
Review via email: mp+341338@code.launchpad.net

Description of the change

This is mostly just a merge of jibel's -ng branch on top of the current trunk. It worked for me to convert a recent bionic image.

To post a comment you must log in.
Revision history for this message
Daniel Manrique (roadmr) wrote :

I don't love having curtinator run as root, it was part of the reasons why we used nc to slurp the filesystem in the first place.

If possible, I'd like to see a solution that doesn't require this.

That said, since you guys probably use this more than I do, I'll merge this so as to not block you and we can look at other options later.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2015-01-09 19:39:56 +0000
3+++ README 2018-03-13 14:46:08 +0000
4@@ -12,7 +12,7 @@
5
6
7 Prerequisite packages and setup:
8-- Install qemu-kvm libvirt-bin virt-viewer genisoimage
9+- Install qemu-kvm libvirt-bin virt-viewer genisoimage libguestfs-tools
10 - Add the required user to the libvirtd and kvm groups:
11 sudo usermod -a -G libvirtd,kvm <username>
12 - REBOOT. Logging out and back in does NOT suffice due to kvm module
13
14=== modified file 'data/libvirt.xml'
15--- data/libvirt.xml 2014-10-27 21:46:10 +0000
16+++ data/libvirt.xml 2018-03-13 14:46:08 +0000
17@@ -1,7 +1,7 @@
18 <domain type='kvm'>
19 <name>@@NAME@@</name>
20 <uuid>@@UUID@@</uuid>
21- <memory>800000</memory>
22+ <memory>1572864</memory>
23 <vcpu>1</vcpu>
24 <features>
25 <acpi/>
26
27=== modified file 'data/preseed.txt'
28--- data/preseed.txt 2018-01-05 21:46:30 +0000
29+++ data/preseed.txt 2018-03-13 14:46:08 +0000
30@@ -4,7 +4,9 @@
31 d-i passwd/auto-login boolean true
32 d-i passwd/user-fullname string Ubuntu User
33 d-i passwd/username string ubuntu
34-d-i passwd/user-password-crypted password $1$NxGTHVE/$NX4GcXv76Xorum3DFgx53/
35+d-i passwd/user-password password ubuntu
36+d-i passwd/user-password-again password ubuntu
37+d-i user-setup/allow-password-weak boolean true
38 d-i debian-installer/allow_unauthenticated boolean true
39 d-i preseed/late_command string \
40 sed -i '/^deb cdrom:/s/^/#/' /target/etc/apt/sources.list; \
41@@ -21,8 +23,7 @@
42 ); \
43 umount /target/sys; \
44 umount /target/media/cdrom; \
45- umount /target/proc; \
46- (cd /target/; tar -c ./ ) | nc @@ADDRESS@@ @@PORT@@
47+ umount /target/proc
48
49 d-i console-setup/ask_detect boolean false
50 d-i console-setup/layoutcode string us
51@@ -57,5 +58,7 @@
52 grep -q "source.*/${enid}" "$eni" && exit 0; \
53 { echo; echo "#curtinator added"; echo "source /$enid/*.cfg"; } >> "$eni" \
54 ); \
55- (cd /target/; tar -c ./ ) | nc @@ADDRESS@@ @@PORT@@
56+ umount /target/sys; \
57+ umount /target/media/cdrom; \
58+ umount /target/proc
59
60
61=== modified file 'scripts/curtinator'
62--- scripts/curtinator 2018-01-05 15:33:11 +0000
63+++ scripts/curtinator 2018-03-13 14:46:08 +0000
64@@ -1,6 +1,15 @@
65 #!/bin/bash
66
67-set -e
68+set -eu
69+
70+if [ $(id -u) -ne 0 -a -z "$(echo $@ | grep -- -h)" ]; then
71+ echo "E: This script must run as root. Aborting!"
72+ exit 1
73+fi
74+
75+LANG=C # Required because output of virsh command is i18ned and string matching are failing
76+SLEEP_TIME=30
77+MAX_RETRY=$(( 20 * 60 / $SLEEP_TIME )) # Retry for 20 minutes
78
79 MIRROR_HOSTNAME=${MIRROR_HOSTNAME:-archive.ubuntu.com}
80 MIRROR_DIRECTORY=${MIRROR_DIRECTORY:-/ubuntu}
81@@ -21,18 +30,21 @@
82 PATH=$(dirname $0):$PATH
83
84 function usage() {
85- echo "Usage: $(basename $0) [-h] [-d DIRECTORY] [-n NAME] [-t RESULT_TARBALL] ISO"
86+ trap - EXIT INT QUIT ABRT PIPE TERM
87+ echo "Usage: $(basename $0) [-h] [-d] [-D DIRECTORY] [-n NAME] [-t RESULT_TARBALL] ISO"
88 exit 1
89 }
90
91-function absolute_path() {
92- local relative_path=$1; shift
93-
94- directory=$(dirname "$relative_path")
95- filename=$(basename "$relative_path")
96- echo $(cd "$directory" 2>/dev/null && pwd || echo "$directory")/$filename
97+function on_exit() {
98+ local rc=$?
99+ echo "Cleaning environment!"
100+ virsh destroy $NAME 2>/dev/null ||true
101+ virsh undefine $NAME 2>/dev/null ||true
102+ exit $rc
103 }
104
105+trap on_exit EXIT INT QUIT ABRT PIPE TERM
106+
107 function disk_info() {
108 local info_file=$1; shift
109
110@@ -136,10 +148,15 @@
111 $DATA_DIR/preseed.txt
112 }
113
114+NAME=""
115+DIRECTORY=""
116+TARBALL=""
117+
118 # Parse the command-line options.
119-while getopts "d:n:t:h" OPTION; do
120+while getopts "dD:n:t:h" OPTION; do
121 case ${OPTION} in
122- d) DIRECTORY=$OPTARG;;
123+ d) set -x;;
124+ D) DIRECTORY=$OPTARG;;
125 n) NAME=$OPTARG;;
126 t) TARBALL=$OPTARG;;
127 h|?) usage;;
128@@ -214,10 +231,10 @@
129 -e "s|@@MAC@@|${MAC}|" \
130 -e "s|@@NAME@@|${NAME}|" \
131 -e "s|@@UUID@@|${UUID}|" \
132- -e "s|@@CDROM@@|$(absolute_path $ISO)|" \
133- -e "s|@@DISK@@|$(absolute_path $QCOW2)|" \
134- -e "s|@@KERNEL@@|$(absolute_path $DIRECTORY/$KERNEL)|" \
135- -e "s|@@INITRD@@|$(absolute_path $DIRECTORY/$INITRD)|" \
136+ -e "s|@@CDROM@@|$(readlink -f $ISO)|" \
137+ -e "s|@@DISK@@|$(readlink -f $QCOW2)|" \
138+ -e "s|@@KERNEL@@|$(readlink -f $DIRECTORY/$KERNEL)|" \
139+ -e "s|@@INITRD@@|$(readlink -f $DIRECTORY/$INITRD)|" \
140 $DATA_DIR/libvirt.xml > $LIBVIRT
141
142 # Destroy and undefine the previous libvirt domain silently, just in case.
143@@ -230,14 +247,29 @@
144 virsh -c qemu:///system "start $NAME"
145
146 # Listen on the random port and wait for the tarball.
147-TARFILE="$ISO.tar"
148-TGZFILE="$TARFILE.gz"
149+TGZFILE="$(readlink -f $DIRECTORY)/$(basename $ISO .iso).tar.gz"
150 echo "Installing, run this command for progress:"
151 echo "# virt-viewer $NAME"
152-# Note: gzip not available in installer environment.
153-nc -l $DEFAULT_ADDRESS $DEFAULT_PORT > $TARFILE
154-echo "Compressing tarball"
155-gzip -f $TARFILE
156+
157+# Wait until installation is over
158+TRY=0
159+while :; do
160+ if virsh domstate $NAME|grep -q "shut off"; then
161+ break
162+ fi
163+ sleep 30
164+ TRY=$(( $TRY + 1 ))
165+ if [ $TRY -ge $MAX_RETRY ]; then
166+ echo "E: Reached max retries ($MAX_RETRY) Exiting!"
167+ exit 1
168+ fi
169+done
170+
171+guestmount -d $NAME --ro -m /dev/sda1 /mnt
172+cd /mnt
173+tar czf $TGZFILE .
174+cd -
175+guestunmount /mnt
176
177 # Patch the libvirt xml configuration so that it can be booted.
178 # Note: this is a convenience, not absolutely necessary.
179@@ -253,6 +285,7 @@
180 # All done
181 echo "Finished $TGZFILE"
182
183-[ ! -z "$TARBALL" ] && (mv $TGZFILE $TARBALL; echo "Moved to $TARBALL")
184-
185-
186+if [ -n "$TARBALL" ]; then
187+ mv $TGZFILE $TARBALL
188+ echo "Moved to $TARBALL"
189+fi

Subscribers

People subscribed via source and target branches

to all changes: