#!/bin/bash # SPDX-License-Identifier: GPL-2.0-or-later USAGE="$0 " 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 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. if [ "$TRANSACTIONAL_UPDATE" = "true" ] && [ "x$TRANSACTIONAL_UPDATE_ROOT" != "x" ]; then 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" fi ulp trigger --recursive -r 100 --timeout 200 --revert-all=target \ "$TRIGGER_PATH/*.so" echo "ulp trigger executed." } do_remove() { : # reserved for future use } # 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 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 } # Parse first argument (install or remove). cmd=$1 PACKAGE=$2 VER=$3 TARGET_LIB=$4 NUM_PACKAGES=${5-0} case "$cmd" in install|remove|movelibs|removelibs) do_$cmd "$@" exit ;; *) echo "$USAGE" >&2 exit 1 esac