]> TLD Linux GIT Repositories - tld-builder.git/blobdiff - client/make-request.sh
- use builtin urllib instead of urllib3
[tld-builder.git] / client / make-request.sh
index d73c08ab19df1ae1b7db69cd5fa97d0554141745..8467bf1dd4416551d5325b63e9850d794feb1694 100755 (executable)
@@ -1,4 +1,6 @@
 #!/bin/sh
+# vim:noet:ts=4:sw=4
+VERSION=1.89
 
 # prevent "*" from being expanded in builders var
 set -f
@@ -15,9 +17,11 @@ dist=
 url=
 no_depend=no
 verbose=no
-autotag=no
+pkgrevision=no
+requester_override=
+relup=no
 
-if [ -x /usr/bin/python ]; then
+if [ -x /usr/bin/python3 ]; then
        send_mode="python"
 else
        echo "No python present, using mail mode"
@@ -34,14 +38,14 @@ if [ ! -f "$USER_CFG" ]; then
        echo "Creating config file $USER_CFG. You *must* edit it."
        cat > $USER_CFG <<EOF
 priority=2
-requester=deviloper@pld-linux.org
-default_key=deviloper@pld-linux.org
+requester=deviloper@tld-linux.org
+default_key=deviloper@tld-linux.org
 send_mode="$send_mode"
 url="$url"
-mailer="/usr/sbin/sendmail -t"
+mailer="/usr/lib/sendmail -t"
 gpg_opts=""
-dist=th
-url="http://src.th.pld-linux.org:1234/"
+dist=ti
+url="https://src.tld-linux.org:1241/"
 
 # defaults:
 f_upgrade=yes
@@ -61,6 +65,8 @@ fi
 specs=
 df_fetch=no
 upgrade_macros=no
+upgrade_scripts=no
+cr=$(printf "\r")
 
 # Set colors
 c_star=$(tput setaf 2)
@@ -82,32 +88,52 @@ send_request() {
        # switch to mail mode, if no url set
        [ -z "$url" ] && send_mode="mail"
 
+       if [ -n "$wait" ]; then
+               msg "Waiting $wait seconds before sending request"
+               sleep $wait
+               msg "Wait has ended, proceeding!"
+       fi
+
        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
+               msg "Sending using HTTP mode to $url"
+               cat - | python3 -c '
+import sys, socket, ssl
+from urllib import request
+
+try:
+    _create_unverified_https_context = ssl._create_unverified_context
+except AttributeError:
+    pass
+else:
+    ssl._create_default_https_context = _create_unverified_https_context
 
 try:
-        data = sys.stdin.read()
+        data = sys.stdin.read().encode("utf-8")
         url = sys.argv[1]
-        socket.setdefaulttimeout(10)
-        req = urllib2.Request(url, data)
-        f = urllib2.urlopen(req)
+        socket.setdefaulttimeout(30)
+        req = request.Request(url, data=data)
+        f = request.urlopen(req)
         f.close()
-except Exception, e:
-        print >> sys.stderr, "Problem while sending request via HTTP: %s: %s" % (url, e)
+except Exception as e:
+        print("Problem while sending request via HTTP: %s: %s" % (url, e), file=sys.stderr)
         sys.exit(1)
-print >> sys.stdout, "Request queued via HTTP."
+        print("Request queued via HTTP.", file=sys.stdout)
 ' "$url"
                ;;
        esac
 }
 
+# htmlspecialchars: escape <, > and &
+hsc() {
+       local input=$1
+       printf "%s\n" "$input" | sed -e 's,&,\&amp;,g;s,<,\&lt;,g;s,>,\&gt;,g'
+}
+
 # simple df_fetcher, based on packages/fetchsrc_request
 # TODO: tcp (smtp) mode
 # TODO: adjust for ~/.requestrc config
@@ -115,7 +141,7 @@ df_fetch() {
        local specs="$@"
 
        # Sending by
-       local MAILER='/usr/sbin/sendmail'
+       local MAILER='/usr/lib/sendmail'
        # MAILER='/usr/bin/msmtp'
        # Sending via
        local VIA="SENDMAIL"
@@ -126,23 +152,24 @@ df_fetch() {
        # VIA_ARGS='-a gmail'
        #
        # DISTFILES EMAIL
-       local DMAIL="distfiles@pld-linux.org"
+       local DMAIL="df@tld-linux.org"
 
        local HOST=$(hostname -f)
        local LOGIN=${requester%@*}
 
+       local SPEC BRANCH
        for spec in $specs; do
-               local SPEC=$(echo "$spec" | sed -e 's|:.*||')
-               local BRANCH=$(echo "$spec" | sed -e 's|.*:||')
+               SPEC=$(echo "$spec" | sed -e 's|:.*||')
+               SPEC=${SPEC%.spec}
+               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-Package: $SPEC
                        X-Branch: $BRANCH
                        X-Flags: force-reply
 
@@ -151,45 +178,33 @@ df_fetch() {
        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
+# get package revision for specs
+get_pkgrevision() {
+       local pkgrev pkg spec rpmdir
 
        rpmdir=$(rpm -E %_topdir)
-       cd $rpmdir
        for pkg in "$@"; do
+               cd $rpmdir
                # 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"
+               wget http://pkgrevs.tld-linux.org/list/$pkg -O /tmp/$pkg.tags 1>/dev/null 2>&1
+               pkgrev=$(head -n 1 /tmp/$pkg.tags)
+               rm -f /tmp/$pkg.tags
+               if [ "x$pkgrev" = "x" ]; then
+                       echo "$pkg.spec"
                else
-                       autotag $pkg/$pkg.spec
+                       echo "$pkg.spec:$pkgrev"
                fi
        done
 }
 
+relup() {
+       local script=$(dirname $(rpm -E %_topdir))/rpm-build-tools/relup.sh
+       $script -u -i "$@"
+}
+
 usage() {
        cat <<EOF
 Usage: make-request.sh [OPTION] ... [SPECFILE] ....
@@ -210,8 +225,10 @@ Mandatory arguments to long options are mandatory for short options too.
             set alt_kernel to VALUE
       --target VALUE
             set --target to VALUE
+      -D "NAME VALUE"|--define "NAME VALUE"
+            define macro named NAME with value VALUE
       -s BUILD_ID, --skip BUILD_ID[,BUILD_ID][,BUILD_ID]
-            mark build ids on src builder to be skipped
+            mark build ids on src builder to be skipped (instructs srcbuilder to create 'skipme' file)
       --branch VALUE
             specify default branch for specs in request
       -t, --test-build
@@ -222,6 +239,10 @@ Mandatory arguments to long options are mandatory for short options too.
             (and later moved by release manager staff to ready/ and main ftp tree)
       -u, --upgrade
             Forces package upgrade (for use with -c or -q, not -t)
+      --relup
+            Bump package release, see also --relup
+      -m, --message
+            Set commit message for relup
       -n, --no-upgrade
             Disables package upgrade (for use with -r)
       -ni, --no-install-br
@@ -251,14 +272,24 @@ Mandatory arguments to long options are mandatory for short options too.
             Updates builders infrastructure (outside chroot)
       --update-macros
             Updates rpm-build-macros on src builder
+      --update-scripts
+            Updates ~/rpm/rpm-build-tools on builder
+      --requester username
+            Override the requester
       -q
             shortcut for --command rpm -q ARGS
       -g, --gpg-opts "opts"
             Pass additional options to gpg binary
       -p, --priority VALUE
             sets request priority (default 2)
+      -w SECONDS
+            Wait SECONDS before sending actual request. Note: gpg passphrase is still asked immediately.
+            This may be useful if you just commited package and want to send it
+            for test build after distfiles has fetched the file.
       -h, --help
             Displays this help message
+      -v
+            Verbose. Print some more debug on screen
 EOF
        exit 0
 }
@@ -266,20 +297,10 @@ EOF
 # validate distro, set $dist
 set_dist() {
        case "$1" in
-       ac)
-               ;;
-       ac-java|ac-xen)
-               ;;
        ti)
                ;;
        ti-dev)
                ;;
-       th)
-               ;;
-       th-java)
-               ;;
-       aidath)
-               ;;
        *)
                die "dist \`$1' not known"
                ;;
@@ -288,7 +309,7 @@ set_dist() {
        dist=$1
 }
 
-while [ $# -gt 0 ] ; do
+while [ $# -gt 0 ]; do
        case "$1" in
                -d | --dist | --distro)
                        set_dist $2
@@ -308,7 +329,16 @@ while [ $# -gt 0 ] ; do
                        ;;
 
                -a)
-                       autotag=yes
+                       pkgrevision=yes
+                       ;;
+
+               -m)
+                       shift
+                       message=$1
+                       ;;
+
+               --relup)
+                       relup=yes
                        ;;
 
                --with)
@@ -336,6 +366,13 @@ while [ $# -gt 0 ] ; do
                        shift
                        ;;
 
+               -D|--define)
+                       value=${2#* }
+                       name=${2%% *}
+                       define="$define$cr$name=$value"
+                       shift
+                       ;;
+
                -s|--skip)
                        skip="$2"
                        shift
@@ -380,6 +417,11 @@ while [ $# -gt 0 ] ; do
                        jobs="${1#-j}"
                        ;;
 
+               -w)
+                       wait="$2"
+                       shift
+                       ;;
+
                -v)
                        verbose=yes
                        ;;
@@ -445,6 +487,10 @@ while [ $# -gt 0 ] ; do
                        upgrade_macros="yes"
                        ;;
 
+               --update-scripts)
+                       upgrade_scripts='yes'
+                       ;;
+
                -df | --distfiles-fetch | --distfiles-fetch-request)
                        df_fetch=yes
                        ;;
@@ -458,6 +504,11 @@ while [ $# -gt 0 ] ; do
                        usage
                        ;;
 
+               --requester)
+                       requester_override="$2"
+                       shift
+                       ;;
+
                -*)
                        die "unknown knob: $1"
                        ;;
@@ -470,50 +521,17 @@ while [ $# -gt 0 ] ; do
 done
 
 case "$dist" in
-ac)
-       builder_email="builder-ac@pld-linux.org"
-       default_builders="ac-*"
-       default_branch="AC-branch"
-       url="http://ep09.pld-linux.org:1289/"
-       control_url="http://ep09.pld-linux.org/~buildsrc"
-       ;;
-ac-java) # fake "dist" for java available ac architectures
-       builder_email="builder-ac@pld-linux.org"
-       default_builders="ac-i586 ac-i686 ac-athlon ac-amd64"
-       default_branch="AC-branch"
-       url="http://ep09.pld-linux.org:1289/"
-       ;;
-ac-xen) # fake "dist" for xen-enabled architectures
-       builder_email="builder-ac@pld-linux.org"
-       default_builders="ac-i686 ac-athlon ac-amd64"
-       default_branch="AC-branch"
-       ;;
 ti)
-       builder_email="builderti@kraz.tld-linux.org"
+       builder_email="builderti@src.tld-linux.org"
        default_builders="ti-*"
-       url="http://kraz.tld-linux.org:1231/"
-       control_url="http://kraz.tld-linux.org/~builderti"
+       url="https://src.tld-linux.org:1241/"
+       control_url="http://src.tld-linux.org/~builderti"
        ;;
 ti-dev)
-       builder_email="buildertidev@kraz.tld-linux.org"
+       builder_email="buildertidev@src.tld-linux.org"
        default_builders="ti-dev-*"
-       url="http://kraz.tld-linux.org:1232/"
-       control_url="http://kraz.tld-linux.org/~buildertidev"
-       ;;
-th)
-       builder_email="builderth@pld-linux.org"
-       default_builders="th-*"
-       url="http://src.th.pld-linux.org:1234/"
-       control_url="http://src.th.pld-linux.org"
-       ;;
-th-java) # fake "dist" for java available th architectures
-       builder_email="builderth@pld-linux.org"
-       default_builders="th-x86_64 th-athlon th-i686"
-       url="http://src.th.pld-linux.org:1234/"
-       ;;
-aidath)
-       builder_email="builderaidath@ep09.pld-linux.org"
-       default_builders="aidath-*"
+       url="https://src.tld-linux.org:1242/"
+       control_url="http://src.tld-linux.org/~buildertidev"
        ;;
 *)
        die "dist \`$dist' not known"
@@ -522,36 +540,36 @@ esac
 
 # need to do this after dist selection
 if [ "$skip" ]; then
-       skip=$(skip="$skip" control_url="$control_url" python -c '
-import urllib2
+       skip=$(skip="$skip" control_url="$control_url" python3 -c '
 import sys
-import StringIO
 import gzip
 import re
 import os
 import string
+from urllib import request
+from io import BytesIO
 from xml.dom import minidom
 
 skip = os.environ.get("skip").split(",");
 control_url = os.environ.get("control_url")
 
-print >> sys.stderr, "* Check queue_id-s against %s" % control_url
+print("* Check queue_id-s against %s" % control_url, file=sys.stderr)
 
 try:
        headers = { "Cache-Control": "no-cache", "Pragma": "no-cache" }
-       req = urllib2.Request(url=control_url + "/queue.gz", headers=headers)
-       f = urllib2.urlopen(req)
-except Exception, e:
-       print >> sys.stderr, "Fetch error %s: %s" % (control_url + "/queue.gz", e)
+       req = request.Request(url=control_url + "/queue.gz", headers=headers)
+       f = request.urlopen(req)
+except Exception as e:
+       print("Fetch error %s: %s" % (control_url + "/queue.gz", e), file=sys.stderr)
        sys.exit(1)
 
-sio = StringIO.StringIO()
+sio = BytesIO()
 sio.write(f.read())
 f.close()
 sio.seek(0)
 f = gzip.GzipFile(fileobj = sio)
 
-xml = re.compile("(<queue>.*?</queue>)", re.DOTALL).match(f.read()).group(1)
+xml = re.compile("(<queue>.*?</queue>)", re.DOTALL).match(f.read().decode("utf-8")).group(1)
 d = minidom.parseString(xml)
 
 q = []
@@ -563,13 +581,13 @@ for c in d.documentElement.childNodes:
 err = 0
 for s in skip:
        if s not in q:
-               print >> sys.stderr, "- Check %s: ERROR: Not valid queue-id" % s
+               print("- Check %s: ERROR: Not valid queue-id" % s, file=sys.stderr)
                err = 1
        else:
-               print >> sys.stderr, "- Check %s: OK" % s
+               print("- Check %s: OK" % s, file=sys.stderr)
 if err == 1:
        sys.exit(1)
-print string.join(skip, ",")
+print(",".join(skip))
 ') || exit $?
        f_upgrade=no
        build_mode=test
@@ -587,24 +605,24 @@ specs=`for s in $specs; do
                # skip marker - pass it along
                echo $s
                ;;
-       *.spec:*) # spec with branch
-               echo $s
-               ;;
-       *.spec) # spec without branch
-               echo $(basename $s):$branch
-               ;;
        *:*) # package name with branch
-               echo $s | sed -e 's/:/.spec:/'
+               _specfile=$(basename ${s%:*})
+               echo ${_specfile%.spec}.spec:${s##*:}
                ;;
        *) # just package name
-               echo $(basename $s).spec:$branch
+               echo $(basename ${s%.spec}).spec:$branch
                ;;
        esac
 done`
 
-if [ "$autotag" = "yes" ]; then
-       msg "Auto autotag build enabled"
-       specs=$(get_autotag $specs)
+if [ "$relup" = "yes" ]; then
+       msg "Auto relup enabled"
+       relup ${message:+-m "$message"} $specs
+fi
+
+if [ "$pkgrevision" = "yes" ]; then
+       msg "Package revision build enabled"
+       specs=$(get_pkgrevision $specs)
 fi
 
 if [ "$df_fetch" = "yes" ]; then
@@ -619,8 +637,16 @@ if [ "$upgrade_macros" = "yes" ]; then
        build_mode=test
 fi
 
+if [ "$upgrade_scripts" = "yes" ]; then
+       command="cd ~/rpm/rpm-build-tools && git pull"
+       command_flags=as-builder
+       builders="$dist-src"
+       f_upgrade=no
+       build_mode=test
+fi
+
 if [[ "$requester" != *@* ]] ; then
-       requester="$requester@pld-linux.org"
+       requester="$requester@tld-linux.org"
 fi
 
 if [ -z "$builders" ] ; then
@@ -676,12 +702,16 @@ gen_req() {
                msg "Build mode: $(tput setaf 3)$build_mode$c_norm"
        fi
 
+       if [ -n "$requester_override" ] ; then
+               echo "  <requester>$requester_override</requester>"
+       fi
+
        msg "Queue-ID: $id"
        echo
 
        # job to depend on
        local depend=
-       local b i=1
+       local b i=1 val
        local name branch builders_xml
 
        for b in $builders; do
@@ -691,10 +721,10 @@ gen_req() {
 
        if [ "$command" ]; then
                bid=$(uuidgen)
-               echo -E >&2 "* Command: $command"
+               printf "%s\n" "* Command: $command" >&2
                echo "  <batch id='$bid' depends-on=''>"
                echo "           <command flags='$command_flags'>"
-               echo -E "$command" | sed -e 's,&,\&amp;,g;s,<,\&lt;,g;s,>,\&gt;,g'
+               hsc "$command"
                echo "</command>"
                echo "           <info></info>"
                echo "$builders_xml"
@@ -725,6 +755,17 @@ gen_req() {
                echo "           <branch>$branch</branch>"
                echo "           ${kernel:+<kernel>$kernel</kernel>}"
                echo "           ${target:+<target>$target</target>}"
+
+               oIFS=$IFS; IFS=$cr
+               for b in $define; do
+                       [ -z "$b" ] && continue
+                       value=${b#*=}
+                       b=${b%%=*}
+                       echo "           <define name='$(hsc $b)'>$(hsc "$value")</define>"
+                       msg "- define $b=$value"
+               done
+               IFS=$oIFS
+
                echo "           <info></info>"
                echo
                for b in $with; do
@@ -747,10 +788,10 @@ gen_req() {
                if [ "$no_depend" = yes ]; then
                        depend=
                fi
-               echo -E >&2 "* Post-Command: $post_command"
+               printf "%s\n" "* Post-Command: $post_command" >&2
                echo "  <batch id='$bid' depends-on='$depend'>"
                echo "           <command flags='$command_flags'>"
-               echo -E "$post_command" | sed -e 's,&,\&amp;,g;s,<,\&lt;,g;s,>,\&gt;,g'
+               hsc "$post_command"
                echo "</command>"
                echo "           <info></info>"
                echo "$builders_xml"
@@ -776,8 +817,8 @@ gen_email () {
        To: $builder_email
        Subject: build request
        Message-Id: <$id@$(hostname)>
-       X-New-PLD-Builder: request
-       X-Requester-Version: \$Id$
+       X-New-TLD-Builder: request
+       X-Requester-Version: $VERSION
 
        EOF