X-Git-Url: https://git.tld-linux.org/?p=TLD.git;a=blobdiff_plain;f=pld-builder.new%2Fclient%2Fmake-request.sh;fp=pld-builder.new%2Fclient%2Fmake-request.sh;h=35b94f9fe5fb374a19cc61a12cb0f51ffdfb3cc6;hp=0000000000000000000000000000000000000000;hb=90809c8fec988489786ce00247d9a4150070748b;hpb=ab3934fab858112cd552359b18cb980ea07c310b diff --git a/pld-builder.new/client/make-request.sh b/pld-builder.new/client/make-request.sh new file mode 100755 index 0000000..35b94f9 --- /dev/null +++ b/pld-builder.new/client/make-request.sh @@ -0,0 +1,788 @@ +#!/bin/sh + +# prevent "*" from being expanded in builders var +set -f + +builders= +with= +without= +flags= +command= +command_flags= +gpg_opts= +default_branch='HEAD' +dist= +url= +no_depend=no +verbose=no +autotag=no + +if [ -x /usr/bin/python ]; then + send_mode="python" +else + echo "No python present, using mail mode" + send_mode="mail" +fi + +if [ -n "$HOME_ETC" ]; then + USER_CFG=$HOME_ETC/.requestrc +else + USER_CFG=$HOME/.requestrc +fi + +if [ ! -f "$USER_CFG" ]; then + echo "Creating config file $USER_CFG. You *must* edit it." + cat > $USER_CFG <&2 "${c_star}*${c_norm} $*" +} +red() { + echo "${c_red}$*${c_norm}" +} + +die() { + echo >&2 "$0: $*" + exit 1 +} + +send_request() { + # switch to mail mode, if no url set + [ -z "$url" ] && send_mode="mail" + + case "$send_mode" in + "mail") + msg "Sending using mail mode" + cat - | $mailer + ;; + *) + msg "Sending using http mode to $url" + cat - | python -c ' +import sys, socket, urllib2 + +try: + data = sys.stdin.read() + url = sys.argv[1] + socket.setdefaulttimeout(10) + req = urllib2.Request(url, data) + f = urllib2.urlopen(req) + f.close() +except Exception, e: + print >> sys.stderr, "Problem while sending request via HTTP: %s: %s" % (url, e) + sys.exit(1) +print >> sys.stdout, "Request queued via HTTP." +' "$url" + ;; + esac +} + +# simple df_fetcher, based on packages/fetchsrc_request +# TODO: tcp (smtp) mode +# TODO: adjust for ~/.requestrc config +df_fetch() { + local specs="$@" + + # Sending by + local MAILER='/usr/sbin/sendmail' + # MAILER='/usr/bin/msmtp' + # Sending via + local VIA="SENDMAIL" + #VIA="localhost" + local VIA_ARGS="" + #VIA_ARGS="some additional flags" + # e.g. for msmtp: + # VIA_ARGS='-a gmail' + # + # DISTFILES EMAIL + local DMAIL="distfiles@pld-linux.org" + + local HOST=$(hostname -f) + local LOGIN=${requester%@*} + + for spec in $specs; do + local SPEC=$(echo "$spec" | sed -e 's|:.*||') + local BRANCH=$(echo "$spec" | sed -e 's|.*:||') + echo >&2 "Distfiles Request: $SPEC:$BRANCH via $MAILER ${VIA_ARGS:+ ($VIA_ARGS)}" + cat <<-EOF | "$MAILER" -t -i $VIA_ARGS + To: $DMAIL + From: $LOGIN <$LOGIN@$HOST> + Subject: fetchsrc_request notify + X-CVS-Module: SPECS + X-distfiles-request: yes + X-Login: $LOGIN + X-Spec: $SPEC + X-Branch: $BRANCH + X-Flags: force-reply + + . + EOF + done +} + +# autotag from rpm-build-macros +# displays latest used tag for a specfile +autotag() { + local out s + for s in "$@"; do + # strip branches + s=${s%:*} + # ensure package ends with .spec + s=${s%.spec}.spec + out=$(cvs status -v $s | awk "!/Sticky/&&/auto-$dist-/{if (!a++) print \$1}") + echo "$s:$out" + done +} + +# get autotag for specs +# WARNING: This may checkout some files from CVS +get_autotag() { + local pkg spec rpmdir + + rpmdir=$(rpm -E %_topdir) + cd $rpmdir + for pkg in "$@"; do + # strip branches + pkg=${pkg%:*} + # strip .spec extension + pkg=${pkg%.spec} + # checkout only if missing + if [ ! -e $pkg/$pkg.spec ]; then + $rpmdir/builder -g $pkg -ns -r HEAD 1>&2 + fi + if [ ! -e $pkg/$pkg.spec ]; then + # just print it out, to fallback to base pkg name + echo "$pkg" + else + autotag $pkg/$pkg.spec + fi + done +} + +usage() { + cat <