@@ -441,11 +441,8 @@ func archiveBasename(arch string, archiveVersion string) string {
441441func archiveUpload (archive string , blobstore string , signer string ) error {
442442 // If signing was requested, generate the signature files
443443 if signer != "" {
444- pgpkey , err := base64 .StdEncoding .DecodeString (os .Getenv (signer ))
445- if err != nil {
446- return fmt .Errorf ("invalid base64 %s" , signer )
447- }
448- if err := build .PGPSignFile (archive , archive + ".asc" , string (pgpkey )); err != nil {
444+ key := getenvBase64 (signer )
445+ if err := build .PGPSignFile (archive , archive + ".asc" , string (key )); err != nil {
449446 return err
450447 }
451448 }
@@ -489,6 +486,7 @@ func doDebianSource(cmdline []string) {
489486 var (
490487 signer = flag .String ("signer" , "" , `Signing key name, also used as package author` )
491488 upload = flag .String ("upload" , "" , `Where to upload the source package (usually "ppa:ethereum/ethereum")` )
489+ sshUser = flag .String ("sftp-user" , "" , `Username for SFTP upload (usually "geth-ci")` )
492490 workdir = flag .String ("workdir" , "" , `Output directory for packages (uses temp dir if unset)` )
493491 now = time .Now ()
494492 )
@@ -498,11 +496,7 @@ func doDebianSource(cmdline []string) {
498496 maybeSkipArchive (env )
499497
500498 // Import the signing key.
501- if b64key := os .Getenv ("PPA_SIGNING_KEY" ); b64key != "" {
502- key , err := base64 .StdEncoding .DecodeString (b64key )
503- if err != nil {
504- log .Fatal ("invalid base64 PPA_SIGNING_KEY" )
505- }
499+ if key := getenvBase64 ("PPA_SIGNING_KEY" ); len (key ) > 0 {
506500 gpg := exec .Command ("gpg" , "--import" )
507501 gpg .Stdin = bytes .NewReader (key )
508502 build .MustRun (gpg )
@@ -523,12 +517,45 @@ func doDebianSource(cmdline []string) {
523517 build .MustRunCommand ("debsign" , changes )
524518 }
525519 if * upload != "" {
526- build . MustRunCommand ( "dput" , "--passive" , "--no- upload-log" , * upload , changes )
520+ uploadDebianSource ( * workdir , * upload , * sshUser , changes )
527521 }
528522 }
529523 }
530524}
531525
526+ func uploadDebianSource (workdir , ppa , sshUser , changes string ) {
527+ // Create the dput config file.
528+ dputConfig := filepath .Join (workdir , "dput.cf" )
529+ p := strings .Split (ppa , "/" )
530+ if len (p ) != 2 {
531+ log .Fatal ("-upload PPA name must contain single /" )
532+ }
533+ templateData := map [string ]string {
534+ "LaunchpadUser" : p [0 ],
535+ "LaunchpadPPA" : p [1 ],
536+ "LaunchpadSSH" : sshUser ,
537+ }
538+ if sshkey := getenvBase64 ("PPA_SSH_KEY" ); len (sshkey ) > 0 {
539+ idfile := filepath .Join (workdir , "sshkey" )
540+ ioutil .WriteFile (idfile , sshkey , 0600 )
541+ templateData ["IdentityFile" ] = idfile
542+ }
543+ build .Render ("build/dput-launchpad.cf" , dputConfig , 0644 , templateData )
544+
545+ // Run dput to do the upload.
546+ dput := exec .Command ("dput" , "-c" , dputConfig , "--no-upload-log" , ppa , changes )
547+ dput .Stdin = strings .NewReader ("Yes\n " ) // accept SSH host key
548+ build .MustRun (dput )
549+ }
550+
551+ func getenvBase64 (variable string ) []byte {
552+ dec , err := base64 .StdEncoding .DecodeString (os .Getenv (variable ))
553+ if err != nil {
554+ log .Fatal ("invalid base64 " + variable )
555+ }
556+ return []byte (dec )
557+ }
558+
532559func makeWorkdir (wdflag string ) string {
533560 var err error
534561 if wdflag != "" {
@@ -800,15 +827,10 @@ func doAndroidArchive(cmdline []string) {
800827 os .Rename (archive , meta .Package + ".aar" )
801828 if * signer != "" && * deploy != "" {
802829 // Import the signing key into the local GPG instance
803- b64key := os .Getenv (* signer )
804- key , err := base64 .StdEncoding .DecodeString (b64key )
805- if err != nil {
806- log .Fatalf ("invalid base64 %s" , * signer )
807- }
830+ key := getenvBase64 (* signer )
808831 gpg := exec .Command ("gpg" , "--import" )
809832 gpg .Stdin = bytes .NewReader (key )
810833 build .MustRun (gpg )
811-
812834 keyID , err := build .PGPKeyID (string (key ))
813835 if err != nil {
814836 log .Fatal (err )
0 commit comments