github.com/coreos/mantle@v0.13.0/cmd/cork/download.go (about)

     1  // Copyright 2015 CoreOS, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package main
    16  
    17  import (
    18  	"github.com/spf13/cobra"
    19  
    20  	"github.com/coreos/mantle/sdk"
    21  )
    22  
    23  var (
    24  	downloadCmd = &cobra.Command{
    25  		Use:   "download",
    26  		Short: "Download the SDK tarball",
    27  		Long:  "Download the current SDK tarball to a local cache.",
    28  		Run:   runDownload,
    29  	}
    30  	downloadVersion       string
    31  	downloadVerifyKeyFile string
    32  )
    33  
    34  func init() {
    35  	downloadCmd.Flags().StringVar(&downloadVersion,
    36  		"sdk-version", "", "SDK version")
    37  	downloadCmd.Flags().StringVar(&downloadImageVerifyKeyFile,
    38  		"verify-key", "", "PGP public key to be used in verifing download signatures.  Defaults to CoreOS Buildbot (0412 7D0B FABE C887 1FFB  2CCE 50E0 8855 93D2 DCB4)")
    39  	root.AddCommand(downloadCmd)
    40  }
    41  
    42  func runDownload(cmd *cobra.Command, args []string) {
    43  	if len(args) != 0 {
    44  		plog.Fatal("No args accepted")
    45  	}
    46  
    47  	if downloadVersion == "" {
    48  		plog.Fatal("Missing --sdk-version=VERSION")
    49  	}
    50  
    51  	plog.Noticef("Downloading SDK version %s", downloadVersion)
    52  	if err := sdk.DownloadSDK(downloadVersion, downloadVerifyKeyFile); err != nil {
    53  		plog.Fatalf("Download failed: %v", err)
    54  	}
    55  }