Exemple #1
0
func runType(x *xEnv, argv ...string) error {
	defer app.Exiting()
	opts := opt.New("{name}")
	app.Dprintf("type %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		app.Exits(dbg.ErrUsage)
	}
	for _, n := range args {
		app.Printf("%s: %s\n", n, x.ntype(n))
	}
	app.Exits(nil)
	return nil
}
Exemple #2
0
// runs here
func runWait(x *xEnv, argv ...string) error {
	opts := opt.New("wait")
	app.Dprintf("wait %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		return dbg.ErrUsage
	}
	if len(args) == 0 {
		args = []string{"&"}
	}
	if len(args) != 1 {
		opts.Usage()
		return dbg.ErrUsage
	}
	x.wait(args[0])
	return nil
}
Exemple #3
0
// runs here
func runCd(x *xEnv, argv ...string) error {
	opts := opt.New("")
	app.Dprintf("cd %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		return dbg.ErrUsage
	}
	if len(args) != 0 {
		opts.Usage()
		return dbg.ErrUsage
	}
	m, ok := <-app.In()
	if !ok {
		err = cerror(app.In())
		app.Warn("%s", err)
		return err
	}
	d, ok := m.(zx.Dir)
	if !ok {
		b, ok := m.([]byte)
		if !ok {
			app.Warn("%s", dbg.ErrNotDir)
			return dbg.ErrNotDir
		}
		s := string(b)
		d, err = nsutil.Stat(s)
		if err != nil {
			app.Warn("%s: %s", s, err)
			return err
		}
	}
	if d["type"] != "d" {
		app.Warn("%s: %s", d["path"], dbg.ErrNotDir)
		return dbg.ErrNotDir
	}
	app.Cd(d["path"])
	out := app.Out()
	if out != nil {
		out <- d
	}
	return nil
}
Exemple #4
0
// runs here
func runNew(x *xEnv, argv ...string) error {
	opts := opt.New("dup")
	app.Dprintf("dup %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		return dbg.ErrUsage
	}
	for _, arg := range args {
		switch arg {
		case "ns":
			app.NewNS(nil)
		case "io":
			app.NewIO(nil)
		case "env":
			app.NewEnv(nil)
		case "dot":
			app.NewDot("")
		default:
			app.Warn("unknown resource '%s'", arg)
		}
	}
	return nil
}
Exemple #5
0
	"clive/zx/rfs"
	"errors"
	"fmt"
	"os"
	"path"
	"path/filepath"
	"strings"
)

var (
	Verbose, Debug, Zdebug bool

	Dprintf = dbg.FlagPrintf(os.Stdout, &Debug)
	Vprintf = dbg.FlagPrintf(os.Stdout, &Verbose)

	opts  = opt.New("{spec}")
	port  string
	wport string
	svc   string
	addr  string

	zxw = map[string]string{}
)

func zxwax() {
	ctrl := ctl.NewControl()
	ctrl.BoolFlag("Debug", &Debug)
	ctrl.CmdFlag("Exit", func() {
		dbg.Fatal("exiting at user request")
	})
	wax.ServeLogin("/", "/index")
Exemple #6
0
package main

import (
	"clive/app"
	"clive/app/opt"
	"clive/app/ql/qlfs"
	"clive/dbg"
	"clive/zx"
	"clive/zx/rfs"
	"clive/zx/zxfs"
	"os"
)

var (
	sflag       bool
	opts        = opt.New("[mntdir] &")
	addr, xaddr string
	mntdir      = "/n/ql"
	dprintf     = dbg.FlagPrintf(os.Stderr, &zxfs.Debug)
)

func main() {
	defer app.Exiting()
	x := app.New()
	stacks := false
	opts.NewFlag("F", "debug fuse requests", &zxfs.Debug)
	opts.NewFlag("D", "debug", &x.Debug)
	opts.NewFlag("s", "statistics", &sflag)
	opts.NewFlag("x", "addr: re-export locally the ql tree to this address", &xaddr)
	opts.NewFlag("S", "dump stacks on unmount for debugging", &stacks)
	args, err := opts.Parse(x.Args)
Exemple #7
0
/*
	Simple static web server for UNIX files.
*/
package main

import (
	"clive/app"
	"clive/app/opt"
	"net/http"
	"os"
)

var (
	dir  = "/zx/usr/web"
	port = "8080"
	opts = opt.New("[dir]")
)

func main() {
	defer app.Exiting()
	app.New()
	opts.NewFlag("p", "port: port used (8080 by default)", &port)
	args, err := opts.Parse(os.Args)
	if err != nil {
		app.Warn("%s", err)
		opts.Usage()
		app.Exits(err)
	}
	switch len(args) {
	case 0:
	case 1:
Exemple #8
0
	Restart bool	// restart if the command dies
	At string	// run at time times (cron format: min hour day month wday)
	Bin string	// restart if the binary changes
	Env map[string]string
	x *exec.Cmd
	name string	// Base(dir)
	dir string	// path of the dir for the cmd
	runt time.Time	// start time

	donec chan bool
	sigrestart bool
	bint time.Time
}

var (
	opts = opt.New("")
	debug, verb bool
	dprintf = dbg.FlagPrintf(os.Stderr, &debug)
	vprintf = dbg.FlagPrintf(os.Stderr, &verb)
	shell = "rc"
	dir = "/tmp/xcmd"
	cmd1 string
	ErrNotYet = errors.New("not ready to start")
	ErrExited = errors.New("command has exited")
	ErrRestart = errors.New("restart required")
)


func walk(ds []os.FileInfo, name string) os.FileInfo {
	for _, d := range ds {
		if d.Name() == name {
Exemple #9
0
package main

import (
	"clive/app/opt"
	"clive/dbg"
	"clive/zx/sync"
	"clive/zx/sync/repl"
	"errors"
	"fmt"
	"os"
	"strings"
	"time"
)

var (
	opts                                 = opt.New("cfg [laddr raddr]")
	pullonly, pushonly, skip, dry, print bool
	quiet                                bool
	name                                 string
)

func waitReplTime(name string) {
	t := time.Now()
	dt := time.Date(t.Year(), t.Month(), t.Day(), 3, 0, 0, 0, time.Local)
	if dt.Before(time.Now()) {
		dt = dt.Add(24 * time.Hour)
	}
	dbg.Warn("next %s sync at %v", name, dt)
	delta := dt.Sub(t)
	time.Sleep(delta)
}
Exemple #10
0
import (
	"bytes"
	"clive/app"
	"clive/app/opt"
	"clive/dbg"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path"
	"strings"
)

var (
	opts  = opt.New("{cmd}")
	dummy bool
	ql    = "/n/ql"
)

func main() {
	defer app.Exiting()
	os.Args[0] = "Q"
	c := app.New()
	opts.NewFlag("c", "ignored for compatibility", &dummy)
	opts.NewFlag("D", "debug", &c.Debug)
	edir := dbg.Usr
	opts.NewFlag("e", "env: qlfs environment name (defaults to uid)", &edir)
	opts.NewFlag("q", "qldir: qlfs root dir (defaults to /n/ql)", &ql)
	args, err := opts.Parse(os.Args)
	if err != nil {
Exemple #11
0
	Under flag -f it rewrites the key file even if it exists.
*/
package main

import (
	"clive/app"
	"clive/app/opt"
	"clive/net/auth"
	"os"
)

var (
	dir   string
	force bool
	opts  = opt.New("name user secret [group...]")
)

func main() {
	defer app.Exiting()
	os.Args[0] = "auth"
	app.New()
	dfltdir := auth.KeyDir()
	dir = dfltdir
	opts.NewFlag("d", "adir: clive auth dir", &dir)
	opts.NewFlag("f", "force write of key file when file already exists", &force)
	args, err := opts.Parse(os.Args)
	if err != nil {
		app.Warn("%s", err)
		opts.Usage()
		app.Exits(err)
Exemple #12
0
	"clive/dbg"
	"clive/zx"
	"clive/zx/lfs"
	"os"
	"path"
	"strings"
)

var (
	Debug, Verbose bool
	Dump           string
	Xcludes        []string
	Once           bool
	Skip           bool

	opts    = opt.New("{file|name!file}")
	vprintf = dbg.FlagPrintf(os.Stderr, &Verbose)
	dprintf = dbg.FlagPrintf(os.Stderr, &Debug)
)

func main() {
	defer dbg.Exits("")
	os.Args[0] = "zxdump"
	dfltdump := zx.Path(dbg.Home, "dump")
	opts.NewFlag("s", "don't dump right now, wait until next at 5am", &Skip)
	opts.NewFlag("1", "dump once and exit", &Once)
	opts.NewFlag("v", "verbose", &Verbose)
	opts.NewFlag("D", "debug", &Debug)
	opts.NewFlag("x", "expr: files excluded (.*, tmp.* if none given); tmp always excluded.", &Xcludes)
	Dump = dfltdump
	opts.NewFlag("d", "dir: where to keep the dump, or empty if none", &Dump)
Exemple #13
0
	fs "clive/fuse"
	"clive/x/bazil.org/fuse"
)

var (
	addr         string
	mntdir       = "/n/zx"
	rflag, sflag bool
	nopings      bool

	zxdebug, lfsdebug, rfsdebug, verb bool

	nocache             bool
	lfscache, mlfscache string
	xaddr               string
	opts                = opt.New("addr|dir [mntdir] &")
	dprintf             = dbg.FlagPrintf(os.Stderr, &zxfs.Debug)
)

func mklfs(path string) (zx.RWTree, *zx.Flags, *zx.IOstats, error) {
	ronly := rflag && nocache
	fs, err := lfs.New(path, path, ronly)
	if err != nil {
		return nil, nil, nil, fmt.Errorf("lfs: %s", err)
	}
	if sflag {
		fs.IOstats = &zx.IOstats{}
	}
	fs.Dbg = lfsdebug
	fs.SaveAttrs(true)
	return fs, fs.Flags, fs.IOstats, nil