Added "config show" to oz-setup

master
xSmurf 9 years ago
parent 01ab72df23
commit eb09a54c9a

@ -4,6 +4,8 @@ import (
"fmt"
"os"
"os/exec"
"reflect"
"strconv"
"strings"
"syscall"
@ -31,7 +33,7 @@ func main() {
app.Usage = "command line interface to install, remove, and create Oz sandboxes\nYou can specify a package name, a binary path, or a Oz profile file "
app.Author = "Subgraph"
app.Email = "info@subgraph.com"
app.Version = "0.0.1"
app.Version = oz.OzVersion
app.EnableBashCompletion = true
flagsHookMode := []cli.Flag{
@ -91,7 +93,62 @@ func handleConfigcheck(c *cli.Context) {
}
func handleConfigshow(c *cli.Context) {
handleConfigcheck(c)
config, err := oz.LoadConfig(oz.DefaultConfigPath)
useDefaults := false
if err != nil {
if os.IsNotExist(err) {
config = oz.NewDefaultConfig()
useDefaults = true
} else {
fmt.Fprintf(os.Stderr, "Could not load configuration: %s", oz.DefaultConfigPath, err)
os.Exit(1)
}
}
v := reflect.ValueOf(*config)
vt := reflect.TypeOf(*config)
maxFieldLength := 0
for i := 0; i < v.NumField(); i++ {
flen := len(vt.Field(i).Tag.Get("json"))
if flen > maxFieldLength {
maxFieldLength = flen
}
}
maxValueLength := 0
for i := 0; i < v.NumField(); i++ {
sval := fmt.Sprintf("%v", v.Field(i).Interface())
flen := len(sval)
if flen > maxValueLength {
maxValueLength = flen
}
}
sfmt := "%-" + strconv.Itoa(maxFieldLength) + "s: %-" + strconv.Itoa(maxValueLength) + "v"
hfmt := "%-" + strconv.Itoa(maxFieldLength) + "s: %s\n"
if !useDefaults {
fmt.Printf(hfmt, "Config file", oz.DefaultConfigPath)
} else {
fmt.Printf(hfmt, "Config file", "Not found - using defaults")
}
for i := 0; i < len(fmt.Sprintf(sfmt, "", "")); i++ {
fmt.Print("=")
}
fmt.Println("")
for i := 0; i < v.NumField(); i++ {
fval := fmt.Sprintf("%v", v.Field(i).Interface())
fmt.Printf(sfmt, vt.Field(i).Tag.Get("json"), fval)
desc := vt.Field(i).Tag.Get("desc")
if desc != "" {
fmt.Printf(" # %s", desc)
}
fmt.Println("")
}
os.Exit(0)
}
func handleInstall(c *cli.Context) {

@ -10,18 +10,18 @@ import (
)
type Config struct {
ProfileDir string `json:"profile_dir"`
ShellPath string `json:"shell_path"`
InitPath string `json:"init_path"`
ClientPath string `json:"client_path"`
SandboxPath string `json:"sandbox_path"`
BridgeMACAddr string `json:"bridge_mac"`
DivertSuffix string `json:"divert_suffix"`
NMIgnoreFile string `json:"nm_ignore_file"`
UseFullDev bool `json:"use_full_dev"`
AllowRootShell bool `json:"allow_root_shell"`
LogXpra bool `json:"log_xpra"`
EnvironmentVars []string `json:"environment_vars"`
ProfileDir string `json:"profile_dir" desc:"Directory containing the sandbox profiles"`
ShellPath string `json:"shell_path" desc:"Path of the shell using when entering a sandbox"`
InitPath string `json:"init_path" desc:"Path to the 'oz-init' binary"`
ClientPath string `json:"client_path" desc:"Path to the 'oz' client binary "`
SandboxPath string `json:"sandbox_path" desc:"Path of the sandboxes base"`
BridgeMACAddr string `json:"bridge_mac" desc:"MAC Address of the bridge interface"`
DivertSuffix string `json:"divert_suffix" desc:"Suffix using for dpkg-divert of application executables"`
NMIgnoreFile string `json:"nm_ignore_file" desc:"Path to the NetworkManager ignore config file"`
UseFullDev bool `json:"use_full_dev" desc:"Give sandboxes full access to devices instead of a restricted set"`
AllowRootShell bool `json:"allow_root_shell" desc:"Allow entering a sandbox shell as root"`
LogXpra bool `json:"log_xpra" desc:"Log output of Xpra"`
EnvironmentVars []string `json:"environment_vars" desc:"Default environment variables passed to sandboxes"`
}
const OzVersion = "0.0.1"

@ -26,7 +26,6 @@ func init() {
case "oz":
runFunc = runApplication
default:
// TODO: Exit if already inside sandbox should only happen
runFunc = runSandbox
}
}

@ -15,7 +15,7 @@ type Profile struct {
// Path to binary to launch
Path string
// Path of the config file
ConfigPath string `json:"-"`
ProfilePath string `json:"-"`
// Optional path of binary to watch for watchdog purposes if different than Path
Watchdog string
// Optional wrapper binary to use when launching command (ex: tsocks)
@ -153,6 +153,6 @@ func loadProfileFile(file string) (*Profile, error) {
if p.Name == "" {
p.Name = path.Base(p.Path)
}
p.ConfigPath = file
p.ProfilePath = file
return p, nil
}

Loading…
Cancel
Save