示例#1
0
文件: main.go 项目: ipfs/refs
func main() {
	u := flag.String("uri", "127.0.0.1:5001", "the IPFS API endpoint to use")
	c := flag.String("current", "/ipns/refs.ipfs.io", "add links to previous versions")
	flag.Parse()

	sh := shell.NewShell(*u)

	h, err := dmca.AddDenylist(sh)
	if err != nil {
		log.Fatalf("dmca.AddDenylist: %s", err)
	}

	if len(*c) > 0 {
		p, err := addPrevious(sh, h, *c+"/lists/denylists/dmca")
		if err != nil {
			log.Printf("could not add previous link: %s\n", err)
		} else {
			h = p
		}
	}

	h, err = addSkeleton(sh, h)
	if err != nil {
		log.Fatalf("main.addSkeleton: %s", err)
	}

	fmt.Println(h)
}
示例#2
0
文件: main.go 项目: lgierth/pinbot
func main() {
	name := flag.String("name", "pinbot-test", "set pinbots name")
	server := flag.String("server", "irc.freenode.net:6667", "set server to connect to")
	flag.Parse()

	for _, h := range loadHosts() {
		shs = append(shs, shell.NewShell(h))
	}

	con, err := hb.NewIrcConnection(*server, *name, false, true)
	if err != nil {
		panic(err)
	}

	connectToFreenodeIpfs(con)
	fmt.Println("Connection lost! attempting to reconnect!")
	con.Close()

	recontime := time.Second
	for {
		// Dont try to reconnect this time
		con, err := hb.NewIrcConnection(*server, *name, false, false)
		if err != nil {
			fmt.Println("ERROR CONNECTING: ", err)
			time.Sleep(recontime)
			recontime += time.Second
			continue
		}
		recontime = time.Second

		connectToFreenodeIpfs(con)
		fmt.Println("Connection lost! attempting to reconnect!")
		con.Close()
	}
}
// Creates a unixfs structure of notice/object tuples,
// e.g. /ipfs/Qmdenylist/2015-09-24-Qmobject/notice (the rendered notice)
// and /ipfs/Qmdenylist/2015-09-24-Qmobject/object (link to Qmobject)
//
// Each object listed in a keys file will get its own tuple with a link
// name of the form <dirname>-<key>.
func main() {
	u := flag.String("uri", "127.0.0.1:5001", "the IPFS API endpoint to use")
	flag.Parse()

	noticeTemplate = template.Must(template.New("notice").Parse(string(noticeBytes)))

	sh := shell.NewShell(*u)

	h, err := addDenylist("./", sh)
	if err != nil {
		log.Fatalf("denylist failed: %s\n", err)
	}

	h, err = addPrevious("./versions/history", h, sh)
	if err != nil {
		log.Fatalf("previous failed: %s\n", err)
	}

	fmt.Println(h)
}
示例#4
0
文件: main.go 项目: rht/gx
func main() {
	cwd, err := os.Getwd()
	if err != nil {
		fmt.Println("error: ", err)
		return
	}

	pm := &PM{
		shell: sh.NewShell("localhost:5001"),
	}

	err = pm.CheckDaemon()
	if err != nil {
		fmt.Printf("%s requires a running ipfs daemon (%s)\n", os.Args[0], err)
		return
	}

	var global bool
	var lang string
	var verbose bool
	var pkgname string

	var GxCommand = &cobra.Command{
		Use:   "gx",
		Short: "gx is a packaging tool that uses ipfs",
	}

	var PublishCommand = &cobra.Command{
		Use:   "publish",
		Short: "publish a package",
		Run: func(cmd *cobra.Command, args []string) {
			pkg, err := LoadPackageFile(PkgFileName)
			if err != nil {
				fmt.Println("error: ", err)
				return
			}

			hash, err := pm.PublishPackage(cwd, pkg)
			if err != nil {
				fmt.Printf("error: %s\n", err)
				return
			}
			fmt.Printf("package %s published with hash: %s\n", pkg.Name, hash)

			// write out version hash
			fi, err := os.Create(".gxlastpubver")
			if err != nil {
				fmt.Printf("failed to create version file: %s\n", err)
				return
			}
			_, err = fi.Write([]byte(hash))
			if err != nil {
				fmt.Printf("failed to write version file: %s\n", err)
				return
			}
		},
	}

	var ImportCommand = &cobra.Command{
		Use:   "import",
		Short: "import a package as a dependency",
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) == 0 {
				fmt.Println("import requires a package name")
				return
			}

			pkg, err := LoadPackageFile(PkgFileName)
			if err != nil {
				fmt.Println("error: ", err)
				return
			}

			depname := args[0]

			ndep, err := pm.GetPackage(depname)
			if err != nil {
				fmt.Printf("error: %s\n", err)
				return
			}

			pkg.Dependencies = append(pkg.Dependencies,
				&Dependency{
					Name: ndep.Name,
					Hash: depname,
				},
			)

			err = SavePackageFile(pkg, PkgFileName)
			if err != nil {
				fmt.Printf("error writing pkgfile: %s\n", err)
				return
			}
		},
	}

	var InstallCommand = &cobra.Command{
		Use:   "install",
		Short: "install a package",
		Run: func(cmd *cobra.Command, args []string) {
			pkg, err := LoadPackageFile(PkgFileName)
			if err != nil {
				fmt.Println("error: ", err)
				return
			}
			location := cwd + "/vendor/src"
			if global {
				location = os.Getenv("GOPATH") + "/src"
			}

			err = pm.InstallDeps(pkg, location)
			if err != nil {
				fmt.Println(err)
				return
			}
		},
	}

	var GetCommand = &cobra.Command{
		Use:   "get",
		Short: "download a package",
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) == 0 {
				fmt.Println("no package specified")
				return
			}

			pkg := args[0]

			_, err := pm.getPackageLocalDaemon(pkg, cwd)
			if err != nil {
				fmt.Printf("error fetching package: %s\n", err)
				return
			}
		},
	}

	var InitCommand = &cobra.Command{
		Use:   "init",
		Short: "initialize a package in the current working directory",
		Run: func(cmd *cobra.Command, args []string) {
			var pkgname string
			if len(args) > 0 {
				pkgname = args[0]
			} else {
				pkgname = path.Base(cwd)
			}
			fmt.Printf("initializing package %s...\n", pkgname)

			// check for existing packagefile
			_, err := os.Stat(PkgFileName)
			if err == nil {
				fmt.Println("package file already exists in working dir")
				return
			}

			pkg := new(Package)
			pkg.Name = pkgname
			pkg.Language = lang
			pkg.Version = "1.0.0"
			err = SavePackageFile(pkg, PkgFileName)
			if err != nil {
				fmt.Printf("save error: %s\n", err)
				return
			}
		},
	}

	var UpdateCommand = &cobra.Command{
		Use:   "update",
		Short: "update a package dependency",
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) < 2 {
				fmt.Println("update requires two arguments, current and target")
				return
			}

			existing := args[0]
			target := args[1]
			// TODO: ensure both args are the 'same' package (same name at least)

			pkg, err := LoadPackageFile(PkgFileName)
			if err != nil {
				fmt.Println("error: ", err)
				return
			}

			npkg, err := pm.GetPackage(target)
			if err != nil {
				fmt.Println("(getpackage) error: ", err)
				return
			}

			err = pm.InstallDeps(npkg, cwd+"/vendor/src")
			if err != nil {
				fmt.Println("(installdeps) error: ", err)
				return
			}

			for _, dep := range pkg.Dependencies {
				if dep.Hash == existing {
					dep.Hash = target
				}
			}

			err = SavePackageFile(pkg, PkgFileName)
			if err != nil {
				fmt.Printf("error writing package file: %s\n", err)
				return
			}

			fmt.Println("now update your source with:")
			fmt.Printf("sed -i s/%s/%s/ ./*\n", existing, target)
		},
	}

	var BuildCommand = &cobra.Command{
		Use:   "build",
		Short: "build a package",
		Run: func(cmd *cobra.Command, args []string) {
			pkg, err := LoadPackageFile(PkgFileName)
			if err != nil {
				fmt.Println("error: ", err)
				return
			}

			switch pkg.Language {
			case "go":
				env := os.Getenv("GOPATH")
				os.Setenv("GOPATH", env+":"+cwd+"/vendor")
				cmd := exec.Command("go", "build")
				cmd.Env = os.Environ()
				out, err := cmd.CombinedOutput()
				if err != nil {
					fmt.Printf("build error: %s\n", err)
				}
				fmt.Print(string(out))
			default:
				fmt.Println("language unrecognized or unspecified")
				return
			}
		},
	}

	GxCommand.Flags().BoolVar(&verbose, "v", false, "verbose output")

	GxCommand.AddCommand(PublishCommand)
	GxCommand.AddCommand(GetCommand)
	GxCommand.AddCommand(InitCommand)
	InitCommand.Flags().StringVar(&lang, "lang", "", "specify the primary language of the package")

	GxCommand.AddCommand(ImportCommand)
	ImportCommand.Flags().StringVar(&pkgname, "name", "", "specify the name to be used for the imported package")

	GxCommand.AddCommand(InstallCommand)
	InstallCommand.Flags().BoolVar(&global, "global", false, "install to global scope")

	GxCommand.AddCommand(BuildCommand)
	GxCommand.AddCommand(UpdateCommand)
	err = GxCommand.Execute()
	if err != nil {
		fmt.Println(err)
	}
}