-
Notifications
You must be signed in to change notification settings - Fork 510
/
rpm2migrations
executable file
·46 lines (38 loc) · 1.27 KB
/
rpm2migrations
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
#!/usr/bin/env bash
#
# Retrieve migrations from the RPM and output an appropriately named tarball
set -eu -o pipefail
for opt in "$@"; do
optarg="$(expr "${opt}" : '[^=]*=\(.*\)')"
case "${opt}" in
--package-dir=*) PACKAGE_DIR="${optarg}" ;;
--output-dir=*) OUTPUT_DIR="${optarg}" ;;
esac
done
mkdir -p "${OUTPUT_DIR}"
MIGRATIONS_ARCHIVE="bottlerocket-${VARIANT}-${ARCH}-${VERSION_ID}-${BUILD_ID}-migrations.tar"
ROOT_TEMP="$(mktemp -d)"
SYS_ROOT="${ARCH}-bottlerocket-linux-gnu/sys-root"
MIGRATIONS_DIR="${ROOT_TEMP}/${SYS_ROOT}/usr/share/migrations"
# "Install" the migrations (just puts them in $MIGRATIONS_DIR)
rpm -iv --root "${ROOT_TEMP}" "${PACKAGE_DIR}"/*.rpm
if [ ! -d "${MIGRATIONS_DIR}" ]; then
echo "Migrations directory does not exist: ${MIGRATIONS_DIR}"
rm -rf "${ROOT_TEMP}"
exit 1
fi
# lz4 compress each migration
for migration in "${MIGRATIONS_DIR}"/*; do
[ -e "${migration}" ] || continue
lz4 -v "${migration}" "${migration}.lz4"
done
# Tar up migrations with a .lz4 extension if they exist.
# Otherwise create an empty archive
pushd "${MIGRATIONS_DIR}"
if ls *.lz4 &> /dev/null; then
tar -cvf "${OUTPUT_DIR}/${MIGRATIONS_ARCHIVE}" *.lz4
else
tar -cvf "${OUTPUT_DIR}/${MIGRATIONS_ARCHIVE}" --files-from /dev/null
fi
popd
rm -rf "${ROOT_TEMP}"