Added "config show" to oz-setup

master
xSmurf 10 years ago
parent 01ab72df23
commit eb09a54c9a

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"reflect"
"strconv"
"strings" "strings"
"syscall" "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.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.Author = "Subgraph"
app.Email = "info@subgraph.com" app.Email = "info@subgraph.com"
app.Version = "0.0.1" app.Version = oz.OzVersion
app.EnableBashCompletion = true app.EnableBashCompletion = true
flagsHookMode := []cli.Flag{ flagsHookMode := []cli.Flag{
@ -91,7 +93,62 @@ func handleConfigcheck(c *cli.Context) {
} }
func handleConfigshow(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) { func handleInstall(c *cli.Context) {

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

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

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

Loading…
Cancel
Save