Skip to content
Snippets Groups Projects
Commit 7084e0d5 authored by Reinder Kraaij's avatar Reinder Kraaij :eye:
Browse files

Software module, distset

parent cee0239f
No related branches found
No related tags found
2 merge requests!15Resolve L2SS-2305 "Add hawkbit support",!4L2SS-2305: Add Hawkbit support
Pipeline #124530 skipped
......@@ -37,7 +37,7 @@ publish_to_hawkbit:
script:
- cd publish
- chmod +x *.sh
- ./create_software_module.sh
- ./create_software_module_with_distset.sh
- ./publish_to_hawkbit.sh
......
......@@ -5,14 +5,15 @@ DEFAULT_SERVER="https://ota.lofar.net"
SERVER="${1:-$DEFAULT_SERVER}"
# Software module metadata
MODULE_NAME="CCD/APSCT Yocto Image"
MODULE_NAME="Lofar CCD and APSCT Yocto Image"
MODULE_TYPE="os"
MODULE_VENDOR="LOFAR"
MODULE_DESC="Yocto image for Raspberry Pi"
# Distribution metadata
DIST_NAME="Lofar CCD/APSCT Yocto Image Distribution"
DIST_DESC="Distribution for CCD/APSCT Raspberry Pi Yocto images"
# Distribution set metadata
DISTSET_NAME="Lofar CCD and APSCT Yocto Image Distribution"
DISTSET_DESC="Distribution set for CCD APSCT Raspberry Pi Yocto images"
DISTSET_TYPE="os_app" # its a full os with apps :)
# Determine version from GitLab CI or local commit
if [ -n "$CI_COMMIT_TAG" ]; then
......@@ -25,12 +26,19 @@ fi
echo "Using version: $MODULE_VERSION"
# 1. Check if software module exists and get its ID
# urlencode function using jq
urlencode() {
printf '%s' "$1" | jq -sRr @uri
}
# 1. Check if software module exists and get its ID, using q filter
query_sm="name==\"$MODULE_NAME\";version==\"$MODULE_VERSION\""
query_sm_enc=$(urlencode "$query_sm")
modules=$(curl -s -u "$HAWKBITUSER:$HAWKBITPW" \
"$SERVER/rest/v1/softwaremodules?page=0&size=100")
"$SERVER/rest/v1/softwaremodules?q=$query_sm_enc&limit=1")
module_id=$(echo "$modules" | jq -r --arg name "$MODULE_NAME" --arg version "$MODULE_VERSION" \
'.content[] | select(.name == $name and .version == $version) | .id // empty')
module_id=$(echo "$modules" | jq -r '.content[0].id // empty')
if [ -n "$module_id" ]; then
echo "➤ Software module \"$MODULE_NAME\" version \"$MODULE_VERSION\" already exists with ID $module_id."
......@@ -60,24 +68,51 @@ else
echo "➤ Created software module with ID: $module_id"
fi
# 2. Check if distribution exists
distributions=$(curl -s -u "$HAWKBITUSER:$HAWKBITPW" \
"$SERVER/rest/v1/distributions?page=0&size=100")
# 2. Check if distribution set exists and get its ID, using q filter
query_ds="name==\"$DISTSET_NAME\""
query_ds_enc=$(urlencode "$query_ds")
distsets=$(curl -s -u "$HAWKBITUSER:$HAWKBITPW" \
"$SERVER/rest/v1/distributionsets?q=$query_ds_enc&limit=1")
#echo "$distsets"
distset_id=$(echo "$distsets" | jq -r '.content[0]?.id // empty')
if echo "$distributions" | jq -e --arg name "$DIST_NAME" \
'.content[] | select(.name == $name)' > /dev/null; then
echo "➤ Distribution \"$DIST_NAME\" already exists."
if [ -n "$distset_id" ]; then
echo "➤ Distribution set \"$DISTSET_NAME\" already exists with ID $distset_id."
else
echo "➤ Creating distribution \"$DIST_NAME\"..."
echo "➤ Creating distribution set \"$DISTSET_NAME\"..."
dist_payload=$(jq -n \
--arg name "$DIST_NAME" \
--arg desc "$DIST_DESC" \
--argjson modules "[{ \"id\": \"$module_id\" }]" \
'{ name: $name, description: $desc, softwareModules: $modules, enabled: true }')
# Prepare modules array with module_id converted to number inside jq
modules_array=$(jq -n --arg id "$module_id" '[{id: ($id|tonumber)}]')
distset_payload=$(jq -n \
--arg name "$DISTSET_NAME" \
--arg desc "$DISTSET_DESC" \
--arg version "$MODULE_VERSION" \
--arg type "$DISTSET_TYPE" \
--argjson modules "$modules_array" \
'{
name: $name,
description: $desc,
version: $version,
locked: true,
requiredMigrationStep: false,
modules: $modules,
type: $type
}')
#echo "$distset_payload" | jq .
curl -s -w "\n→ HTTP %{http_code}\n" -u "$HAWKBITUSER:$HAWKBITPW" \
response=$(curl -s -u "$HAWKBITUSER:$HAWKBITPW" \
-H "Content-Type: application/json" \
-X POST "$SERVER/rest/v1/distributions" \
-d "$dist_payload"
-X POST "$SERVER/rest/v1/distributionsets" \
-d "[$distset_payload]")
echo "$response"
distset_id=$(echo "$response" | jq -r '.[0].id')
if [ -z "$distset_id" ] || [ "$distset_id" = "null" ]; then
echo "❌ ERROR: Failed to create distribution set or parse ID"
exit 1
fi
echo "➤ Created distribution set with ID: $distset_id"
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment