Modified lookaside_upload_sig file based on received feedback

This commit is contained in:
Adam Piasecki 2022-04-05 17:15:17 +01:00
parent 2918905b9b
commit bb01e710ed

View file

@ -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
cat << EOF
You need to call the script like this : $0 -arguments
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.
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=<urlOfYourChoice> ./lookaside_upload_sig ...
EOF
}
function varcheck {
if [ -z "$1" ] ; then
if [ -z "$1" ] ; then
usage
exit 1
fi
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
@ -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 ""
@ -167,9 +170,6 @@ elif [ -z "${hash}" && "${branch}" -gt 0 ] ;then
--form "file=@${file}" \
--progress-bar | tee /dev/null
# Saving a copy
> lookaside_upload
upload_result="${PIPESTATUS[0]}"
if [ "$upload_result" -ne "0" ] ;then