Blame SOURCES/lookaside_upload

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