コード例 #1
0
ファイル: main.go プロジェクト: hako/afto
// updateRepo updates all the packages that exist in the current repo.
func (af *AftoRepo) updateRepo() {
	af.checkReqs()
	log.Println("updating repo: \"" + af.Name + "\"")
	path, err := afutil.GetRepo(af.Name)
	if err != nil {
		log.Fatalln(err)
	}

	// The debfile we are comparing to in -r <deb>
	inputDeb, err := afutil.ParseDeb(file)
	if err != nil {
		log.Fatalf(aftoUnexpectedError)
	}
	var newDeb, name, version, oldDeb = false, "", "", ""

	// The debfile we are comparing against <repo>
	for _, deb := range af.Debs {
		repodeb, err := afutil.ParseDeb(deb)
		if err != nil {
			log.Fatalf(aftoUnexpectedError)
		}
		if repodeb.Name() == inputDeb.Name() && repodeb.Version() != inputDeb.Version() {
			newDeb = true
			name = inputDeb.Name()
			version = inputDeb.Version()
			oldDeb = deb
		}
	}
	if newDeb != true {
		log.Println("No update is available.")
		os.Exit(0)
	}

	// Copy updated deb outside of folder.
	log.Println("Update is available for \"" + name + "\" version " + version)
	stripedRepo := strings.Replace(path, af.Name, "", -1)
	e := afutil.Copy(af.SingleDeb, stripedRepo+filepath.Base(af.SingleDeb))
	if err != nil {
		fmt.Println(e)
	}

	// Move other debs outside of folder, except old one. Delete that.
	currentDebs, _ := afutil.CheckDebWithPath(path)
	for _, c := range currentDebs {
		if filepath.Base(oldDeb) == c {
			continue
		}
		movedDeb := stripedRepo + filepath.Base(c)
		os.Rename(path+"/"+c, movedDeb)
	}

	// Delete and recreate repo. change command to update.
	os.RemoveAll(path)
	af.Cmd = "new"
	af.newRepo()
}
コード例 #2
0
ファイル: main.go プロジェクト: hako/afto
func main() {
	// Parse flags.
	if len(os.Args) == 1 {
		fmt.Println(usage)
		os.Exit(1)
	}

	// Parse options with docopt.
	opts, _ := docopt.Parse(usage, nil, true, "afto "+version, false)
	log.SetPrefix("afto: ")
	log.SetFlags(2)

	if (opts["-d"] != true && opts["--dir"] != true) && opts["new"] != true && opts["update"] != true && opts["-s"] != true && opts["--sign"] != true {
		fmt.Println("afto: -d or --dir is required")
		os.Exit(1)
	}

	if opts["-p"] == true || opts["--port"] == true {
		argport := opts["<port>"].(string)
		port = argport
	}

	if opts["-f"] == true || opts["--file"] == true {
		optsfile := opts["<file>"].(string)
		file = optsfile
	}

	// Afto -s option.
	if opts["-s"] == true || opts["--sign"] == true {
		repo := opts["<dir>"].(string)
		log.Println("signing repo \"" + repo + "\"")
		err := afutil.SignRepo(repo)
		if err != nil {
			log.Fatalln(err.Error())
		}
		log.Println("repo successfully signed!")
		os.Exit(0)
	}

	// Afto new command.
	if opts["new"] == true {
		name := opts["<name>"].(string)
		af := &AftoRepo{Name: name, Cmd: "new"}
		af.newRepo()
		os.Exit(0)
	}

	// Afto update command.
	if opts["update"] == true {
		var af *AftoRepo
		name := opts["<name>"].(string)

		if file != "" {
			af = &AftoRepo{Name: name, Cmd: "update", SingleDeb: file}
		} else {
			af = &AftoRepo{Name: name, Cmd: "update"}
		}
		af.updateRepo()
		os.Exit(0)
	}

	var dir = opts["<dir>"].(string)

	finalPath, gtderr := afutil.GetRepo(dir)
	if gtderr != nil {
		log.Fatalln(gtderr.Error())
		os.Exit(1)
	}

	repoPath = finalPath

	// afto watches, listens and takes action. (afto listens on 0.0.0.0:[port])
	color.Cyan("afto (αυτο) v" + version + " - the cydia repo generator/manager.")
	color.Cyan("(c) 2016 Wesley Hill (@hako/@hakobyte)")
	fmt.Println("afto is watching & listening for connections on port " + port)

	// Add middleware.
	mx := http.FileServer(http.Dir(repoPath))
	loggingHandler := handlers.LoggingHandler(os.Stdout, mx)

	// AFTODO: Put watcher command here.

	// Spin up a goroutine and serve the repo.
	go func() {
		err := http.ListenAndServe(":"+port, loggingHandler)
		if err != nil {
			fmt.Println("afto: error " + err.Error())
			os.Exit(1)
		}
	}()

	select {}
}