예제 #1
0
파일: main.go 프로젝트: traherom/syncer
func exportKeys(c *cli.Context) {
	localDir := c.String("local")
	password := c.String("password")
	//keyName := c.String("gpg")
	outPath := c.String("out")

	// Command check
	if localDir == "" {
		log.Println("Local directory must be set to export keys")
		return
	}
	if password == "" {
		log.Println("Password to protect keys with must be given")
		return
	}

	log.Println("Loading sync")
	sync, err := core.LoadSync(localDir)
	if err != nil {
		fmt.Printf("Failed to load sync: %v\n", err)
		return
	}

	if outPath == "" {
		outPath = filepath.Join(sync.RemoteBase(), "export.keys")
	}

	if err := sync.ExportKeys(outPath, password); err != nil {
		log.Println("Export failed:", err)
		return
	}

	log.Println("Keys exported to", outPath)
}
예제 #2
0
파일: main.go 프로젝트: traherom/syncer
func importKeys(c *cli.Context) {
	localDir := c.String("local")
	password := c.String("password")
	//keyName := c.String("gpg")
	inPath := c.String("in")

	// Command check
	if localDir == "" {
		log.Println("Local directory must be set to import keys")
		return
	}
	if password == "" {
		log.Println("Password to decrypt keys with must be given")
		return
	}

	log.Println("Loading sync")
	sync, err := core.LoadSync(localDir)
	if err != nil {
		fmt.Printf("Failed to load sync: %v\n", err)
		return
	}

	if inPath == "" {
		inPath = filepath.Join(sync.RemoteBase(), "export.keys")
	}

	if err := sync.ImportKeys(inPath, password); err != nil {
		log.Println("Import failed:", err)
		return
	}

	log.Println("Keys imported from", inPath)
}
예제 #3
0
파일: main.go 프로젝트: traherom/syncer
func monitorSync(c *cli.Context) {
	localDir := c.String("local")

	// Command check
	if localDir == "" {
		log.Println("Local directory must be set to monitor")
		return
	}

	log.Println("Loading sync")
	sync, err := core.LoadSync(localDir)
	if err != nil {
		fmt.Printf("Failed to load sync: %v\n", err)
		return
	}

	// Change processor
	var wg syncPkg.WaitGroup
	die := make(chan bool)
	changes := make(chan *core.Change)
	completed := make(chan *core.Change)
	errors := make(chan error)

	wg.Add(1)
	go func() {
		core.ChangeQueueManager(changes, completed, errors, die)
		wg.Done()
	}()

	// Start monitoring and wait for enter
	wg.Add(1)
	go func() {
		sync.Monitor(changes, errors, die)
		wg.Done()
	}()

	// If all our children die, end the main program
	end := make(chan bool)
	go func() {
		wg.Wait()
		close(end)
		log.Println("All children have died, exiting")
	}()

	log.Println("Monitoring started")
	/*go func() {
		fmt.Scanln()
		close(end)
	}()*/

	// UI interaction
mainLoop:
	for {
		select {
		case change := <-completed:
			log.Println("Completed", change)
		case err := <-errors:
			log.Println("Error:", err)
		case <-end:
			break mainLoop
		}
	}

	// TODO timeout on waiting?
	log.Println("Requesting that handlers close")
	close(die)
	wg.Wait()
	log.Println("Syncer ended cleanly")
}