Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
emli committed Mar 15, 2018
1 parent cecadc8 commit 6934547
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/subutai-io/gorjun/download"
"github.com/subutai-io/gorjun/upload"
"net/url"
"os/exec"
)

func readTempl(hash string) (configfile string, err error) {
Expand Down Expand Up @@ -180,6 +181,7 @@ func Download(w http.ResponseWriter, r *http.Request) {
// }

func Info(w http.ResponseWriter, r *http.Request) {
ModifyConfig()
if r.Method != "GET" {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Incorrect method"))
Expand Down Expand Up @@ -263,3 +265,52 @@ func delTag(values map[string][]string) (int, error) {
}
return http.StatusBadRequest, fmt.Errorf("Bad request")
}

func ModifyConfig() {
list := db.Search("")
for _, k := range list {
if db.CheckRepo("", "template", k) == 0 {
continue
}
item := download.FormatItem(db.Info(k), "template", "")
//cmd := exec.Command("bash", "-c", "mkdir myfolder " + item.Hash.Md5)
//cmd.Dir = config.Storage.Path
//err := cmd.Run()
//if err != nil {
// log.Fatal(err)
// log.Info("Can't run dpkg-scanpackages")
//}
cmd := exec.Command("bash", "-c", "tar -C "+config.Storage.Path+"/myfolder"+" -xvzf "+item.Hash.Md5)

cmd.Dir = config.Storage.Path
err := cmd.Run()
if err != nil {
log.Fatal(err)
log.Info("Can't run dpkg-scanpackages")
}
prepareMetaData(item)
appendFile()
break
}
}

func appendFile() {
file, err := os.OpenFile(config.Storage.Path+"/myfolder/"+"config", os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
log.Fatal("failed opening file: %s", err)
}
defer file.Close()

_, err = file.WriteString("subutai.template = \ntemplate")
if err != nil {
log.Fatal("failed writing to file: %s", err)
}
}

func prepareMetaData(item download.ListItem) {
s := "subutai.template = " + item.Name + "\n" +
"subutai.template.owner = " + item.Owner[0] + "\n" +
"subutai.parent.owner"
list := db.Search(ite)

}

0 comments on commit 6934547

Please sign in to comment.