Skip to content

Commit be76a77

Browse files
committed
Add self-update feature
1 parent 4b95ef8 commit be76a77

7 files changed

Lines changed: 136 additions & 9 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ podman run --rm -it ghcr.io/essentialkaos/sslcli:latest mydomain.com
5656
docker run --rm -it ghcr.io/essentialkaos/sslcli:latest mydomain.com
5757
```
5858

59+
### Upgrading
60+
61+
Since version `3.1.0` you can update `sslcli` to the latest release using [self-update feature](https://github.com/essentialkaos/.github/blob/master/APPS-UPDATE.md):
62+
63+
```bash
64+
sslcli --update
65+
```
66+
67+
This command will runs a self-update in interactive mode. If you want to run a quiet update (_no output_), use the following command:
68+
69+
```bash
70+
sslcli --update=quiet
71+
```
72+
73+
> [!NOTE]
74+
> Please note that the self-update feature only works with binaries that are downloaded from the [EK Apps Repository](https://apps.kaos.st/sslcli/latest). Binaries from packages do not have a self-update feature and must be upgraded via the package manager.
75+
5976
### Feature list
6077

6178
* Superb UI

cli/cli.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/essentialkaos/ek/v13/support"
2626
"github.com/essentialkaos/ek/v13/support/deps"
2727
"github.com/essentialkaos/ek/v13/terminal"
28+
"github.com/essentialkaos/ek/v13/terminal/tty"
2829
"github.com/essentialkaos/ek/v13/timeutil"
2930
"github.com/essentialkaos/ek/v13/usage"
3031
"github.com/essentialkaos/ek/v13/usage/completion/bash"
@@ -40,7 +41,7 @@ import (
4041

4142
const (
4243
APP = "SSLScan Client"
43-
VER = "3.0.3"
44+
VER = "3.1.0"
4445
DESC = "Command-line client for the SSL Labs API"
4546
)
4647

@@ -64,6 +65,7 @@ const (
6465
OPT_NAME = "name"
6566
OPT_ORG = "org"
6667

68+
OPT_UPDATE = "U:update"
6769
OPT_VERB_VER = "vv:verbose-version"
6870
OPT_COMPLETION = "completion"
6971
OPT_GENERATE_MAN = "generate-man"
@@ -155,6 +157,9 @@ func Run(gitRev string, gomod []byte) {
155157

156158
runtime.GOMAXPROCS(2)
157159

160+
preConfigureUI()
161+
preConfigureOptions()
162+
158163
args, errs := options.Parse(optMap)
159164

160165
if !errs.IsEmpty() {
@@ -181,6 +186,8 @@ func Run(gitRev string, gomod []byte) {
181186
WithChecks(checkAPIAvailability()).
182187
Print()
183188
os.Exit(0)
189+
case withSelfUpdate && options.GetB(OPT_UPDATE):
190+
os.Exit(updateBinary())
184191
case options.GetB(OPT_HELP) || (len(args) == 0 && !options.GetB(OPT_REGISTER)):
185192
genUsage().Print()
186193
os.Exit(0)
@@ -211,9 +218,9 @@ func Run(gitRev string, gomod []byte) {
211218
}
212219
}
213220

214-
// configureUI configures user interface
215-
func configureUI() {
216-
if options.GetB(OPT_NO_COLOR) {
221+
// preConfigureUI preconfigures UI based on information about user terminal
222+
func preConfigureUI() {
223+
if !tty.IsTTY() {
217224
fmtc.DisableColors = true
218225
}
219226

@@ -230,6 +237,18 @@ func configureUI() {
230237
}
231238
}
232239

240+
// preConfigureOptions preconfigures command-line options based on build tags
241+
func preConfigureOptions() {
242+
optMap.SetIf(withSelfUpdate, OPT_UPDATE, &options.V{Type: options.MIXED})
243+
}
244+
245+
// configureUI configures user interface
246+
func configureUI() {
247+
if options.GetB(OPT_NO_COLOR) {
248+
fmtc.DisableColors = true
249+
}
250+
}
251+
233252
// prepare prepares utility for processing data
234253
func prepare() error {
235254
if !options.Has(OPT_MAX_LEFT) {
@@ -753,6 +772,11 @@ func genUsage() *usage.Info {
753772
info.AddOption(OPT_QUIET, "Don't show any output")
754773
info.AddOption(OPT_PAGER, "Use pager for long output")
755774
info.AddOption(OPT_NO_COLOR, "Disable colors in output")
775+
776+
if withSelfUpdate {
777+
info.AddOption(OPT_UPDATE, "Update application to the latest version")
778+
}
779+
756780
info.AddOption(OPT_HELP, "Show this help message")
757781
info.AddOption(OPT_VER, "Show version")
758782

cli/with_selfupdate.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//go:build selfupdate
2+
3+
package cli
4+
5+
// ////////////////////////////////////////////////////////////////////////////////// //
6+
// //
7+
// Copyright (c) 2026 ESSENTIAL KAOS //
8+
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
9+
// //
10+
// ////////////////////////////////////////////////////////////////////////////////// //
11+
12+
import (
13+
"strings"
14+
15+
"github.com/essentialkaos/ek/v13/fmtc"
16+
"github.com/essentialkaos/ek/v13/options"
17+
"github.com/essentialkaos/ek/v13/selfupdate"
18+
"github.com/essentialkaos/ek/v13/selfupdate/interactive"
19+
storage "github.com/essentialkaos/ek/v13/selfupdate/storage/basic"
20+
"github.com/essentialkaos/ek/v13/terminal"
21+
)
22+
23+
// ////////////////////////////////////////////////////////////////////////////////// //
24+
25+
var withSelfUpdate = true
26+
27+
// ////////////////////////////////////////////////////////////////////////////////// //
28+
29+
// updateBinary updates current binary to the latest version
30+
func updateBinary() int {
31+
quiet := strings.ToLower(options.GetS(OPT_UPDATE)) == "quiet"
32+
updInfo, hasUpdate, err := storage.NewStorage("https://apps.kaos.ws").Check(APP, VER)
33+
34+
if err != nil {
35+
if !quiet {
36+
terminal.Error("Can't update binary: %v", err)
37+
}
38+
39+
return 1
40+
}
41+
42+
if !hasUpdate {
43+
fmtc.If(!quiet).Println("{g}You are using the latest version of the app{!}")
44+
return 0
45+
}
46+
47+
pubKey := "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEnYHsOTvrKqeE97dsEt7Ge97+yUcvQJn1++s++FqShDyqwV8CcoKp0E6nDTc8SxInZ5wxwcScxSicfvC9S73OSg=="
48+
49+
if quiet {
50+
err = selfupdate.Run(updInfo, pubKey, nil)
51+
} else {
52+
err = selfupdate.Run(updInfo, pubKey, interactive.Dispatcher())
53+
}
54+
55+
if err != nil {
56+
return 1
57+
}
58+
59+
return 0
60+
}
61+
62+
// ////////////////////////////////////////////////////////////////////////////////// //

cli/without_selfupdate.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build !selfupdate
2+
3+
package cli
4+
5+
// ////////////////////////////////////////////////////////////////////////////////// //
6+
// //
7+
// Copyright (c) 2026 ESSENTIAL KAOS //
8+
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
9+
// //
10+
// ////////////////////////////////////////////////////////////////////////////////// //
11+
12+
var withSelfUpdate = false
13+
14+
// ////////////////////////////////////////////////////////////////////////////////// //
15+
16+
// updateBinary updates current binary to the latest version
17+
func updateBinary() int {
18+
return 1
19+
}
20+
21+
// ////////////////////////////////////////////////////////////////////////////////// //

common/sslcli.spec

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
Summary: Pretty awesome command-line client for public SSLLabs API
1212
Name: sslcli
13-
Version: 3.0.3
13+
Version: 3.1.0
1414
Release: 0%{?dist}
1515
Group: Applications/System
1616
License: Apache License, Version 2.0
@@ -22,7 +22,7 @@ Source100: checksum.sha512
2222

2323
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
2424

25-
BuildRequires: golang >= 1.23
25+
BuildRequires: golang >= 1.24
2626

2727
Provides: %{name} = %{version}-%{release}
2828

@@ -103,6 +103,9 @@ fi
103103
################################################################################
104104

105105
%changelog
106+
* Tue Jan 20 2026 Anton Novojilov <andy@essentialkaos.com> - 3.1.0-0
107+
- Dependencies update
108+
106109
* Thu May 15 2025 Anton Novojilov <andy@essentialkaos.com> - 3.0.3-0
107110
- Code refactoring
108111
- Dependencies update

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.24.0
44

55
require (
66
github.com/essentialkaos/ek/v13 v13.38.3
7-
github.com/essentialkaos/sslscan/v14 v14.1.3
7+
github.com/essentialkaos/sslscan/v14 v14.1.4
88
)
99

1010
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/essentialkaos/depsy v1.3.1 h1:00k9QcMsdPM4IzDaEFHsTHBD/zoM0oxtB5+dMUw
44
github.com/essentialkaos/depsy v1.3.1/go.mod h1:B5+7Jhv2a2RacOAxIKU2OeJp9QfZjwIpEEPI5X7auWM=
55
github.com/essentialkaos/ek/v13 v13.38.3 h1:gQVNC6RdSBBYFhmtN9QOCZbshm+ib0PO2b9O0C7JMWc=
66
github.com/essentialkaos/ek/v13 v13.38.3/go.mod h1:qS5hOA6BaVYCS+nstm6l502Ehkb8i5PaN5nd40fbUg0=
7-
github.com/essentialkaos/sslscan/v14 v14.1.3 h1:OTDspOu2CBaDGnUk/ZVzewW49AgpeVHZFiczG+kHKho=
8-
github.com/essentialkaos/sslscan/v14 v14.1.3/go.mod h1:pQD5CLYEflZSBlqXII/HO++wxBBRjbfIWGoznq0LuHM=
7+
github.com/essentialkaos/sslscan/v14 v14.1.4 h1:gtVs4OyiA7yyy7og3meVL9WTlo5C21d8WR2TkV3RGEo=
8+
github.com/essentialkaos/sslscan/v14 v14.1.4/go.mod h1:MD8HhNo9gDH/ko9vHTyzapAOixEZraYyjmSgulPr/ac=
99
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1010
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
1111
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=

0 commit comments

Comments
 (0)