Skip to content

Instantly share code, notes, and snippets.

@chris1984
Last active September 23, 2022 13:27
Show Gist options
  • Save chris1984/7d2a03df1bff749d7b8d1bf7766379e9 to your computer and use it in GitHub Desktop.
Save chris1984/7d2a03df1bff749d7b8d1bf7766379e9 to your computer and use it in GitHub Desktop.
upload_package_to_repo.sh
if [ $# -lt 2 ]; then
echo "too few arguments"
exit
fi
repoid=${1}
package=${2}
pkgname=${package##*/}
creds=admin:redhat
saturl=$(hostname -f)
size=$(wc -c $package | awk '{ print $1}')
checksum=$(sha256sum $package | awk '{ print $1}')
upload_url=$(curl --header "Accept:application/json" \
--header "Content-Type:application/json" \
--request POST --insecure --user $creds \
--data "{\"size\": ${size}}" \
https://${saturl}/katello/api/repositories/${repoid}/content_uploads | cut -d\" -f4 )
curl --header "Accept:application/json" \
--header "Content-Type:multipart/form-data" \
--request PUT --insecure --user $creds \
--data-urlencode "content@${package}" \
--data-urlencode offset=0 \
--data-urlencode size=${size} \
https://${saturl}/katello/api/repositories/${repoid}/content_uploads/${upload_url}
curl --header "Accept:application/json" \
--header "Content-Type:application/json" \
--request PUT --insecure \
--user $creds \
--data "{\"uploads\":[{\"id\": \"${upload_url}\", \"name\": \"${pkgname}\"}]}" \
https://${saturl}/katello/api/repositories/${repoid}/import_uploads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment