Skip to content

Commit 2ae953e

Browse files
committed
feat(Makefile): create shell script installer
1 parent dce34ce commit 2ae953e

6 files changed

Lines changed: 93 additions & 1 deletion

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
package/
22
deisctl/deisctl
3+
4+
# ctags index
5+
tags
6+
7+
# installer droppings
8+
dist/

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2014 OpDemand LLC
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an AS IS BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ COMPONENTS=builder cache controller database logger registry router
33
build:
44
godep go build ./...
55

6+
installer:
7+
rm -rf dist && mkdir -p dist
8+
godep go build -a -o dist/deisctl .
9+
command -v upx >/dev/null 2>&1 && upx --best --ultra-brute -q dist/deisctl
10+
makeself.sh --current --nox11 dist \
11+
dist/deisctl-`cat deis-version`-`go env GOOS`-`go env GOARCH`.run \
12+
"Deis Control CLI" "./deisctl refresh-units"
13+
614
install:
715
godep go install -v ./...
816

client/unit.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io/ioutil"
66
"os"
7+
"os/user"
78
"path"
89
"regexp"
910
"strconv"
@@ -13,7 +14,7 @@ import (
1314
)
1415

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

1819
// getUnits returns a list of units filtered by target
1920
func (c *FleetClient) Units(target string) (units []string, err error) {
@@ -118,6 +119,7 @@ func readTemplate(component string) (out []byte, err error) {
118119
} else {
119120
// otherwise look in rootPaths hierarchy
120121
for _, rootPath := range rootPaths {
122+
rootPath, _ := expandUser(rootPath)
121123
filename := path.Join(rootPath, templateName)
122124
if _, err := os.Stat(filename); err == nil {
123125
templateFile = filename
@@ -135,3 +137,12 @@ func readTemplate(component string) (out []byte, err error) {
135137
}
136138
return
137139
}
140+
141+
// expandUser replaces "~" in a string with the current user's home directory.
142+
func expandUser(path string) (string, error) {
143+
user, err := user.Current()
144+
if err != nil {
145+
return path, err
146+
}
147+
return strings.Replace(path, "~/", user.HomeDir, 1), nil
148+
}

cmd/cmd.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ package cmd
22

33
import (
44
"fmt"
5+
"io/ioutil"
6+
"net/http"
7+
"os"
8+
"os/user"
9+
"path/filepath"
510
"regexp"
611
"strconv"
712

@@ -250,3 +255,50 @@ func Update() error {
250255
}
251256
return nil
252257
}
258+
259+
func RefreshUnits() error {
260+
// create the $HOME/.deisctl directory if necessary
261+
user, err := user.Current()
262+
if err != nil {
263+
return err
264+
}
265+
dir := filepath.Join(user.HomeDir, ".deisctl")
266+
if err = os.MkdirAll(dir, 0700); err != nil {
267+
return err
268+
}
269+
270+
// download and save the unit files to $HOME/.deisctl
271+
rootUrl := "https://raw.githubusercontent.com/deis/deisctl/"
272+
branch := "master"
273+
units := []string{
274+
"deis-builder.service",
275+
"deis-builder-data.service",
276+
"deis-cache.service",
277+
"deis-controller.service",
278+
"deis-database.service",
279+
"deis-database-data.service",
280+
"deis-logger.service",
281+
"deis-logger-data.service",
282+
"deis-registry.service",
283+
"deis-registry-data.service",
284+
"deis-router.service",
285+
}
286+
for _, unit := range units {
287+
src := rootUrl + branch + "/units/" + unit
288+
dest := filepath.Join(dir, unit)
289+
res, err := http.Get(src)
290+
if err != nil {
291+
return err
292+
}
293+
defer res.Body.Close()
294+
data, err := ioutil.ReadAll(res.Body)
295+
if err != nil {
296+
return err
297+
}
298+
if err = ioutil.WriteFile(dest, data, 0600); err != nil {
299+
return err
300+
}
301+
fmt.Printf("Refreshed %s from %s\n", unit, branch)
302+
}
303+
return nil
304+
}

deisctl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ Options:
108108
err = cmd.Config()
109109
case "update":
110110
err = cmd.Update()
111+
case "refresh-units":
112+
err = cmd.RefreshUnits()
111113
default:
112114
fmt.Printf(usage)
113115
os.Exit(2)

0 commit comments

Comments
 (0)