mirror of
https://github.com/rancher/os.git
synced 2025-08-01 15:08:47 +00:00
Support URL when using ros install -c (#2202)
This commit is contained in:
parent
b08d29cc2c
commit
3b92e04065
@ -158,8 +158,14 @@ func installAction(c *cli.Context) error {
|
||||
} else {
|
||||
os.MkdirAll("/opt", 0755)
|
||||
uc := "/opt/user_config.yml"
|
||||
if err := util.FileCopy(cloudConfig, uc); err != nil {
|
||||
log.WithFields(log.Fields{"cloudConfig": cloudConfig, "error": err}).Fatal("Failed to copy cloud-config")
|
||||
if strings.HasPrefix(cloudConfig, "http://") || strings.HasPrefix(cloudConfig, "https://") {
|
||||
if err := util.HTTPDownloadToFile(cloudConfig, uc); err != nil {
|
||||
log.WithFields(log.Fields{"cloudConfig": cloudConfig, "error": err}).Fatal("Failed to http get cloud-config")
|
||||
}
|
||||
} else {
|
||||
if err := util.FileCopy(cloudConfig, uc); err != nil {
|
||||
log.WithFields(log.Fields{"cloudConfig": cloudConfig, "error": err}).Fatal("Failed to copy cloud-config")
|
||||
}
|
||||
}
|
||||
cloudConfig = uc
|
||||
}
|
||||
|
14
util/util.go
14
util/util.go
@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
@ -45,6 +46,19 @@ func FileCopy(src, dest string) error {
|
||||
return WriteFileAtomic(dest, data, 0666)
|
||||
}
|
||||
|
||||
func HTTPDownloadToFile(url, dest string) error {
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return WriteFileAtomic(dest, body, 0666)
|
||||
}
|
||||
|
||||
func WriteFileAtomic(filename string, data []byte, perm os.FileMode) error {
|
||||
dir, file := path.Split(filename)
|
||||
tempFile, err := ioutil.TempFile(dir, fmt.Sprintf(".%s", file))
|
||||
|
Loading…
Reference in New Issue
Block a user