Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
holmanb committed Sep 4, 2024
1 parent 1bf5d42 commit 705d856
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 102 deletions.
78 changes: 0 additions & 78 deletions debian/cloud-init.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -7,83 +7,6 @@ set -e
set -f # disable pathname expansion
db_capb escape # to support carriage return / multi-line values

fix_1336855() {
### Begin fix for LP: 1336855
# fix issue where cloud-init misidentified the location of grub and
# where grub misidentifies the location of the device
local oldver="$1" last_bad_ver="24.3~1g6e4153b3-0ubuntu1"
dpkg --compare-versions "$oldver" le-nl "$last_bad_ver" || return 0

# if cloud-init's grub module did not run, then it did not break anything.
[ -f /var/lib/cloud/instance/sem/config_grub_dpkg ] || return 0

# This bug only happened on /dev/xvda devices
[ -b /dev/xvda ] || return 0

# we can't fix the system without /proc/cmdline
[ -r /proc/cmdline ] || return 0

# Don't do anything unless we have grub
command -v grub-install > /dev/null || return 0

# First, identify the kernel device for the parent.
for parm in $(cat /proc/cmdline); do
dev=$(echo $parm | awk -F\= '{print$NF}')
case $parm in
root=UUID*) [ -d /dev/disk/by-uuid ] &&
root_dev=$(readlink -f /dev/disk/by-uuid/$dev);;
root=LABEL*) [ -d /dev/disk/by-label ] &&
root_dev=$(readlink -f /dev/disk/by-label/$dev);;
root=/dev*) [ -d /dev ] &&
root_dev=$(readlink -f $dev);;
esac
[ -n "$root_dev" ] && break
done

# Don't continue if we don't have a root directive
[ -z "$root_dev" ] && return 0

# Only deal with simple, cloud-based devices
case $root_dev in
/dev/vda*|/dev/xvda*|/dev/sda*) ;;
*) return 0;;
esac

# Make sure that we are not chrooted.
[ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ] && return 0

# Check if we are in a container, i.e. LXC
if systemd-detect-virt --quiet --container || lxc-is-container 2>/dev/null; then
return 0
fi

# Find out where grub thinks the root device is. Only continue if
# grub postinst would install/reinstall grub
db_get grub-pc/install_devices && grub_cfg_dev=${RET} || return 0
db_get grub-pc/install_devices_empty && grub_dev_empty=${RET} || return 0

# Find out the parent device for the root device.
# example output: sda/sda1
block_path=$(udevadm info -q path -n $root_dev | awk '-Fblock/' '{print$NF}') || return 0

# Extract the parent device name. This works where the device is a block device
# example output: /dev/sda
parent_dev=$(echo $block_path | awk '-F/' '$1 { if ( $1 ) {print"/dev/"$1}}')
[ -b "${parent_dev}" ] || return 0

# Do nothing if the device that the grub postinst would install is already used
[ "$grub_cfg_dev" = "$parent_dev" -o "$grub_cfg_dev" = "$root_dev" ] && return 0

# If we get here, do the installation
echo "Reconfiguring grub install device due to mismatch (LP: #1336855)"
echo " Grub should use $parent_dev but is configured for $grub_cfg_dev"
db_set grub-pc/install_devices "$parent_dev"
grub-install $parent_dev &&
echo "Reinstalled grub" ||
echo "WARNING! Unable to fix grub device mismatch. You may be broken."

}

fix_lp1889555() {
local oldver="$1" last_bad_ver="20.3-2-g371b392c-0ubuntu1"
dpkg --compare-versions "$oldver" le-nl "$last_bad_ver" || return 0
Expand Down Expand Up @@ -156,7 +79,6 @@ EOF
if [ "$1" = "configure" ]; then

update_maas_spelling "$2"
fix_1336855 "$2"
fix_lp1889555 "$2"
rename_hook_hotplug_udev_rule "$2"

Expand Down
26 changes: 2 additions & 24 deletions debian/cloud-init.preinst
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,16 @@ set -e

cleanup_oci_network_lp1956788() {
# Remove vestigial /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
# from Oracle now that datasource honors system cfg above datasource cfg.
local oldver="$1" last_bad_ver="24.3~1g6e4153b3-0ubuntu1"
dpkg --compare-versions "$oldver" le "$last_bad_ver" || return 0 # from Oracle now that datasource honors system cfg above datasource cfg.
dpkg --compare-versions "$oldver" le "$last_bad_ver" || return 0
grep DataSourceOracle /var/lib/cloud/instance/datasource > /dev/null 2>&1 || return 0
rm -f /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
}

cleanup_user_scripts() {
local oldver="$1" last_bad_ver="24.3~1g6e4153b3-0ubuntu1"
dpkg --compare-versions "$oldver" le "$last_bad_ver" || return 0 # from Oracle now that datasource honors system cfg above datasource cfg.
# 0.6.0 changed 'user-scripts' to config-scripts-user (LP: #1049146)
if [ -e /var/lib/cloud/instance/sem/user-scripts ]; then
ln -sf user-scripts /var/lib/cloud/instance/sem/config-scripts-user
fi
}

cleanup_rename_config() {
local oldver="$1" last_bad_ver="24.3~1g6e4153b3-0ubuntu1"
dpkg --compare-versions "$oldver" le "$last_bad_ver" || return 0 # from Oracle now that datasource honors system cfg above datasource cfg.
d=/etc/cloud/
if [ -f "$d/distro.cfg" ] && [ ! -f "$d/cloud.cfg.d/90_dpkg.cfg" ]; then
echo "moving $d/distro.cfg -> $d/cloud.cfg.d/90_dpkg.cfg"
[ -d "${d}/cloud.cfg.d" ] || mkdir "${d}/cloud.cfg.d"
mv "$d/distro.cfg" "$d/cloud.cfg.d/90_dpkg.cfg"
fi
}
case "$1" in
install|upgrade)

cleanup_user_scripts "$2"
cleanup_rename_config "$2"
cleanup_oci_network_lp1956788 "$2"

esac

#DEBHELPER#

0 comments on commit 705d856

Please sign in to comment.