-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0ff517d
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env sh | ||
set -x -e -u | ||
|
||
ssh $1 mkdir -p /root/go/src/github.com/ngrash/ftl | ||
scp *.go $1:/root/go/src/github.com/ngrash/ftl/ | ||
|
||
|
||
date=$(date +%s) | ||
dst=/var/log/ftl/$date/plans | ||
ssh $1 mkdir -p $dst | ||
scp $2 $1:$dst/../$2 | ||
ssh $1 go run $dst/../$2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package ftl | ||
|
||
import ( | ||
"bytes" | ||
"net/http" | ||
"os/exec" | ||
) | ||
|
||
func Exec(command string, args ...string) (*exec.Cmd, error) { | ||
cmd := exec.Command(command, args...) | ||
var stdout bytes.Buffer | ||
var stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
if err := cmd.Run(); err != nil { | ||
return cmd, err | ||
} | ||
return cmd, nil | ||
} | ||
|
||
func Installed(name string) (bool, error) { | ||
_, err := Exec("dpkg", "-l", name) | ||
if exit, ok := err.(*exec.ExitError); ok { | ||
if exit.ExitCode() == 1 { | ||
return false, nil | ||
} | ||
return false, err | ||
} | ||
return true, nil | ||
} | ||
|
||
func UpdateRepos() error { | ||
_, err := Exec("apt-get", "update") | ||
return err | ||
} | ||
|
||
func Missing(names ...string) []string { | ||
var missing []string | ||
for _, name := range names { | ||
installed, err := Installed(name) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if !installed { | ||
missing = append(missing, name) | ||
} | ||
} | ||
return missing | ||
} | ||
|
||
func Install(names ...string) error { | ||
_, err := Exec("apt-get", append([]string{"install", "--yes"}, names...)...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func DistroCodename() (string, error) { | ||
cmd, err := Exec("lsb_release", "--short", "--codename") | ||
if err != nil { | ||
return "", err | ||
} | ||
return cmd.Stdout.(*bytes.Buffer).String(), nil | ||
} | ||
|
||
func AddRepo(repo, pubKey string) error { | ||
resp, err := http.Get(pubKey) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
cmd := exec.Command("apt-key", "add", "-") | ||
cmd.Stdin = resp.Body | ||
if err := cmd.Run(); err != nil { | ||
return err | ||
} | ||
|
||
_, err = Exec("add-apt-repository", repo) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/ngrash/ftl | ||
|
||
go 1.15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/ngrash/ftl" | ||
) | ||
|
||
func main() { | ||
installDocker() | ||
} | ||
|
||
func must(err error) { | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func installDocker() { | ||
if len(ftl.Missing("docker-ce")) > 0 { | ||
prereqs := []string{"apt-transport-https", "ca-certificates", "curl", "gnupg", "lsb-release"} | ||
if missing := ftl.Missing(prereqs...); len(missing) > 0 { | ||
must(ftl.UpdateRepos()) | ||
must(ftl.Install(missing...)) | ||
} | ||
|
||
codename, err := ftl.DistroCodename() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
must(ftl.AddRepo(fmt.Sprintf("deb [arch=amd64] https://download.docker.com/linux/ubuntu %s stable", codename), "https://download.docker.com/linux/ubuntu/gpg")) | ||
must(ftl.UpdateRepos()) | ||
must(ftl.Install("docker-ce")) | ||
} | ||
} |