Skip to content

Commit 3ffcbe2

Browse files
authored
PKG-932 Provide SBOMS for PLM (#115)
1 parent dfa5aba commit 3ffcbe2

File tree

2 files changed

+1128
-0
lines changed

2 files changed

+1128
-0
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
shell_quote_string() {
5+
echo "$1" | sed -e 's,\([^a-zA-Z0-9/_.=-]\),\\\1,g'
6+
}
7+
8+
usage () {
9+
cat <<EOF
10+
Usage: $0 [OPTIONS]
11+
The following options may be given :
12+
--plm_version PostgreSQL major_version.minor_version
13+
--repo_type Repository type
14+
--help) usage ;;
15+
Example $0 --plm_version=7.0.18-11 --repo_type=testing
16+
EOF
17+
exit 1
18+
}
19+
20+
append_arg_to_args () {
21+
args="$args "$(shell_quote_string "$1")
22+
}
23+
24+
parse_arguments() {
25+
pick_args=
26+
if test "$1" = PICK-ARGS-FROM-ARGV
27+
then
28+
pick_args=1
29+
shift
30+
fi
31+
32+
for arg do
33+
val=$(echo "$arg" | sed -e 's;^--[^=]*=;;')
34+
case "$arg" in
35+
--builddir=*) WORKDIR="$val" ;;
36+
--plm_version=*) PLM_VERSION="$val" ;;
37+
--repo_type=*) REPO_TYPE="$val" ;;
38+
--git_repo=*) GIT_REPO="$val" ;;
39+
--git_branch=*) GIT_BRANCH="$val" ;;
40+
--help) usage ;;
41+
*)
42+
if test -n "$pick_args"
43+
then
44+
append_arg_to_args "$arg"
45+
fi
46+
;;
47+
esac
48+
done
49+
}
50+
51+
CWD=$(pwd)
52+
PLM_VERSION=0.5.0
53+
REPO_TYPE=testing
54+
ARCH=$(uname -m)
55+
56+
parse_arguments PICK-ARGS-FROM-ARGV "$@"
57+
58+
# Set non-interactive tzdata environment variables to avoid prompts
59+
export DEBIAN_FRONTEND=noninteractive
60+
61+
# Platform detection
62+
if [ -f /etc/os-release ]; then
63+
. /etc/os-release
64+
PLATFORM_ID=$(echo "$ID" | tr '[:upper:]' '[:lower:]')
65+
VERSION_ID=$(echo "$VERSION_ID" | tr -d '"')
66+
else
67+
echo "Unable to detect OS."
68+
exit 1
69+
fi
70+
71+
# Function to install dependencies
72+
install_dependencies() {
73+
case "$PLATFORM_ID" in
74+
ol|centos|rhel|rocky|almalinux)
75+
# RHEL/CentOS/OracleLinux (RHEL 8/9)
76+
RHEL=$(rpm --eval %rhel)
77+
PLATFORM=${PLATFORM_ID}${RHEL}
78+
dnf install -y jq
79+
dnf config-manager --set-enabled ol${RHEL}_codeready_builder || true
80+
dnf install -y 'dnf-command(config-manager)'
81+
;;
82+
ubuntu|debian)
83+
# Install dependencies for Ubuntu/Debian
84+
PLATFORM=$(echo "$VERSION_CODENAME" | tr '[:upper:]' '[:lower:]')
85+
apt update
86+
apt install -y curl gnupg jq lsb-release
87+
apt --fix-broken install -y # Fix broken dependencies
88+
;;
89+
*)
90+
echo "Unsupported platform: $PLATFORM_ID"
91+
exit 1
92+
;;
93+
esac
94+
}
95+
96+
# Install required dependencies
97+
install_dependencies
98+
99+
# Install Percona repo and PostgreSQL
100+
install_percona_link_mongodb() {
101+
case "$PLATFORM_ID" in
102+
ol|rhel|centos|oraclelinux)
103+
# Install Percona repo on RHEL/CentOS/OracleLinux
104+
curl -sO https://repo.percona.com/yum/percona-release-latest.noarch.rpm
105+
dnf install -y percona-release-latest.noarch.rpm
106+
percona-release enable plm ${REPO_TYPE}
107+
dnf install -y \
108+
percona-link-mongodb
109+
;;
110+
ubuntu|debian)
111+
# Install Percona repo on Ubuntu/Debian
112+
curl -sO https://repo.percona.com/apt/percona-release_latest.generic_all.deb
113+
dpkg -i percona-release_latest.generic_all.deb
114+
apt --fix-broken install -y # Fix broken dependencies
115+
apt update
116+
117+
# Explicitly enable the plm repository
118+
percona-release enable telemetry
119+
percona-release enable plm ${REPO_TYPE}
120+
apt-get update
121+
apt-get install -y \
122+
percona-link-mongodb
123+
;;
124+
*)
125+
echo "Unsupported platform: $PLATFORM_ID"
126+
exit 1
127+
;;
128+
esac
129+
}
130+
131+
# Install Percona repository and PostgreSQL
132+
install_percona_link_mongodb
133+
134+
# Install Syft (if not already installed)
135+
if ! command -v syft &>/dev/null; then
136+
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
137+
fi
138+
139+
mkdir -p $CWD/plm_sbom
140+
141+
# Generate full SBOM using db fallback
142+
echo "Generating full SBOM via db..."
143+
syft dir:/ --output cyclonedx-json > sbom-full-db.json
144+
145+
# Filter PLM components and preserve SBOM structure
146+
jq '{
147+
"$schema": ."$schema",
148+
"bomFormat": .bomFormat,
149+
"specVersion": .specVersion,
150+
"serialNumber": .serialNumber,
151+
"version": .version,
152+
"metadata": .metadata,
153+
"components": [.components[] | select(.name | test("mongodb|percona"; "i"))]
154+
}' sbom-full-db.json > $CWD/plm_sbom/sbom-percona-link-mongodb-${PLM_VERSION}-${PLATFORM}-${ARCH}.json
155+
156+
echo "✅ SBOM for Percona Backup for MongoDB ${PLM_VERSION} written to: $CWD/plm_sbom/sbom-percona-link-mongodb-${PLM_VERSION}-${PLATFORM}-${ARCH}.json"

0 commit comments

Comments
 (0)