Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Acme Downloader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Geant DevOps
Acme Downloader
Commits
a92c021c
Unverified
Commit
a92c021c
authored
3 years ago
by
Massimiliano Adamo
Browse files
Options
Downloads
Patches
Plain Diff
add self-update script
parent
a8271ada
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.go
+45
-0
45 additions, 0 deletions
main.go
with
45 additions
and
0 deletions
main.go
+
45
−
0
View file @
a92c021c
...
...
@@ -5,6 +5,7 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
...
...
@@ -291,6 +292,37 @@ func ReadOSRelease(configfile string) map[string]string {
return
ConfigParams
}
// download file: taken as is from StackOverflow
func
downloadFile
(
filepath
string
,
url
string
)
(
err
error
)
{
// Create the file
out
,
err
:=
os
.
Create
(
filepath
)
if
err
!=
nil
{
return
err
}
defer
out
.
Close
()
// Get the data
resp
,
err
:=
http
.
Get
(
url
)
if
err
!=
nil
{
return
err
}
defer
resp
.
Body
.
Close
()
// Check server response
if
resp
.
StatusCode
!=
http
.
StatusOK
{
return
fmt
.
Errorf
(
"bad status: %s"
,
resp
.
Status
)
}
// Writer the body to file
_
,
err
=
io
.
Copy
(
out
,
resp
.
Body
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
main
()
{
OSInfo
:=
ReadOSRelease
(
"/etc/os-release"
)
...
...
@@ -343,6 +375,7 @@ Options:
--key-destination=KEYDESTINATION Key Destination [default: %v/<cert-name>.key]
--ca-destination=CADESTINATION CA Destination [default: %v/COMODO_<type>.crt]
--wildcard The certificate type is wildcard
--update Self-updates the tool and exit
`
,
CertBase
,
CertBase
,
KeyBase
,
CertBase
)
arguments
,
_
:=
docopt
.
Parse
(
usage
,
nil
,
true
,
appVersion
,
false
)
...
...
@@ -352,6 +385,18 @@ Options:
appExit
(
0
)
}
if
arguments
[
"--wildcard"
]
==
true
{
ArtifactoryBase
:=
"https://artifactory.software.geant.org/artifactory/acme-downloader"
ArtifactName
:=
fmt
.
Sprintf
(
"acme-downloader_%v_%v"
,
runtime
.
GOOS
,
runtime
.
GOARCH
)
ToolName
:=
os
.
Args
[
0
]
ArtifactURL
:=
fmt
.
Sprintf
(
"%v/%v"
,
ArtifactoryBase
,
ArtifactName
)
if
runtime
.
GOOS
==
"windows"
{
ArtifactURL
=
fmt
.
Sprintf
(
"%v/%v.exe"
,
ArtifactoryBase
,
ArtifactName
)
}
downloadFile
(
ToolName
,
ArtifactURL
)
fmt
.
Printf
(
"%v updated successfully!
\n
"
,
ToolName
)
}
if
runtime
.
GOOS
==
"windows"
{
tmpCertificateDestination
=
"C:
\\
tmp
\\
acme-downloader
\\
cert
\\
amce_cert.pem"
tmpFullchainDestination
=
"C:
\\
tmp
\\
acme-downloader
\\
cert
\\
amce_fullchain.pem"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment