|
|
9023a8 |
#!/bin/bash
|
|
|
9023a8 |
|
|
|
9023a8 |
# This script will let you upload sources/blobs to new CentOS lookaside cache
|
|
|
9023a8 |
# requirements:
|
|
|
9023a8 |
# - curl
|
|
|
9023a8 |
# - valid TLS certs from https://accounts.centos.org (or dev instance for testing)
|
|
|
9023a8 |
# - valid group membership to let you upload to specific "branch"
|
|
|
9023a8 |
|
|
|
9023a8 |
# Some variables, switch for new url
|
|
|
e575c2 |
lookaside_baseurl="https://git.centos.org"
|
|
|
9023a8 |
|
|
|
9023a8 |
function usage {
|
|
|
9023a8 |
|
|
|
9023a8 |
cat << EOF
|
|
|
9023a8 |
|
|
|
9023a8 |
You need to call the script like this : $0 -arguments
|
|
|
9023a8 |
|
|
|
9023a8 |
-f : filename/source to upload (required, default:none)
|
|
|
9023a8 |
-n : package name for that source (requred, default:none, example "httpd")
|
|
|
9023a8 |
-b : "branch" where to upload to (required, default:none, example "c7-sig-core")
|
|
|
9023a8 |
-h : display this help
|
|
|
9023a8 |
|
|
|
9023a8 |
EOF
|
|
|
9023a8 |
|
|
|
9023a8 |
}
|
|
|
9023a8 |
|
|
|
9023a8 |
function varcheck {
|
|
|
9023a8 |
if [ -z "$1" ] ; then
|
|
|
9023a8 |
usage
|
|
|
9023a8 |
exit 1
|
|
|
9023a8 |
fi
|
|
|
9023a8 |
|
|
|
9023a8 |
}
|
|
|
9023a8 |
|
|
|
9023a8 |
function f_log {
|
|
|
9023a8 |
echo "[+] CentOS Lookaside upload tool -> $*"
|
|
|
9023a8 |
}
|
|
|
9023a8 |
|
|
|
9023a8 |
|
|
|
9023a8 |
|
|
|
9023a8 |
while getopts “hf:n:b:” OPTION
|
|
|
9023a8 |
do
|
|
|
9023a8 |
case $OPTION in
|
|
|
9023a8 |
h)
|
|
|
9023a8 |
usage
|
|
|
9023a8 |
exit 1
|
|
|
9023a8 |
;;
|
|
|
9023a8 |
f)
|
|
|
9023a8 |
file=$OPTARG
|
|
|
9023a8 |
;;
|
|
|
9023a8 |
n)
|
|
|
9023a8 |
pkgname=$OPTARG
|
|
|
9023a8 |
;;
|
|
|
9023a8 |
b)
|
|
|
9023a8 |
branch=$OPTARG
|
|
|
9023a8 |
;;
|
|
|
9023a8 |
?)
|
|
|
9023a8 |
usage
|
|
|
9023a8 |
exit
|
|
|
9023a8 |
;;
|
|
|
9023a8 |
esac
|
|
|
9023a8 |
done
|
|
|
9023a8 |
|
|
|
9023a8 |
varcheck $file
|
|
|
9023a8 |
varcheck $pkgname
|
|
|
9023a8 |
varcheck $branch
|
|
|
9023a8 |
|
|
|
9023a8 |
if [ ! -f ~/.centos.cert ] ;then
|
|
|
9023a8 |
f_log "No mandatory TLS cert found (~/.centos.cert) .."
|
|
|
9023a8 |
f_log "please use centos-cert to retrieve your ACO TLS cert"
|
|
|
9023a8 |
exit 1
|
|
|
9023a8 |
fi
|
|
|
9023a8 |
|
|
|
353eaf |
if [ ! -f "${file}" ] ;then
|
|
|
353eaf |
f_log "Source to upload ${file} not found"
|
|
|
353eaf |
exit 2
|
|
|
353eaf |
fi
|
|
|
353eaf |
|
|
|
9023a8 |
checksum=$(sha1sum ${file}|awk '{print $1}')
|
|
|
353eaf |
|
|
|
353eaf |
f_log "Checking if file already uploaded"
|
|
Pablo Greco |
b04595 |
local_size=$(stat -c %s ${file})
|
|
Pablo Greco |
b04595 |
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')
|
|
Pablo Greco |
b04595 |
if [ "$local_size" -eq "$remote_size" ] ; then
|
|
|
353eaf |
f_log "File already uploaded"
|
|
|
353eaf |
exit 3
|
|
|
353eaf |
fi
|
|
|
353eaf |
|
|
|
353eaf |
f_log "Initialing new upload to lookaside"
|
|
|
9023a8 |
f_log "URL : $lookaside_baseurl"
|
|
|
9023a8 |
f_log "Source to upload : ${file} "
|
|
|
9023a8 |
f_log "Package name: $pkgname"
|
|
|
9023a8 |
f_log "sha1sum: ${checksum}"
|
|
|
9023a8 |
f_log "Remote branch: ${branch}"
|
|
|
9023a8 |
f_log " ====== Trying to upload ======="
|
|
|
9023a8 |
echo ""
|
|
|
9023a8 |
curl ${lookaside_baseurl}/sources/upload.cgi \
|
|
|
9023a8 |
--fail \
|
|
|
9023a8 |
--cert ~/.centos.cert \
|
|
|
9023a8 |
--form "name=${pkgname}" \
|
|
|
9023a8 |
--form "branch=${branch}" \
|
|
|
9023a8 |
--form "sha1sum=${checksum}" \
|
|
|
9023a8 |
--form "file=@${file}" \
|
|
|
9023a8 |
--progress-bar | tee /dev/null
|
|
|
9023a8 |
|
|
|
e6e12e |
upload_result="${PIPESTATUS[0]}"
|
|
|
e6e12e |
|
|
|
e6e12e |
if [ "$upload_result" -ne "0" ] ;then
|
|
|
e6e12e |
f_log "[ERROR] Something didn't work to push to ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}"
|
|
|
e6e12e |
f_log "[ERROR] Verify at the server side"
|
|
|
e6e12e |
exit 1
|
|
|
e6e12e |
fi
|
|
|
e6e12e |
|
|
|
c43fda |
f_log "Validating that source was correctly uploaded ...."
|
|
|
c43fda |
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')
|
|
|
c43fda |
if [ "$local_size" -eq "$remote_size" ] ; then
|
|
|
e6e12e |
f_log "[SUCCESS] Source should be available at ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}"
|
|
|
c43fda |
else
|
|
|
e6e12e |
f_log "[ERROR] it seems there is a mismatch with source size and remote file size"
|
|
|
c43fda |
fi
|
|
|
c43fda |
|
|
|
9023a8 |
|