appmanager: with web interface to upload chart archives
diff --git a/appmanager/cmd/main.go b/appmanager/cmd/main.go
index f3b009d..79658a1 100644
--- a/appmanager/cmd/main.go
+++ b/appmanager/cmd/main.go
@@ -1,22 +1,87 @@
 package main
 
 import (
-	app "github.com/giolekva/pcloud/appmanager"
+	"flag"
+	"fmt"
+	"io"
+	"log"
+	"net/http"
+	"os"
 
-	"github.com/golang/glog"
+	// "github.com/golang/glog"
+
+	app "github.com/giolekva/pcloud/appmanager"
 )
 
-func main() {
-	unpacker := app.NewHelmUnpacker("/usr/local/bin/helm")
-	temps, err := unpacker.Unpack("/Users/lekva/dev/go/src/github.com/giolekva/pcloud/apps/rpuppy/chart",
-		"app-rpuppy",
-		map[string]string{
-			"replicas":    "2",
-			"servicePort": "8080",
-		},
-	)
-	if err != nil {
-		panic(err)
+var port = flag.Int("port", 1234, "Port to listen on.")
+
+var helmUploadPage = `
+<html>
+<head>
+       <title>Upload Helm chart</title>
+</head>
+<body>
+<form enctype="multipart/form-data" action="/" method="post">
+    <input type="file" name="chartfile" />
+    <input type="submit" value="upload" />
+</form>
+</body>
+</html>
+`
+
+func helmHandler(w http.ResponseWriter, r *http.Request) {
+	if r.Method == "GET" {
+		_, err := io.WriteString(w, helmUploadPage)
+		if err != nil {
+			http.Error(w, err.Error(), http.StatusInternalServerError)
+		}
+	} else if r.Method == "POST" {
+		r.ParseMultipartForm(1000000)
+		file, handler, err := r.FormFile("chartfile")
+		if err != nil {
+			http.Error(w, err.Error(), http.StatusInternalServerError)
+			return
+		}
+		defer file.Close()
+		p := "/tmp/" + handler.Filename
+		f, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE, 0666)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		defer f.Close()
+		_, err = io.Copy(f, file)
+		if err != nil {
+			http.Error(w, err.Error(), http.StatusInternalServerError)
+			return
+		}
+		if err = installHelmChart(p); err != nil {
+			http.Error(w, err.Error(), http.StatusInternalServerError)
+			return
+		}
+		w.Write([]byte("Installed"))
 	}
-	glog.Info(temps)
+}
+
+func installHelmChart(path string) error {
+	h, err := app.HelmChartFromDir("/Users/lekva/dev/go/src/github.com/giolekva/pcloud/apps/rpuppy/chart")
+	if err != nil {
+		return err
+	}
+	// err = app.InstallSchema(h.Schema, "http://localhost:1111/add_schema")
+	// if err != nil {
+	// 	return err
+	// }
+	// glog.Infof("Installed schema: %s", h.Schema)
+	err = h.Install(
+		"/usr/local/bin/helm",
+		map[string]string{})
+	return err
+}
+
+func main() {
+	flag.Parse()
+	http.HandleFunc("/", helmHandler)
+	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
+
 }