Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Commit

Permalink
update: add initial update command powered by equinox
Browse files Browse the repository at this point in the history
  • Loading branch information
philips committed Aug 14, 2020
1 parent 5e6fadd commit 2cccbbe
Show file tree
Hide file tree
Showing 44 changed files with 2,584 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/spf13/cobra"
"go.transparencylog.net/tl/cmd/cat"
"go.transparencylog.net/tl/cmd/get"
"go.transparencylog.net/tl/cmd/update"
"go.transparencylog.net/tl/cmd/verify"
"go.transparencylog.net/tl/cmd/version"
)
Expand All @@ -41,6 +42,7 @@ func init() {
rootCmd.AddCommand(verify.VerifyCmd)
rootCmd.AddCommand(cat.CatCmd)
rootCmd.AddCommand(version.Cmd)
rootCmd.AddCommand(update.Cmd)
}

func Execute() {
Expand Down
57 changes: 57 additions & 0 deletions cmd/update/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package update

import (
"fmt"
"log"

"github.com/equinox-io/equinox"
"github.com/spf13/cobra"
)

var Cmd = &cobra.Command{
Use: "update",
Short: "Update to the latest release",

Args: cobra.ExactArgs(0),

Run: update,
}

// assigned when creating a new application in the dashboard
const appID = "app_gCwJN1DfmYU"

// public portion of signing key generated by `equinox genkey`
var publicKey = []byte(`
-----BEGIN ECDSA PUBLIC KEY-----
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEHk9AJl154cKxZRECl5oO7GaAAM4Rc5e4
rBytsXGhOWeZdv/QGXWO3gPq134sTFeOwNwu6GJdk1QhAw85YQc/RKFf2vm2Jut4
Ad3Me5ph2iwXmgG3tPvBNthqeQgIu58f
-----END ECDSA PUBLIC KEY-----
`)

func update(cmd *cobra.Command, args []string) {
var opts equinox.Options
if err := opts.SetPublicKeyPEM(publicKey); err != nil {
log.Fatalf("%v", err)
}

// check for the update
resp, err := equinox.Check(appID, opts)
switch {
case err == equinox.NotAvailableErr:
fmt.Println("No update available, already at the latest version!")
log.Fatalf("%v", err)
case err != nil:
fmt.Println("Update failed:", err)
log.Fatalf("%v", err)
}

// fetch the update and apply it
err = resp.Apply()
if err != nil {
log.Fatalf("%v", err)
}

fmt.Printf("Updated to new version: %s!\n", resp.ReleaseVersion)
return
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.14
require (
github.com/cavaliercoder/grab v1.0.1-0.20200703095818-d3334b8f122d
github.com/dgraph-io/badger/v2 v2.0.3
github.com/equinox-io/equinox v1.2.0
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUn
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/equinox-io/equinox v1.2.0 h1:bBS7Ou+Y7Jwgmy8TWSYxEh85WctuFn7FPlgbUzX4DBA=
github.com/equinox-io/equinox v1.2.0/go.mod h1:6s3HJB0PYUNgs0mxmI8fHdfVl3TQ25ieA/PVfr+eyVo=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down
7 changes: 7 additions & 0 deletions release
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
equinox release \
--version=$(git describe --tags) \
--platforms="darwin_amd64 darwin_arm64 linux_arm linux_arm64 linux_amd64 windows_amd64 windows_arm64" \
--signing-key=${EQUINOX_KEY} \
--app="app_gCwJN1DfmYU" \
--token="${EQUINOX_TOKEN}" \
go.transparencylog.net/tl
13 changes: 13 additions & 0 deletions vendor/github.com/equinox-io/equinox/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/equinox-io/equinox/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions vendor/github.com/equinox-io/equinox/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions vendor/github.com/equinox-io/equinox/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/equinox-io/equinox/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions vendor/github.com/equinox-io/equinox/internal/go-update/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2cccbbe

Please sign in to comment.