2024-05-03 15:31:27 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
USAGE="$0 <install|remove> <package> <version> <num_packages>"
|
|
|
|
|
|
|
|
if test "$1" = "-h" -o "$1" = "--help"; then
|
|
|
|
echo "$USAGE"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if test "$#" -lt 2; then
|
|
|
|
echo "$USAGE" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ulp trigger have problems with bash expanding its arguments. Disable that
|
|
|
|
# and let it expand the wildcard by itself.
|
|
|
|
shopt -s nullglob
|
|
|
|
|
|
|
|
check_livepatching_env()
|
|
|
|
{
|
|
|
|
[ -z "$PACKAGE" ] && return 0
|
|
|
|
|
|
|
|
echo $PACKAGE
|
|
|
|
|
|
|
|
COMPONENT=${PACKAGE%-livepatches}
|
|
|
|
COMPONENT=${COMPONENT^^}
|
|
|
|
COMPONENT=${COMPONENT/-/_}
|
|
|
|
CONF_VAR_NAME="LIVEPATCH_$COMPONENT"
|
|
|
|
eval "$CONF_VAR_NAME"=auto
|
|
|
|
|
|
|
|
# Check if a sysconfig for livepatching exists. If yes, include the file.
|
|
|
|
if test -f "/etc/sysconfig/livepatching"; then
|
|
|
|
. /etc/sysconfig/livepatching || :
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
do_install()
|
|
|
|
{
|
|
|
|
if test -e /.buildenv; then
|
|
|
|
echo "Skipping userspace live patches in buildroot"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
check_livepatching_env || return 0
|
|
|
|
|
2024-12-11 15:11:23 +01:00
|
|
|
INSTALL_DIR="/usr/lib64/$PACKAGE/$VER"
|
|
|
|
TRIGGER_PATH="$INSTALL_DIR"
|
|
|
|
|
|
|
|
# Check if we are running a transactional update. If yes, then we need to
|
|
|
|
# move the livepatches to a better location.
|
2024-05-03 15:31:27 +02:00
|
|
|
if [ "$TRANSACTIONAL_UPDATE" = "true" ] && [ "x$TRANSACTIONAL_UPDATE_ROOT" != "x" ]; then
|
2024-12-11 15:11:23 +01:00
|
|
|
TRIGGER_PATH="/var/livepatches/$PACKAGE/$VER/lp"
|
|
|
|
|
|
|
|
# Create path if it doesn't already exist.
|
|
|
|
mkdir -p "$TRIGGER_PATH"
|
|
|
|
|
|
|
|
# Clean the path
|
|
|
|
rm -rf "$TRIGGER_PATH"
|
|
|
|
|
|
|
|
# Copy the patches to the location we have permission.
|
|
|
|
cp -rZ "$INSTALL_DIR" "$TRIGGER_PATH"
|
2024-05-03 15:31:27 +02:00
|
|
|
fi
|
|
|
|
|
2024-12-11 15:11:23 +01:00
|
|
|
ulp trigger --recursive -r 100 --timeout 200 --revert-all=target \
|
|
|
|
"$TRIGGER_PATH/*.so"
|
2024-05-03 15:31:27 +02:00
|
|
|
|
|
|
|
echo "ulp trigger executed."
|
|
|
|
}
|
|
|
|
|
|
|
|
do_remove()
|
|
|
|
{
|
|
|
|
: # reserved for future use
|
|
|
|
}
|
|
|
|
|
2024-12-11 15:11:23 +01:00
|
|
|
# Execute this on sle-micro to move the new libraries to the current snapshot.
|
|
|
|
do_movelibs()
|
|
|
|
{
|
|
|
|
if test -e /.buildenv; then
|
|
|
|
echo "Skipping move libs in buildroot"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
local ld_so_conf="/var/livepatches/ld.so.conf"
|
|
|
|
local addline="/var/livepatches/$PACKAGE/$VER/libs"
|
|
|
|
local line_pattern="/var/livepatches/$PACKAGE/.*/libs"
|
|
|
|
|
|
|
|
[[ -e $ld_so_conf ]] && sed -i "\#$line_pattern#d" $ld_so_conf
|
|
|
|
|
|
|
|
echo "$addline" >> $ld_so_conf
|
|
|
|
|
|
|
|
mkdir -p $addline
|
|
|
|
|
|
|
|
for i in $(seq 1 3); do
|
|
|
|
shift
|
|
|
|
done
|
2024-05-03 15:31:27 +02:00
|
|
|
|
2024-12-11 15:11:23 +01:00
|
|
|
for file in "$@"; do
|
|
|
|
[[ -e $file ]] && install -D -Z $file "$addline/$(basename $file)"
|
|
|
|
done
|
|
|
|
|
|
|
|
/sbin/ldconfig
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute this on sle-micro to move the new libraries to the current snapshot.
|
|
|
|
do_removelibs()
|
|
|
|
{
|
|
|
|
if test -e /.buildenv; then
|
|
|
|
echo "Skipping move libs in buildroot"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
local ld_so_conf="/var/livepatches/ld.so.conf"
|
|
|
|
local addline="/var/livepatches/$PACKAGE/$VER/libs"
|
|
|
|
local line_pattern="/var/livepatches/$PACKAGE/.*/libs"
|
|
|
|
|
|
|
|
# Remove the line of ld.so.conf
|
|
|
|
[[ -e $ld_so_conf ]] && sed -i "\#$line_pattern#d" $ld_so_conf
|
|
|
|
|
|
|
|
# Update ldconfig cache.
|
|
|
|
/sbin/ldconfig
|
|
|
|
|
|
|
|
# Delete copied libs.
|
|
|
|
rm -rf $addline
|
|
|
|
}
|
2024-05-03 15:31:27 +02:00
|
|
|
|
|
|
|
# Parse first argument (install or remove).
|
|
|
|
cmd=$1
|
|
|
|
PACKAGE=$2
|
|
|
|
VER=$3
|
|
|
|
TARGET_LIB=$4
|
|
|
|
NUM_PACKAGES=${5-0}
|
2024-12-11 15:11:23 +01:00
|
|
|
|
2024-05-03 15:31:27 +02:00
|
|
|
case "$cmd" in
|
2024-12-11 15:11:23 +01:00
|
|
|
install|remove|movelibs|removelibs)
|
|
|
|
do_$cmd "$@"
|
2024-05-03 15:31:27 +02:00
|
|
|
exit
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "$USAGE" >&2
|
|
|
|
exit 1
|
|
|
|
esac
|