72 lines
2.3 KiB
Bash
Executable file
72 lines
2.3 KiB
Bash
Executable file
#!/bin/bash
|
|
set -eu
|
|
|
|
# Check if the output directory is provided as the first parameter
|
|
if [ "$#" -lt 1 ]; then
|
|
echo "Error: Output directory not provided."
|
|
echo "Usage: $0 <output_directory>"
|
|
exit 1
|
|
fi
|
|
|
|
# Remove trailing slash from the provided output directory path
|
|
OUTPUT_DIRECTORY=$(echo "$1" | sed 's:/$::')
|
|
|
|
GITEA_USERNAME=${GITEA_USERNAME:?Please export GITEA_USERNAME to env first!}
|
|
GITEA_TOKEN=${GITEA_TOKEN:?Please export GITEA_TOKEN to env first!}
|
|
|
|
# Source environment variables
|
|
if [ -z "$GITEA_USERNAME" ] || [ -z "$GITEA_TOKEN" ]; then
|
|
echo "Error: GITEA_USERNAME or GITEA_TOKEN not set in the environment."
|
|
exit 1
|
|
fi
|
|
|
|
GITEA_BASEURL="https://code.strobel.one"
|
|
GITEA_OWNER="rafeOS"
|
|
IMAGE_ID="rafeOS"
|
|
IMAGE_VARIANT="server"
|
|
IMAGE_VERSION="$(cat mkosi.images/${IMAGE_VARIANT}/mkosi.version)"
|
|
PACKAGE_NAME="image"
|
|
PACKAGE_VERSION="server"
|
|
|
|
# Populate FILES array with all files found in the output directory
|
|
declare -a FILES=("$OUTPUT_DIRECTORY"/*)
|
|
|
|
for FILE in "${FILES[@]}"
|
|
do
|
|
# Check if file exists
|
|
FILE_NAME=$(basename "$FILE")
|
|
URL="${GITEA_BASEURL}/api/packages/${GITEA_OWNER}/generic/${PACKAGE_NAME}/${PACKAGE_VERSION}/${FILE_NAME}"
|
|
response=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
--user "${GITEA_USERNAME}:${GITEA_TOKEN}" \
|
|
"$URL")
|
|
|
|
if [ "$response" == "200" ]; then
|
|
echo "File $FILE_NAME already exists. Skipping..."
|
|
continue
|
|
fi
|
|
|
|
# Upload new file
|
|
echo "Uploading file $FILE_NAME..."
|
|
URL="${GITEA_BASEURL}/api/packages/${GITEA_OWNER}/generic/${PACKAGE_NAME}/${PACKAGE_VERSION}/${FILE_NAME}"
|
|
curl --user "${GITEA_USERNAME}:${GITEA_TOKEN}" \
|
|
--upload-file "$FILE" --fail \
|
|
--progress-bar --output /dev/stderr \
|
|
"$URL"
|
|
if [ $? -eq 0 ]; then
|
|
echo "File $FILE_NAME successfully uploaded."
|
|
else
|
|
echo "Uploading $FILE_NAME failed!"
|
|
fi
|
|
done
|
|
|
|
# Query all files
|
|
UPLOADED_FILES=$(curl -s --user "${GITEA_USERNAME}:${GITEA_TOKEN}" \
|
|
"${GITEA_BASEURL}/api/v1/packages/${GITEA_OWNER}/generic/${PACKAGE_NAME}/${PACKAGE_VERSION}/files")
|
|
|
|
# Display the list of uploaded files in table format
|
|
echo -e "\nCurrent files in package ${PACKAGE_NAME} (${IMAGE_VARIANT}):"
|
|
echo "$UPLOADED_FILES" | jq -r '.[] | "- \(.name)"'
|
|
|
|
# Display total count of files
|
|
TOTAL_COUNT=$(echo "$UPLOADED_FILES" | jq -r 'length')
|
|
echo -e "\nTotal count of files: $TOTAL_COUNT" |