oc-deploy/src/tool/helm.go

52 lines
971 B
Go
Raw Normal View History

2024-09-02 13:44:44 +02:00
package tool
import (
"fmt"
"os"
"oc-deploy/utils"
"oc-deploy/helm"
)
type HelmInstallData struct {
2024-09-03 13:46:45 +02:00
obj ToolData
tmp string
2024-09-02 13:44:44 +02:00
}
func (this HelmInstallData) Get() (ToolData) {
2024-09-03 13:46:45 +02:00
return this.obj
2024-09-02 13:44:44 +02:00
}
func (this HelmInstallData) Download() (error) {
2024-09-03 13:46:45 +02:00
bin_dir := this.obj.Bin
err2 := os.MkdirAll(bin_dir, os.ModePerm)
if err2 != nil {
fmt.Println(err2)
return err2
}
2024-09-02 13:44:44 +02:00
tmp_file := fmt.Sprintf("%s/oc-deploy-%s", this.tmp, this.obj.Name)
2024-09-03 13:46:45 +02:00
url := fmt.Sprintf(this.obj.Url, this.obj.Version)
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
err := utils.DownloadFromUrl(tmp_file, url, 0777)
if err != nil {
return err
}
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
r, _ := os.Open(tmp_file)
err1 := utils.ExtractTarGz(bin_dir, r)
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
os.Remove(tmp_file)
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
bin_file := fmt.Sprintf("%s/%s", bin_dir, this.obj.Name)
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
os.Chmod(bin_file, 0755)
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
return err1
2024-09-02 13:44:44 +02:00
}
///////////////
func (this HelmInstallData) Version(path string) (string, error) {
2024-09-03 13:46:45 +02:00
return helm.Version(path)
2024-09-02 09:09:46 +02:00
}