コード例 #1
0
ファイル: file.go.go プロジェクト: andradeandrey/goadmin
func main() {
	ago.Import("fmt")
	ago.Code(`fmt.Println("I am thinking about changing some files...")`)
	// Want all machines to have the same /etc/motd
	motd, _ := file.Read("/etc/motd")
	motd.GoSet(file.All)
	tmp := file.File{file.StatData{"/tmp/test-from-asroot", 0, 0, 0666, file.IsFile}, "Some demo contents\n"}
	tmp.GoSet(file.All)

	demofiles, e := file.Read("demo-files")
	if e == nil {
		fmt.Println("I am going output demo-files")
		demofiles.Move(".", "/tmp")
		demofiles.GoSet(file.All)
	} else {
		fmt.Println("Error reading demo-files: ", e)
	}

	subdir, e := file.Read("demo-files/subdir")
	if e == nil {
		fmt.Println("I am going output demo-files/subdir")
		subdir.Move("demo-files", "/tmp")
		subdir.GoSet(file.All)
	} else {
		fmt.Println("Error reading subdir: ", e)
	}

	ago.Code(`if file_changed { fmt.Println("I changed a file!") }`)
	ago.Print("files")
}
コード例 #2
0
ファイル: gomakefile.go プロジェクト: andradeandrey/goadmin
func GoAddDep(dependency string) {
	ago.Import("github.com/droundy/goadmin/gomakefile")
	ago.Declare("var changed_files = make(map[string]bool)")
	ago.Declare("var this_file_changed = false")
	code := "this_file_changed, e = gomakefile.AddDep(" + strconv.Quote(dependency) + ")"
	code += fmt.Sprint("\n\tif this_file_changed { changed_files[`Makefile`] = true }")
	ago.Code(code)
}
コード例 #3
0
ファイル: hosts.go プロジェクト: andradeandrey/goadmin
func (ent Entry) GoSet() {
	ago.Import("github.com/droundy/goadmin/hosts")
	code := "e = hosts.Entry{"+strconv.Quote(ent.IpAddress)+","+
		strconv.Quote(ent.CanonicalName)+", []string{"
	as := make([]string, len(ent.Aliases))
	for i := range ent.Aliases {
		as[i] = strconv.Quote(ent.Aliases[i])
	}
	code += strings.Join(as, ", ") +  " } }.Set()"
	ago.Code(code)
}
コード例 #4
0
ファイル: passwd.go プロジェクト: andradeandrey/goadmin
func (u User) GoSet(f Field) {
	if !havepasswords && f&Passwd != 0 {
		fmt.Fprintln(os.Stderr, "Refusing to set password for", u.Name, ", since we can't read /etc/shadow!")
		f = f ^ Passwd // Don't set password if we can't read /etc/shadow!
	}
	if f == 0 {
		return
	} // Nothing to set!
	ago.Import("github.com/droundy/goadmin/passwd")
	code := "e = passwd.User{" + strconv.Quote(u.Name) + ","
	if Passwd&f != 0 {
		code += strconv.Quote(u.Passwd) + ","
	} else {
		code += `"",`
	}
	code += fmt.Sprint(u.Uid, ",", u.Gid, ",")
	code += fmt.Sprint(strconv.Quote(u.Comment), ",", strconv.Quote(u.Home), ",", strconv.Quote(u.Shell))
	code += fmt.Sprint("}.Set(", f, ")")
	code += fmt.Sprint("\n\tif e != nil { return }")
	ago.Code(code)
}
コード例 #5
0
ファイル: file.go プロジェクト: andradeandrey/goadmin
func (f *File) GoSet(which Field) {
	if which == 0 {
		return
	} // Nothing to set!
	ago.Import("github.com/droundy/goadmin/file")
	ago.Declare("var changed_files = make(map[string]bool)")
	ago.Declare("var file_changed = false")
	ago.Declare("var this_file_changed = false")
	ago.Declare("var myf file.File")
	code := "myf = file.File{file.StatData{" + strconv.Quote(f.Name) + ","
	code += fmt.Sprint(f.Uid, ",", f.Gid, ", 0", strconv.Itob(int(f.Perms), 8), ", file.IsFile},")
	if Contents&which != 0 {
		code += strconv.Quote(f.Contents) + "}"
	} else {
		code += `""}`
	}
	code += fmt.Sprint("\n\tthis_file_changed, e = myf.Set(", which, ")")
	code += fmt.Sprint("\n\tif e != nil { fmt.Println(`Trouble setting", f.Name, ":`,e); return }")
	code += fmt.Sprint("\n\tif this_file_changed { changed_files[`", f.Name, "`] = true }")
	code += fmt.Sprint("\n\tfile_changed = file_changed || this_file_changed")
	ago.Code(code)
}
コード例 #6
0
ファイル: file.go プロジェクト: andradeandrey/goadmin
func (f *Directory) GoSet(which Field) {
	if which == 0 {
		return
	} // Nothing to set!
	ago.Import("github.com/droundy/goadmin/file")
	ago.Declare("var changed_files = make(map[string]bool)")
	ago.Declare("var file_changed = false")
	ago.Declare("var this_file_changed = false")
	ago.Declare("var myd file.Directory")
	code := "myd = file.Directory{file.StatData{" + strconv.Quote(f.Name) + ","
	code += fmt.Sprint(f.Uid, ",", f.Gid, ", 0", strconv.Itob(int(f.Perms), 8), ", file.IsFile},")
	code += `map[string]file.StatEntry{}}`
	code += fmt.Sprint("\n\tthis_file_changed, e = myd.Set(", which, ")")
	code += fmt.Sprint("\n\tif e != nil { return }")
	code += fmt.Sprint("\n\tif this_file_changed { changed_files[`", f.Name, "`] = true }")
	code += fmt.Sprint("\n\tfile_changed = file_changed || this_file_changed")
	ago.Code(code)
	if Contents&which != 0 {
		for _, x := range f.Contents {
			x.GoSet(which)
		}
	}
}