On 2014-10-27 04:10, Andrew Schulman wrote:
On 2014-10-19 09:13, Andrew Schulman wrote:
I've published several improvements to cygport on Github.  Each improvement
is in its own branch:

upload
    Adds the "upload" command: upload finished packages to cygwin.com.

I definitely want to add this feature.  However, the implementation is
overly complicated; only one upload client need be supported, which
should then be added to requires:.  (Yes, I'm aware that downloading
handles wget or curl, but that is legacy code and the same should apply
there.)  The pkg_name for loops are also incorrect wrt subpackages.

Both fixed in the upload branch.

Here's what I have at the moment based on your branch as of a few weeks ago. However, with password-protected SSH keys, the password prompt isn't handled properly. Any ideas?
diff --git a/README b/README
index 800dceb..afcfca1 100644
--- a/README
+++ b/README
@@ -144,6 +144,7 @@ to be processed.  All other arguments are interpreted as a 
COMMAND, which may be
     test      - run the package's test suite, if one exists
     install   - install into a DESTDIR, and run post-installation steps
     package   - create binary and source packages
+    upload    - upload finished packages to cygwin.com
     finish    - delete the working directory
     all       - run all of the above, including finish
     almostall - run all of the above, except for finish
@@ -197,6 +198,7 @@ addition to the packages own dependencies:
     gawk
     grep
     gzip
+    lftp
     libtool
     lndir
     make
diff --git a/bin/cygport.in b/bin/cygport.in
index 0b26444..e14b22a 100755
--- a/bin/cygport.in
+++ b/bin/cygport.in
@@ -99,6 +99,7 @@ source ${_privlibdir}/syntax.cygpart
 #  * Installing
 #  * Postinstall
 #  * Packaging
+#  * Uploading
 #  * Cygclasses
 #****
 
@@ -108,8 +109,8 @@ source ${_privlibdir}/syntax.cygpart
 #  REQUIRES
 #  The following packages are required to build packages with cygport:
 #   autoconf, automake, bash, binutils, bzip2, coreutils, diffstat, diffutils,
-#   dos2unix, file, gawk, grep, gzip, libtool, lndir, make, patch, rsync, sed,
-#   tar, unzip, util-linux, wget, which, xz.
+#   dos2unix, file, gawk, grep, gzip, lftp, libtool, lndir, make, patch, rsync,
+#   sed, tar, unzip, util-linux, wget, which, xz.
 #  Other software packages are required by some Cygclasses, as indicated 
within.
 #****
 
@@ -293,6 +294,27 @@ unset conf;
 #  section.
 #****
 
+#****** Cygport/Uploading
+#  INTRODUCTION
+#  Once your binary and source packages are built, in order to distribute them
+#  to users, you need to upload them to the Cygwin package archive.  Before
+#  you can upload packages, you'll need to do the following things:
+#  * Request upload privileges, and provide your ssh public key.  The
+#    |html <a 
href="https://sourceware.org/cygwin-apps/package-upload.html";>Uploading 
Packages</a>
+#    page tells how to do that, and how to be notified in case of problems with
+#    your uploads.
+#  * Be listed on the
+#    |html <a href="https://cygwin.com/cygwin-pkg-maint";>Cygwin package 
maintainers list</a>
+#    as the maintainer of your packages.  Ask on the cygwin-apps mailing list 
if
+#    you need help getting listed.
+#
+#  Once those things are done, running
+#  |html <tt>cygport upload</tt> (or <tt>cygport up</tt> for short)
+#  will upload your finished packages to the package archive on cygwin.com.
+#  From there, if everything goes well, the new files should appear on your
+#  local Cygwin mirror within about 12 hours.
+#****
+
 #****** Cygport/Cygclasses
 #  DESCRIPTION
 #  Cygclasses serve as cygport's standard library, allowing cygport to support
@@ -518,6 +540,10 @@ source ${_privlibdir}/pkg_info.cygpart
 source ${_privlibdir}/pkg_pkg.cygpart
 ###
 
+### __pkg_upload
+source ${_privlibdir}/pkg_upload.cygpart
+###
+
 ### __finish
 source ${_privlibdir}/pkg_cleanup.cygpart
 ###
@@ -737,6 +763,7 @@ declare -r compilelog="${logdir}/${PF}-compile.log";
 declare -r checklog="${logdir}/${PF}-check.log";
 declare -r installlog="${logdir}/${PF}-install.log";
 declare -r pkglog="${logdir}/${PF}-pkg.log";
+declare -r uploadlog="${logdir}/${PF}-upload.log";
 
 if ! defined SRC_URI
 then
@@ -860,6 +887,12 @@ do
                        __pkg_diff;
                        _status=$?;
                        ;;
+               upload|up)
+                       __stage Uploading;
+                       __log_init ${uploadlog};
+                       (__pkg_upload) 2>&1 | tee -a ${uploadlog};
+                       _status=$?;
+                       ;;
                clean|finish)
                        __finish;
                        _status=$?;
diff --git a/cygport.spec b/cygport.spec
index d0dcbf7..7a81b4b 100644
--- a/cygport.spec
+++ b/cygport.spec
@@ -28,6 +28,7 @@ Requires:       file
 Requires:       gawk
 Requires:       grep
 Requires:       imake
+Requires:       lftp
 Requires:       make
 Requires:       patch
 Requires:       rsync
diff --git a/data/cygport-bash-completion b/data/cygport-bash-completion
index 639f873..18a5adf 100644
--- a/data/cygport-bash-completion
+++ b/data/cygport-bash-completion
@@ -11,7 +11,7 @@ _cygport()
                prep unpack oldpatch compile build make \
                check test inst install list dep depends \
                info package pkg diff mkdiff mkpatch clean finish \
-               almostall all help version homepage website'
+               upload up almostall all help version homepage website'
 
        if [[ $COMP_CWORD -eq 1 ]] ; then
                # first arg: source file completion
diff --git a/data/cygport.conf b/data/cygport.conf
index 87a5312..be859c8 100644
--- a/data/cygport.conf
+++ b/data/cygport.conf
@@ -66,6 +66,12 @@
 #****
 #PAGER=
 
+#****v* Configuration/SSH_KEY
+#  DESCRIPTION
+#  Path to the SSH private key corresponding to the public key registered
+#  for uploading on sourceware.
+#****
+#SSH_KEY=~/.ssh/id_rsa
 
 # You can select your own mirrors to use instead of the generic list.
 # See the documentation for mirror list locations and default mirrors.
diff --git a/data/sample.cygport b/data/sample.cygport
index 9f54858..f89cb2e 100644
--- a/data/sample.cygport
+++ b/data/sample.cygport
@@ -16,7 +16,7 @@ ARCH=noarch
 DEPEND="groff help2man robodoc"
 # runtime deps to go in setup.hint, and note the escaped newline
 REQUIRES="autoconf automake binutils bzip2 coreutils diffstat diffutils \
-dos2unix findutils file gawk gcc-core gcc-g++ grep gzip libtool lndir \
+dos2unix findutils file gawk gcc-core gcc-g++ grep gzip lftp libtool lndir \
 make patch rsync sed tar texinfo unzip util-linux wget which xz"
 
 # We use the standard src_compile and src_test.
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 0c9a862..5e1e965 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -8,6 +8,7 @@ cygpart_DATA = \
        lib/pkg_cleanup.cygpart         \
        lib/pkg_info.cygpart            \
        lib/pkg_pkg.cygpart             \
+       lib/pkg_upload.cygpart          \
        lib/src_compile.cygpart         \
        lib/src_fetch.cygpart           \
        lib/src_install.cygpart         \
diff --git a/lib/help.cygpart b/lib/help.cygpart
index 4e82399..0fd9e61 100644
--- a/lib/help.cygpart
+++ b/lib/help.cygpart
@@ -46,6 +46,7 @@ __show_help() {
                  test         run the package's test suite, if one exists
                  install      install into a DESTDIR, and run 
post-installation steps
                  package      create binary and source packages
+                 upload       upload finished packages to cygwin.com
                  finish       delete the working directory
                  all          run all of the above, excluding finish
 
diff --git a/lib/pkg_upload.cygpart b/lib/pkg_upload.cygpart
new file mode 100644
index 0000000..f505b9e
--- /dev/null
+++ b/lib/pkg_upload.cygpart
@@ -0,0 +1,92 @@
+################################################################################
+#
+# pkg_upload.cygpart - cygport package uploading functions
+#
+# Copyright (C) 2014 Andrew Schulman, Yaakov Selkowitz
+# Provided by the Cygwin Ports project <http://sourceware.org/cygwinports/>
+#
+# cygport is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cygport is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cygport.  If not, see <http://www.gnu.org/licenses/>.
+#
+################################################################################
+
+__pkg_upload() {
+       local d;
+       local f;
+       local -i n=0;
+       local -i missing=0;
+       local -a dist_files=(${PN}/${PN}-${PV}-${PR}-src.tar.xz 
${PN}/setup.hint)
+       local -a archdir;
+
+       cd "${distdir}"
+
+       # Check that binary and source package files exist
+       while (( n < pkg_count ))
+       do
+               case ${pkg_name[${n}]} in
+               ${PN})  distsubdir= ;;
+               *)      distsubdir=${pkg_name[${n}]} ;;
+               esac
+
+               
dist_files+=(${PN}/${distsubdir}/${pkg_name[${n}]}-${PVR}.tar.xz 
${PN}/${distsubdir}/setup.hint)
+
+               n+=1;
+       done
+
+       for f in ${dist_files[*]}
+       do
+               [ -f ${f} ] || missing+=1;
+       done
+
+       if (( missing > 0 ))
+       then
+               error "Package staging is incomplete. Run \"cygport 
${cygportfile} package\" to stage packages for upload."
+       fi
+
+       # Upload
+
+       case ${ARCH} in
+               i686)   archdir=(x86) ;;
+               x86_64) archdir=(x86_64) ;;
+               noarch) archdir=(x86 x86_64) ;;
+       esac
+
+       __step "Uploading..."
+
+       {
+               echo "set cmd:fail-exit on"
+               echo "set cmd:interactive on"
+               echo "set net:max-retries 1"
+
+               if test -n "$SSH_KEY"
+               then
+                       echo "set sftp:connect-program ssh -a -x -i 
'${SSH_KEY}'"
+               fi
+
+               echo "open sftp://cygwin:@cygwin.com";
+
+               for d in ${archdir[*]}
+               do
+                       echo "cd /${d}/release"
+#                      echo "rm -f !ready || echo -n"
+                       echo "mirror -v -eR ${PN}"
+                       echo "put -O ${PN} /dev/null -o !ready"
+               done
+
+       } | lftp -f /dev/stdin || error "Upload failed"
+
+       __step "Upload complete."
+}
+
+# protect functions
+readonly -f __pkg_upload

Reply via email to