Skip to content
Snippets Groups Projects
Unverified Commit a92c021c authored by Massimiliano Adamo's avatar Massimiliano Adamo
Browse files

add self-update script

parent a8271ada
No related branches found
No related tags found
No related merge requests found
......@@ -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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment