From 03f8bc4c7e32351e3dcf0a48242f2200259b6977 Mon Sep 17 00:00:00 2001 From: Adam Piasecki Date: Apr 04 2022 10:39:26 +0000 Subject: [PATCH 1/5] Created simple lookaside_upload_sig --- diff --git a/lookaside_upload_sig b/lookaside_upload_sig new file mode 100755 index 0000000..abc99c8 --- /dev/null +++ b/lookaside_upload_sig @@ -0,0 +1,187 @@ +#!/bin/bash + +# This script will let you upload sources/blobs to new CentOS lookaside cache +# requirements: +# - curl +# - valid TLS certs from https://accounts.centos.org (or dev instance for testing) +# - valid group membership to let you upload to specific "branch" + +# Some variables, switch for new url +lookaside_baseurl="https://git.centos.org" + +function usage { + +cat << EOF + +You need to call the script like this : $0 -arguments + + -f : filename/source to upload (required, default:none) + -a : hash parameter (optional, default: none, example "b6804fa") + -n : package name for that source (requred, default:none, example "httpd") + -b : "branch" where to upload to (optional, default:none, example "c7-sig-core") + -h : display this help +As far as branch and hash parameters are optional, one of these needs to be specified. + +EOF + +} + +function varcheck { +if [ -z "$1" ] ; then + usage + exit 1 +fi + +} + +function f_log { + echo "[+] CentOS Lookaside upload tool -> $*" +} + + +while getopts “hf:a:n:b:” OPTION +do + case $OPTION in + h) + usage + exit 1 + ;; + a) + hash=$OPTARG + ;; + f) + file=$OPTARG + ;; + n) + pkgname=$OPTARG + ;; + b) + branch=$OPTARG + ;; + ?) + usage + exit + ;; + esac +done + +varcheck $file +varcheck $hash +varcheck $pkgname +varcheck $branch + +if [ ! -f ~/.centos.cert ] ;then + f_log "No mandatory TLS cert found (~/.centos.cert) .." + f_log "please use centos-cert to retrieve your ACO TLS cert" + exit 1 +fi + +if [ ! -f "${file}" ] ;then + f_log "Source to upload ${file} not found" + exit 2 +fi + +checksum=$(sha1sum ${file}|awk '{print $1}') + +f_log "Checking if file already uploaded" +local_size=$(stat -c %s ${file}) + +# -z parameter optional # + +if [ -z "${branch}" ] ;then + f_log "Branch parameter not given" + http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${checksum}) + remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') + exit 0 +else + http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}) + remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') +fi + + +if [ "$http_code" -eq 200 ] && [ "$local_size" -eq "$remote_size" ] ; then + f_log "File already uploaded" + exit 3 +fi + +f_log "Initialing new upload to lookaside" +f_log "URL : $lookaside_baseurl" +f_log "Source to upload : ${file} " + +if [ -z "${hash}" ]; then + f_log "No hash parameter was specified" +else + f_log "Hash parameter : ${hash}" +fi + +f_log "Package name: $pkgname" +f_log "sha1sum: ${checksum}" + +# Ugly way of implementing conditional parameter + +if [ -z "${branch}" && "${hash}" -gt 0 ] ;then + f_log "Remote branch not specified" + f_log " ====== Trying to upload =======" + echo "" + curl ${lookaside_baseurl}/sources/upload.cgi \ + --fail \ + --cert ~/.centos.cert \ + --form "name=${pkgname}" \ + --form "hash=${hash}" \ + --form "sha1sum=${checksum}" \ + --form "file=@${file}" \ + --progress-bar | tee /dev/null \ +# Saving a copy + > lookaside_upload_sig + + upload_result="${PIPESTATUS[0]}" + + if [ "$upload_result" -ne "0" ] ;then + f_log "[ERROR] Something didn't work to push to ${lookaside_baseurl}/sources/${pkgname}/${checksum}" + f_log "[ERROR] Verify at the server side" + exit 1 + fi + + f_log "Validating that source was correctly uploaded ...." + remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') + if [ "$local_size" -eq "$remote_size" ] ; then + f_log "[SUCCESS] Source should be available at ${lookaside_baseurl}/sources/${pkgname}/${checksum}" + else + f_log "[ERROR] it seems there is a mismatch with source size and remote file size" + fi +elif [ -z "${hash}" && "${branch}" -gt 0 ] ;then + f_log "Remote branch: ${branch}" + f_log " ====== Trying to upload =======" + echo "" + + curl ${lookaside_baseurl}/sources/upload.cgi \ + --fail \ + --cert ~/.centos.cert \ + --form "name=${pkgname}" \ + --form "branch=${branch}" \ + --form "sha1sum=${checksum}" \ + --form "file=@${file}" \ + --progress-bar | tee /dev/null + + # Saving a copy + > lookaside_upload_sig + + upload_result="${PIPESTATUS[0]}" + + if [ "$upload_result" -ne "0" ] ;then + f_log "[ERROR] Something didn't work to push to ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}" + f_log "[ERROR] Verify at the server side" + exit 1 + fi + + f_log "Validating that source was correctly uploaded ...." + remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') + if [ "$local_size" -eq "$remote_size" ] ; then + f_log "[SUCCESS] Source should be available at ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}" + else + f_log "[ERROR] it seems there is a mismatch with source size and remote file size" + fi +else + f_log "[ERROR] Neither branch or hash parameters were specified" + exit 1 +fi From 2918905b9bcad205aa9562e907cd0cff1dde9bc5 Mon Sep 17 00:00:00 2001 From: Adam Piasecki Date: Apr 04 2022 18:04:16 +0000 Subject: [PATCH 2/5] Implemented suggested changes to lookaside_upload_sig --- diff --git a/lookaside_upload_sig b/lookaside_upload_sig index abc99c8..399db77 100755 --- a/lookaside_upload_sig +++ b/lookaside_upload_sig @@ -64,11 +64,15 @@ do ;; esac done - + +if [ -z "${hash}" && -z "${branch}" ] ;then + f_log "Neither -a hash or -b branch parameters were provided." + usage + exit 1 +fi + varcheck $file -varcheck $hash varcheck $pkgname -varcheck $branch if [ ! -f ~/.centos.cert ] ;then f_log "No mandatory TLS cert found (~/.centos.cert) .." @@ -81,8 +85,12 @@ if [ ! -f "${file}" ] ;then exit 2 fi -checksum=$(sha1sum ${file}|awk '{print $1}') - +if [ -n "${hash}" ]; then + checksum=${hash} +else + checksum=$(sha1sum ${file}|awk '{print $1}') +fi + f_log "Checking if file already uploaded" local_size=$(stat -c %s ${file}) @@ -90,12 +98,12 @@ local_size=$(stat -c %s ${file}) if [ -z "${branch}" ] ;then f_log "Branch parameter not given" - http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${checksum}) - remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') + http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${hash}/${checksum}) + remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${hash}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') exit 0 else - http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}) - remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') + http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${hash}/${checksum}) + remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${hash}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') fi @@ -107,13 +115,7 @@ fi f_log "Initialing new upload to lookaside" f_log "URL : $lookaside_baseurl" f_log "Source to upload : ${file} " - -if [ -z "${hash}" ]; then - f_log "No hash parameter was specified" -else - f_log "Hash parameter : ${hash}" -fi - +f_log "Hash parameter : ${hash}" f_log "Package name: $pkgname" f_log "sha1sum: ${checksum}" @@ -122,13 +124,15 @@ f_log "sha1sum: ${checksum}" if [ -z "${branch}" && "${hash}" -gt 0 ] ;then f_log "Remote branch not specified" f_log " ====== Trying to upload =======" - echo "" - curl ${lookaside_baseurl}/sources/upload.cgi \ + echo "" + # Concatenating sha256 + hash_cmd="$(hash) $(sha1sum ${file}|awk '{print $1}')" + curl ${lookaside_baseurl}/sources/upload_sig.cgi \ --fail \ --cert ~/.centos.cert \ --form "name=${pkgname}" \ --form "hash=${hash}" \ - --form "sha1sum=${checksum}" \ + --form "sha1sum=${hash_cmd}" \ --form "file=@${file}" \ --progress-bar | tee /dev/null \ # Saving a copy @@ -145,7 +149,7 @@ if [ -z "${branch}" && "${hash}" -gt 0 ] ;then f_log "Validating that source was correctly uploaded ...." remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') if [ "$local_size" -eq "$remote_size" ] ; then - f_log "[SUCCESS] Source should be available at ${lookaside_baseurl}/sources/${pkgname}/${checksum}" + f_log "[SUCCESS] Source should be available at ${lookaside_baseurl}/sources/${pkgname}/${hash}/${checksum}" else f_log "[ERROR] it seems there is a mismatch with source size and remote file size" fi @@ -164,7 +168,7 @@ elif [ -z "${hash}" && "${branch}" -gt 0 ] ;then --progress-bar | tee /dev/null # Saving a copy - > lookaside_upload_sig + > lookaside_upload upload_result="${PIPESTATUS[0]}" From bb01e710ed1e5a7300fe0001434bb99b20446da7 Mon Sep 17 00:00:00 2001 From: Adam Piasecki Date: Apr 05 2022 16:15:17 +0000 Subject: [PATCH 3/5] Modified lookaside_upload_sig file based on received feedback --- diff --git a/lookaside_upload_sig b/lookaside_upload_sig index 399db77..438a2e8 100755 --- a/lookaside_upload_sig +++ b/lookaside_upload_sig @@ -7,30 +7,36 @@ # - valid group membership to let you upload to specific "branch" # Some variables, switch for new url -lookaside_baseurl="https://git.centos.org" +lookaside_baseurl=$LOOKASIDE_BASEURL + +if [ -z $LOOKASIDE_BASEURL ];then + lookaside_baseurl="https://git.centos.org" + echo "Base URL set to default: $lookaside_baseurl" +fi function usage { - -cat << EOF -You need to call the script like this : $0 -arguments - - -f : filename/source to upload (required, default:none) - -a : hash parameter (optional, default: none, example "b6804fa") - -n : package name for that source (requred, default:none, example "httpd") - -b : "branch" where to upload to (optional, default:none, example "c7-sig-core") - -h : display this help -As far as branch and hash parameters are optional, one of these needs to be specified. + cat << EOF + + You need to call the script like this : $0 -arguments + + -f : filename/source to upload (required, default:none) + -a : hash parameter (optional, default: none, example "b6804fa") + -n : package name for that source (requred, default:none, example "httpd") + -b : "branch" where to upload to (optional, default:none, example "c7-sig-core") + -h : display this help + As far as branch and hash parameters are optional, one of them need to be specified. + It is also possible to amend the default base url (currently set to https://git.centos.org): + LOOKASIDE_BASEURL= ./lookaside_upload_sig ... EOF - } function varcheck { -if [ -z "$1" ] ; then - usage - exit 1 -fi + if [ -z "$1" ] ; then + usage + exit 1 + fi } @@ -65,7 +71,7 @@ do esac done -if [ -z "${hash}" && -z "${branch}" ] ;then +if [ -z "${hash}" ] && [ -z "${branch}" ] ;then f_log "Neither -a hash or -b branch parameters were provided." usage exit 1 @@ -86,7 +92,7 @@ if [ ! -f "${file}" ] ;then fi if [ -n "${hash}" ]; then - checksum=${hash} + checksum="$(${hash}sum ${file}|awk '{print $1}')" else checksum=$(sha1sum ${file}|awk '{print $1}') fi @@ -98,12 +104,11 @@ local_size=$(stat -c %s ${file}) if [ -z "${branch}" ] ;then f_log "Branch parameter not given" - http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${hash}/${checksum}) - remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${hash}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') - exit 0 + http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash}/${checksum}) + remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') else - http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${hash}/${checksum}) - remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${hash}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') + http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}) + remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') fi @@ -111,7 +116,7 @@ if [ "$http_code" -eq 200 ] && [ "$local_size" -eq "$remote_size" ] ; then f_log "File already uploaded" exit 3 fi - + f_log "Initialing new upload to lookaside" f_log "URL : $lookaside_baseurl" f_log "Source to upload : ${file} " @@ -121,22 +126,20 @@ f_log "sha1sum: ${checksum}" # Ugly way of implementing conditional parameter -if [ -z "${branch}" && "${hash}" -gt 0 ] ;then +if [ -z "${branch}" ] && [ !-z"${hash}" ]; then f_log "Remote branch not specified" f_log " ====== Trying to upload =======" echo "" # Concatenating sha256 - hash_cmd="$(hash) $(sha1sum ${file}|awk '{print $1}')" + hash_cmd="$(${hash}sum ${file}|awk '{print $1}')" curl ${lookaside_baseurl}/sources/upload_sig.cgi \ --fail \ --cert ~/.centos.cert \ --form "name=${pkgname}" \ --form "hash=${hash}" \ - --form "sha1sum=${hash_cmd}" \ + --form "${hash}sum=${hash_cmd}" \ --form "file=@${file}" \ --progress-bar | tee /dev/null \ -# Saving a copy - > lookaside_upload_sig upload_result="${PIPESTATUS[0]}" @@ -147,13 +150,13 @@ if [ -z "${branch}" && "${hash}" -gt 0 ] ;then fi f_log "Validating that source was correctly uploaded ...." - remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') + remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') if [ "$local_size" -eq "$remote_size" ] ; then - f_log "[SUCCESS] Source should be available at ${lookaside_baseurl}/sources/${pkgname}/${hash}/${checksum}" + f_log "[SUCCESS] Source should be available at ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash}/${checksum}" else f_log "[ERROR] it seems there is a mismatch with source size and remote file size" fi -elif [ -z "${hash}" && "${branch}" -gt 0 ] ;then +elif [ -z "${hash}" ] && [ !-z"${branch}" ] ;then f_log "Remote branch: ${branch}" f_log " ====== Trying to upload =======" echo "" @@ -166,9 +169,6 @@ elif [ -z "${hash}" && "${branch}" -gt 0 ] ;then --form "sha1sum=${checksum}" \ --form "file=@${file}" \ --progress-bar | tee /dev/null - - # Saving a copy - > lookaside_upload upload_result="${PIPESTATUS[0]}" From 050ddddbeb8e7a89dce0dc1606173581f2705b88 Mon Sep 17 00:00:00 2001 From: Adam Piasecki Date: Apr 21 2022 20:56:51 +0000 Subject: [PATCH 4/5] Removed the branch element from the script and forced use of SHA512 algorithm --- diff --git a/lookaside_upload_sig b/lookaside_upload_sig index 438a2e8..d0942fc 100755 --- a/lookaside_upload_sig +++ b/lookaside_upload_sig @@ -1,191 +1,124 @@ #!/bin/bash - + # This script will let you upload sources/blobs to new CentOS lookaside cache # requirements: # - curl # - valid TLS certs from https://accounts.centos.org (or dev instance for testing) # - valid group membership to let you upload to specific "branch" - + # Some variables, switch for new url lookaside_baseurl=$LOOKASIDE_BASEURL +hash_parameter="sha512" -if [ -z $LOOKASIDE_BASEURL ];then - lookaside_baseurl="https://git.centos.org" - echo "Base URL set to default: $lookaside_baseurl" +if [ -z $LOOKASIDE_BASEURL ]; then + lookaside_baseurl="https://git.centos.org" + echo "Base URL set to default: $lookaside_baseurl" fi - + function usage { - cat << EOF + cat < ./lookaside_upload_sig ... + It is also possible to amend the default base url (currently set to https://git.centos.org): + LOOKASIDE_BASEURL= ./lookaside_upload_sig ... EOF } - + function varcheck { - if [ -z "$1" ] ; then - usage - exit 1 - fi - + if [ -z "$1" ]; then + usage + exit 1 + fi + } - + function f_log { - echo "[+] CentOS Lookaside upload tool -> $*" + echo "[+] CentOS Lookaside upload tool -> $*" } - - -while getopts “hf:a:n:b:” OPTION -do - case $OPTION in - h) - usage - exit 1 - ;; - a) - hash=$OPTARG - ;; - f) - file=$OPTARG - ;; - n) - pkgname=$OPTARG - ;; - b) - branch=$OPTARG - ;; - ?) - usage - exit - ;; - esac -done -if [ -z "${hash}" ] && [ -z "${branch}" ] ;then - f_log "Neither -a hash or -b branch parameters were provided." - usage - exit 1 -fi +while getopts “hf:n:” OPTION; do + case $OPTION in + h) + usage + exit 1 + ;; + f) + file=$OPTARG + ;; + n) + pkgname=$OPTARG + ;; + ?) + usage + exit + ;; + esac +done varcheck $file varcheck $pkgname - -if [ ! -f ~/.centos.cert ] ;then - f_log "No mandatory TLS cert found (~/.centos.cert) .." - f_log "please use centos-cert to retrieve your ACO TLS cert" - exit 1 -fi - -if [ ! -f "${file}" ] ;then - f_log "Source to upload ${file} not found" - exit 2 + +if [ ! -f ~/.centos.cert ]; then + f_log "No mandatory TLS cert found (~/.centos.cert) .." + f_log "please use centos-cert to retrieve your ACO TLS cert" + exit 1 fi -if [ -n "${hash}" ]; then - checksum="$(${hash}sum ${file}|awk '{print $1}')" -else - checksum=$(sha1sum ${file}|awk '{print $1}') +if [ ! -f "${file}" ]; then + f_log "Source to upload ${file} not found" + exit 2 fi +checksum="$(${hash_parameter}sum ${file} | awk '{print $1}')" + f_log "Checking if file already uploaded" local_size=$(stat -c %s ${file}) +http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash_parameter}/${checksum}) +remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash_parameter}/${checksum} | grep "Content-Length" | cut -f 2 -d ':' | tr -d [:blank:] | tr -d '\r') -# -z parameter optional # - -if [ -z "${branch}" ] ;then - f_log "Branch parameter not given" - http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash}/${checksum}) - remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') -else - http_code=$(curl -s -o /dev/null -w "%{http_code}" ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}) - remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') -fi - - -if [ "$http_code" -eq 200 ] && [ "$local_size" -eq "$remote_size" ] ; then - f_log "File already uploaded" - exit 3 +if [ "$http_code" -eq 200 ] && [ "$local_size" -eq "$remote_size" ]; then + f_log "File already uploaded" + exit 3 fi f_log "Initialing new upload to lookaside" f_log "URL : $lookaside_baseurl" f_log "Source to upload : ${file} " -f_log "Hash parameter : ${hash}" +f_log "Hash parameter : ${hash_parameter}" f_log "Package name: $pkgname" f_log "sha1sum: ${checksum}" +f_log " ====== Trying to upload =======" +echo "" + +# Concatenating sha512 +hash_cmd="$(${hash_parameter}sum ${file} | awk '{print $1}')" +curl ${lookaside_baseurl}/sources/upload_sig.cgi \ + --fail \ + --cert ~/.centos.cert \ + --form "name=${pkgname}" \ + --form "hash=${hash_parameter}" \ + --form "${hash_parameter}sum=${hash_cmd}" \ + --form "file=@${file}" \ + --progress-bar | tee /dev/null + +upload_result="${PIPESTATUS[0]}" + +if [ "$upload_result" -ne "0" ]; then + f_log "[ERROR] Something didn't work to push to ${lookaside_baseurl}/sources/${pkgname}/${checksum}" + f_log "[ERROR] Verify at the server side" + exit 1 +fi -# Ugly way of implementing conditional parameter - -if [ -z "${branch}" ] && [ !-z"${hash}" ]; then - f_log "Remote branch not specified" - f_log " ====== Trying to upload =======" - echo "" - # Concatenating sha256 - hash_cmd="$(${hash}sum ${file}|awk '{print $1}')" - curl ${lookaside_baseurl}/sources/upload_sig.cgi \ - --fail \ - --cert ~/.centos.cert \ - --form "name=${pkgname}" \ - --form "hash=${hash}" \ - --form "${hash}sum=${hash_cmd}" \ - --form "file=@${file}" \ - --progress-bar | tee /dev/null \ - - upload_result="${PIPESTATUS[0]}" - - if [ "$upload_result" -ne "0" ] ;then - f_log "[ERROR] Something didn't work to push to ${lookaside_baseurl}/sources/${pkgname}/${checksum}" - f_log "[ERROR] Verify at the server side" - exit 1 - fi - - f_log "Validating that source was correctly uploaded ...." - remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') - if [ "$local_size" -eq "$remote_size" ] ; then - f_log "[SUCCESS] Source should be available at ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash}/${checksum}" - else - f_log "[ERROR] it seems there is a mismatch with source size and remote file size" - fi -elif [ -z "${hash}" ] && [ !-z"${branch}" ] ;then - f_log "Remote branch: ${branch}" - f_log " ====== Trying to upload =======" - echo "" - - curl ${lookaside_baseurl}/sources/upload.cgi \ - --fail \ - --cert ~/.centos.cert \ - --form "name=${pkgname}" \ - --form "branch=${branch}" \ - --form "sha1sum=${checksum}" \ - --form "file=@${file}" \ - --progress-bar | tee /dev/null - - upload_result="${PIPESTATUS[0]}" - - if [ "$upload_result" -ne "0" ] ;then - f_log "[ERROR] Something didn't work to push to ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}" - f_log "[ERROR] Verify at the server side" - exit 1 - fi - - f_log "Validating that source was correctly uploaded ...." - remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}|grep "Content-Length"|cut -f 2 -d ':'|tr -d [:blank:]|tr -d '\r') - if [ "$local_size" -eq "$remote_size" ] ; then - f_log "[SUCCESS] Source should be available at ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}" - else - f_log "[ERROR] it seems there is a mismatch with source size and remote file size" - fi +f_log "Validating that source was correctly uploaded ...." +remote_size=$(curl --silent -i --head ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash}/${checksum} | grep "Content-Length" | cut -f 2 -d ':' | tr -d [:blank:] | tr -d '\r') +if [ "$local_size" -eq "$remote_size" ]; then + f_log "[SUCCESS] Source should be available at ${lookaside_baseurl}/sources/${pkgname}/${file}/${hash}/${checksum}" else - f_log "[ERROR] Neither branch or hash parameters were specified" - exit 1 + f_log "[ERROR] it seems there is a mismatch with source size and remote file size" fi From 792d9ae9609f81d62a358d28c7846de3bd72e3c8 Mon Sep 17 00:00:00 2001 From: Adam Piasecki Date: Apr 22 2022 08:06:50 +0000 Subject: [PATCH 5/5] Modified comment section --- diff --git a/lookaside_upload_sig b/lookaside_upload_sig index d0942fc..7547647 100755 --- a/lookaside_upload_sig +++ b/lookaside_upload_sig @@ -4,7 +4,6 @@ # requirements: # - curl # - valid TLS certs from https://accounts.centos.org (or dev instance for testing) -# - valid group membership to let you upload to specific "branch" # Some variables, switch for new url lookaside_baseurl=$LOOKASIDE_BASEURL