pgreco / centos-git-common

Forked from centos-git-common 5 years ago
Clone

Blame lookaside_upload

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
9023a8
lookaside_baseurl="https://git.stg.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"
353eaf
result=$(curl ${lookaside_baseurl}/sources/upload.cgi \
353eaf
	--fail \
353eaf
	-s \
353eaf
	--cert ~/.centos.cert \
353eaf
	--form "name=${pkgname}" \
353eaf
	--form "branch=${branch}" \
353eaf
	--form "sha1sum=${checksum}")
353eaf
353eaf
if [ "$result" = "Available" ] ;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
9023a8
f_log "Returned value: $?"
9023a8
f_log "Source should be available at ${lookaside_baseurl}/sources/${pkgname}/${branch}/${checksum}"
9023a8