From 2918905b9bcad205aa9562e907cd0cff1dde9bc5 Mon Sep 17 00:00:00 2001 From: Adam Piasecki Date: Apr 04 2022 18:04:16 +0000 Subject: 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]}"