/
gf-anaconda-cleanup
executable file
·80 lines (73 loc) · 2.52 KB
/
gf-anaconda-cleanup
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
#!/usr/bin/env bash
# This runs after virt-install to undo things leftover from Anaconda.
set -euo pipefail
dn=$(dirname "$0")
# shellcheck source=src/cmdlib.sh
. "${dn}"/cmdlib.sh
# shellcheck source=src/libguestfish.sh
. "${dn}"/libguestfish.sh
src="$1"
shift
set -x
coreos_gf_run "${src}"
# We don't have a way to do this with Anaconda/kickstart right now.
# This bootstraps us to be able to do all of the mounts.
coreos_gf set-label /dev/sda2 boot
coreos_gf_run_mount "${src}"
fb=/boot/ignition.firstboot
exists=$(coreos_gf exists "${fb}")
if [ "${exists}" = false ]; then
cat << EOF
---------
error: Couldn't find ${fb} - most likely Anaconda failed."
error: If 9pfs is available, you can find logs in: tmp/build/tmp/anaconda"
---------
EOF
exit 1
fi
# Remove most things written by anaconda in /etc, except
# for /etc/fstab mainly.
for x in "sysconfig/anaconda" "sysconfig/network" "hostname" "crypttab" "resolv.conf" "X11" "systemd/system/default.target" "shadow-"; do
coreos_gf rm-rf "${deploydir}/etc/${x}"
done
for x in $(coreos_gf glob-expand "${deploydir}/etc/sysconfig/network-scripts/"'*'); do
coreos_gf rm-rf "${x}"
done
for x in $(coreos_gf find "${deploydir}/etc/ostree/remotes.d/"); do
e=$(coreos_gf exists "${deploydir}/usr/etc/${x}")
if [ "${e}" = "true" ]; then
continue
fi
coreos_gf rm "${deploydir}/etc/ostree/remotes.d/${x}"
done
# We'd like to remove all of /var, but SELinux issues prevent that.
# see https://github.com/coreos/ignition-dracut/pull/79#issuecomment-488446949
# For now we retain just /var/lib/systemd (for the random seed) and /var/log
# for the journal, which init before systemd-tmpfiles.
# Also just leave /var/home and /var/roothome; this allows early Ignition in
# RHCOS to add users and drop files in /root. (On FCOS, we don't strictly
# *need* this because we run systemd-tmpfiles).
var="${stateroot}/var"
coreos_gf ls "${var}" | while read -r x; do
case "$x" in
log|lib) continue;;
home|roothome) coreos_gf glob rm-rf "${var}/${x}/*";;
*) coreos_gf rm-rf "${var}/${x}"
esac
done
coreos_gf ls "${var}/lib" | while read -r x; do
if [ "${x}" = "systemd" ]; then continue; fi
coreos_gf rm-rf "${var}/lib/${x}"
done
for x in "lib/systemd" "log"; do
coreos_gf glob rm-rf "${var}/${x}/*"
done
# And finally, remove cruft from the *physical* root as nothing should be
# using those; Anaconda is creating them today.
for x in $(coreos_gf glob-expand '/*'); do
case $x in
/ostree/|/boot/) continue;;
*) coreos_gf rm-rf "${x}"
esac
done
coreos_gf_shutdown