Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
feat(Makefile): create shell script installer
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Aug 28, 2014
1 parent dce34ce commit 2ae953e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
@@ -1,2 +1,8 @@
package/
deisctl/deisctl

# ctags index
tags

# installer droppings
dist/
13 changes: 13 additions & 0 deletions LICENSE
@@ -0,0 +1,13 @@
Copyright 2014 OpDemand LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
8 changes: 8 additions & 0 deletions Makefile
Expand Up @@ -3,6 +3,14 @@ COMPONENTS=builder cache controller database logger registry router
build:
godep go build ./...

installer:
rm -rf dist && mkdir -p dist
godep go build -a -o dist/deisctl .
command -v upx >/dev/null 2>&1 && upx --best --ultra-brute -q dist/deisctl
makeself.sh --current --nox11 dist \
dist/deisctl-`cat deis-version`-`go env GOOS`-`go env GOARCH`.run \
"Deis Control CLI" "./deisctl refresh-units"

install:
godep go install -v ./...

Expand Down
13 changes: 12 additions & 1 deletion client/unit.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"os/user"
"path"
"regexp"
"strconv"
Expand All @@ -13,7 +14,7 @@ import (
)

// path hierarchy for finding systemd service templates
var rootPaths = []string{"/var/lib/deis/units", "units"}
var rootPaths = []string{"/var/lib/deis/units", "~/.deisctl/units"}

// getUnits returns a list of units filtered by target
func (c *FleetClient) Units(target string) (units []string, err error) {
Expand Down Expand Up @@ -118,6 +119,7 @@ func readTemplate(component string) (out []byte, err error) {
} else {
// otherwise look in rootPaths hierarchy
for _, rootPath := range rootPaths {
rootPath, _ := expandUser(rootPath)
filename := path.Join(rootPath, templateName)
if _, err := os.Stat(filename); err == nil {
templateFile = filename
Expand All @@ -135,3 +137,12 @@ func readTemplate(component string) (out []byte, err error) {
}
return
}

// expandUser replaces "~" in a string with the current user's home directory.
func expandUser(path string) (string, error) {
user, err := user.Current()
if err != nil {
return path, err
}
return strings.Replace(path, "~/", user.HomeDir, 1), nil
}
52 changes: 52 additions & 0 deletions cmd/cmd.go
Expand Up @@ -2,6 +2,11 @@ package cmd

import (
"fmt"
"io/ioutil"
"net/http"
"os"
"os/user"
"path/filepath"
"regexp"
"strconv"

Expand Down Expand Up @@ -250,3 +255,50 @@ func Update() error {
}
return nil
}

func RefreshUnits() error {
// create the $HOME/.deisctl directory if necessary
user, err := user.Current()
if err != nil {
return err
}
dir := filepath.Join(user.HomeDir, ".deisctl")
if err = os.MkdirAll(dir, 0700); err != nil {
return err
}

// download and save the unit files to $HOME/.deisctl
rootUrl := "https://raw.githubusercontent.com/deis/deisctl/"
branch := "master"
units := []string{
"deis-builder.service",
"deis-builder-data.service",
"deis-cache.service",
"deis-controller.service",
"deis-database.service",
"deis-database-data.service",
"deis-logger.service",
"deis-logger-data.service",
"deis-registry.service",
"deis-registry-data.service",
"deis-router.service",
}
for _, unit := range units {
src := rootUrl + branch + "/units/" + unit
dest := filepath.Join(dir, unit)
res, err := http.Get(src)
if err != nil {
return err
}
defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
if err != nil {
return err
}
if err = ioutil.WriteFile(dest, data, 0600); err != nil {
return err
}
fmt.Printf("Refreshed %s from %s\n", unit, branch)
}
return nil
}
2 changes: 2 additions & 0 deletions deisctl.go
Expand Up @@ -108,6 +108,8 @@ Options:
err = cmd.Config()
case "update":
err = cmd.Update()
case "refresh-units":
err = cmd.RefreshUnits()
default:
fmt.Printf(usage)
os.Exit(2)
Expand Down

0 comments on commit 2ae953e

Please sign in to comment.