USM packages use executable scripts to handle different phases of package lifecycle. Scripts are defined in the execs section of MANIFEST.usm and receive specific arguments based on their purpose.
Required script that compiles source code into binaries.
Arguments: [build-directory]
build-directory: Path where build output should be placedWorking Directory:
simpleBuildEnvironment flag: Build directory (source tree is copied first)Environment Variables: USM sets these non-prefixed variables for execs:
DESTDIR: Destination directoryPREFIX: Installation prefixBINDIR: Binary directoryINCLUDEDIR: Include directoryDATADIR: Data directoryINFODIR: Info directoryLIBDIR: Library directoryMANDIR: Manual directoryLIBEXECDIR: Libexec directoryLOCALEDIR: Locale directoryLOCALSTATEDIR: Local state directorySBINDIR: System binary directorySHAREDSTATEDIR: Shared state directorySYSCONFIGDIR: Configuration directoryTAGSDIR: Tags directoryNote: The USM_* prefixed environment variables are for the USM process itself and should not be used in exec scripts.
Example:
#!/bin/bash
set -e
build_dir=$1
# With simpleBuildEnvironment flag, we're already in build directory
# Without the flag, we need to change to build directory
if [ ! -d "$build_dir" ]; then
mkdir -p "$build_dir"
fi
cd ${build_dir}
meson setup ${src_dir} --prefix=${PREFIX} --libdir=${LIBDIR}
ninja
Optional script that installs built files to destination directory.
Arguments: [build-directory] [install-directory] [install-type]
build-directory: Path containing build outputinstall-directory: Path where files should be installed (DESTDIR)install-type: "fresh", "upgrade", or "downgrade"Working Directory:
simpleBuildEnvironment flag: Build directoryEnvironment Variables:
DESTDIR is overridden to install-directoryExample:
#!/bin/bash
set -e
build_dir=$1
install_dir=$2
install_type=$3
# With simpleBuildEnvironment flag, we're already in build directory
# Without the flag, we need to change to build directory
cd ${build_dir}
meson install --destdir ${install_dir}
Optional script that runs after USM installs resources to system.
Arguments: [build-directory] [install-type]
build-directory: Path containing build outputinstall-type: "fresh", "upgrade", or "downgrade"Working Directory:
simpleBuildEnvironment flag: Build directoryUse Case: System integration, cache generation, service registration
Example:
#!/bin/bash
set -e
build_dir=$1
install_type=$2
# Update desktop database
update-desktop-database
# Update icon cache
gtk-update-icon-cache -f -t /usr/share/icons/hicolor
Optional script that runs before USM removes package resources.
Arguments: [remove-type]
remove-type: "final", "upgrade", or "downgrade"Use Case: Cleanup, service stopping, data preservation
Example:
#!/bin/bash
set -e
remove_type=$1
# Stop service if being upgraded
if [ "$remove_type" != "final" ]; then
systemctl stop myapp || true
fi
# Remove user data only on final removal
if [ "$remove_type" = "final" ]; then
rm -rf /var/lib/myapp
fi
Optional script that downloads and extracts source code.
Arguments: None Working Directory: Package root directory
Use Case: Projects without native USM support, repository packaging
Dependencies: Listed in depends.acquire section
Example:
#!/bin/bash
set -e
ARCHIVE_URL="https://github.com/example/myapp/archive/v1.0.0.tar.gz"
ARCHIVE_NAME="source.tar.gz"
EXTRACT_DIR="."
echo "Downloading source..."
wget -O ${ARCHIVE_NAME} ${ARCHIVE_URL}
echo "Extracting archive..."
tar -xzf ${ARCHIVE_NAME} --strip-components=1
echo "Cleaning up..."
rm ${ARCHIVE_NAME}
Optional script that runs tests after build but before installation.
Arguments: [build-directory]
build-directory: Path containing build outputWorking Directory:
simpleBuildEnvironment flag: Build directoryEnvironment Variables: USM sets the same non-prefixed variables as described in the build script section:
DESTDIR, PREFIX, BINDIR, INCLUDEDIR, DATADIR, INFODIR, LIBDIR, MANDIR, LIBEXECDIR, LOCALEDIR, LOCALSTATEDIR, SBINDIR, SHAREDSTATEDIR, SYSCONFIGDIR, TAGSDIRUse Case: Unit tests, integration tests, validation of build artifacts
Example:
#!/bin/bash
set -e
build_dir=$1
# With simpleBuildEnvironment flag, we're already in build directory
# Without the flag, we need to change to build directory
cd ${build_dir}
# Run unit tests
./test-suite
# Run integration tests
./integration-tests
echo "All tests passed"
All scripts must be executable:
chmod +x usm-scripts/build.sh
Scripts should:
set -e to exit on errorsThe following USM_* prefixed environment variables are used by the USM process itself to configure paths:
USM_DESTDIR: Destination directoryUSM_PREFIX: Installation prefixUSM_BINDIR: Binary directoryUSM_INCLUDEDIR: Include directoryUSM_DATADIR: Data directoryUSM_INFODIR: Info directoryUSM_LIBDIR: Library directoryUSM_MANDIR: Manual directoryUSM_LIBEXECDIR: Libexec directoryUSM_LOCALEDIR: Locale directoryUSM_LOCALSTATEDIR: Local state directoryUSM_SBINDIR: System binary directoryUSM_SHAREDSTATEDIR: Shared state directoryUSM_SYSCONFIGDIR: Configuration directoryUSM_TAGSDIR: Tags directoryUSM_CONFIGDIR: USM configuration directoryUSM sets these non-prefixed variables for all executable scripts:
DESTDIR: Destination directoryPREFIX: Installation prefixBINDIR: Binary directoryINCLUDEDIR: Include directoryDATADIR: Data directoryINFODIR: Info directoryLIBDIR: Library directoryMANDIR: Manual directoryLIBEXECDIR: Libexec directoryLOCALEDIR: Locale directoryLOCALSTATEDIR: Local state directorySBINDIR: System binary directorySHAREDSTATEDIR: Shared state directorySYSCONFIGDIR: Configuration directoryTAGSDIR: Tags directoryImportant: Executable scripts should use the non-prefixed variables (e.g., ${PREFIX}, ${LIBDIR}) and NOT the USM_* prefixed variables, which are for internal USM process use only.
Scripts can be placed anywhere in the package, but common conventions:
usm-scripts/: Directory at package root (recommended)scripts/: Directory at package root (legacy)#!/bin/bash
set -e
src_dir=$(pwd)
build_dir=$1
cd ${build_dir}
meson setup ${src_dir} --prefix=${PREFIX} --libdir=${LIBDIR} --bindir=${BINDIR} --includedir=${INCLUDEDIR}
ninja
#!/bin/bash
set -e
src_dir=$(pwd)
build_dir=$1
cd ${build_dir}
make PREFIX=${PREFIX} LIBDIR=${LIBDIR}
#!/bin/bash
set -e
src_dir=$(pwd)
build_dir=$1
cd ${build_dir}
cmake ${src_dir} -DCMAKE_INSTALL_PREFIX=${PREFIX} -DCMAKE_INSTALL_LIBDIR=${LIBDIR}
make
When the simpleBuildEnvironment flag is set in the manifest:
This flag is particularly useful for:
When using ninjaStyleProgress flag, USM parses build output for progress:
[current/total]This reference provides complete specification for USM executable scripts used throughout package lifecycle management.