-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
83 lines (71 loc) · 1.79 KB
/
main.go
File metadata and controls
83 lines (71 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"os"
"os/user"
"strings"
"time"
"github.com/FrameworkOSS/feature"
shell "github.com/FrameworkOSS/feature_shell"
stdlib "github.com/FrameworkOSS/feature_stdlib"
"github.com/FrameworkOSS/portal"
)
func main() {
osHost, err := os.Hostname()
if err != nil {
osHost = "builder"
}
osUser, err := user.Current()
if err != nil {
osUser = &user.User{Username: "shell"}
}
opts := portal.NewPortalOptions().
SetLog(true).
SetExport(false).
SetID(osHost)
p := portal.NewPortal(opts)
initCmds := make([]string, 0)
if args := os.Args; len(args) > 1 {
args = args[1:]
initStr := strings.Join(args, " ")
initCmds = strings.Split(initStr, ";")
for i := range initCmds {
initCmds[i] = strings.TrimSpace(initCmds[i])
}
initCmds = append(initCmds, "sleep 100")
initCmds = append(initCmds, "exit -code 0") //Terminate the shell instead of prompting for input!
}
sh := shell.NewShell(p, osUser.Username, false, true, initCmds...)
if err := p.BatchFeatureAdd(sh); err != nil {
panic(err)
}
std := stdlib.NewStdlib(p, false, false, false)
features := []feature.Feature{std}
if err := p.BatchFeatureAdd(features...); err != nil {
panic(err)
}
if err := p.Open(); err != nil {
panic(err)
}
featureWait := []string{sh.ID()}
for i := 0; i < len(features); i++ {
featureWait = append(featureWait, features[i].ID())
}
//Wait for the shell and all of our installed features to open.
for {
time.Sleep(p.OptionsGet().GetPollTimeOut())
if p.FeatureIsReady(featureWait...) {
break
}
}
//Wait for the shell or one of our installed features to close.
for {
time.Sleep(p.OptionsGet().GetPollTimeOut())
if !p.FeatureIsReady(featureWait...) {
break
}
}
//Wait for the portal to attempt an exit.
for {
time.Sleep(p.OptionsGet().GetPollTimeOut())
}
}