Exemplo n.º 1
0
func (c *CheckCommand) Run() error {

	// check the package file
	var err error
	c.pkg, err = common.LoadPackage("")
	if err != nil {
		c.Error(err)
		return err
	}

	c.pkg.Validate()

	// check the LICENSE file
	_, err = os.Stat(core.LicenseFile)
	if err != nil {
		c.Error(err)
		return err
	}

	// check the .pri file
	_, err = os.Stat(c.pkg.PriFile())
	if err != nil {
		c.Error(err)
		return err
	}

	// check the .qrc file
	_, err = os.Stat(c.pkg.QrcFile())
	if err != nil {
		c.Warning(err.Error())
	}

	var prefix string
	prefix, err = c.qrc()
	if err != nil {
		c.Warning(err.Error())
	} else if prefix != c.pkg.QrcPrefix() && prefix[1:] != c.pkg.QrcPrefix() {
		c.Error(fmt.Errorf("the QRC prefix (%s) does not equal (%s)", prefix, c.pkg.QrcPrefix()))
	}

	// check the qmldir file
	_, err = os.Stat("qmldir")
	if err != nil {
		c.Warning(err.Error())
	} else {
		var module string
		module, err = c.qmldir()
		if err != nil {
			c.Error(err)
			return err
		}
		if module != c.pkg.Name {
			c.Error(fmt.Errorf("the qmldir module (%s) does not equal (%s)", module, c.pkg.Name))
		}
	}

	fmt.Printf("OK!\n")

	return nil
}
Exemplo n.º 2
0
Arquivo: git.go Projeto: Cutehacks/qpm
func (g *Git) Install(repository *msg.Package_Repository, version *msg.Package_Version, destination string) (*common.PackageWrapper, error) {

	err := os.RemoveAll(destination)
	if err != nil {
		return nil, err
	}

	err = g.cloneRepository(repository.Url, destination)
	if err != nil {
		return nil, err
	}

	pwd, err := os.Getwd()
	if err != nil {
		return nil, err
	}

	err = os.Chdir(destination)
	if err != nil {
		return nil, err
	}

	err = g.checkoutRevision(version.Revision)
	if err != nil {
		return nil, err
	}

	err = os.Chdir(pwd)
	if err != nil {
		return nil, err
	}

	return common.LoadPackage(destination)
}
Exemplo n.º 3
0
func (p *PublishCommand) Run() error {

	token, err := LoginPrompt(context.Background(), p.Ctx.Client)

	if err != nil {
		fmt.Printf("ERROR: %v\n", err)
		return err
	}

	fmt.Println("Running check")
	if err := NewCheckCommand(p.Ctx).Run(); err != nil {
		p.Fatal(err.Error())
	}

	wrapper, err := common.LoadPackage("")

	if err != nil {
		p.Fatal("Cannot read " + core.PackageFile + ": " + err.Error())
	}

	publisher, err := vcs.CreatePublisher(wrapper.Repository)
	if err != nil {
		p.Fatal("Cannot find VCS: " + err.Error())
	}

	wrapper.Version.Revision, err = publisher.LastCommitRevision()

	if err != nil {
		p.Fatal("Cannot get the last commit SHA1: " + err.Error())
	}

	if err := publisher.ValidateCommit(wrapper.Version.Revision); err != nil {
		p.Fatal(err.Error())
	}

	fmt.Println("Publishing")
	_, err = p.Ctx.Client.Publish(context.Background(), &msg.PublishRequest{
		Token:              token,
		PackageDescription: wrapper.Package,
	})

	if err != nil {
		p.Fatal("ERROR:" + err.Error())
	}

	tag := <-Prompt("Tag release:", "Y/n")
	if len(tag) == 0 || strings.ToLower(string(tag[0])) == "y" {
		publisher.CreateTag("qpm/" + wrapper.Version.Label)
	}

	fmt.Println("SUCCESS!")
	signature := strings.Join([]string{wrapper.Name, wrapper.Version.Label}, "@")
	fmt.Println("Publised package: " + signature)
	fmt.Println("Revision: " + wrapper.Version.Revision)

	return nil
}
Exemplo n.º 4
0
func (v *VerifyCommand) Run() error {

	var path string
	if v.fs.NArg() > 0 {
		packageName := v.fs.Arg(0)
		path = filepath.Join(core.Vendor, strings.Replace(packageName, ".", string(filepath.Separator), -1))
	} else {
		path = "."
	}

	var err error
	v.pkg, err = common.LoadPackage("")
	if err != nil {
		v.Error(err)
		return err
	}

	// Hash the package

	hash, err := v.hashTree(path)
	if err != nil {
		v.Error(err)
		return err
	}
	fmt.Println("Package SHA-256: " + hash)

	// Verify the signature

	if v.pkg.Version.Fingerprint == "" {
		err = fmt.Errorf("no fingerprint set in " + core.PackageFile)
		v.Error(err)
		return err
	}

	entity, err := entityFromLocal("pubring.gpg", v.pkg.Version.Fingerprint)
	if err != nil {
		v.Error(err)
		return err
	}

	sig, err := ioutil.ReadFile(core.SignatureFile)
	if err != nil {
		v.Error(err)
		return err
	}

	err = Verify(hash, sig, entity.PrimaryKey)
	if err != nil {
		v.Error(err)
		return err
	}

	fmt.Println("Signature verified")

	return nil
}
Exemplo n.º 5
0
func (m *Mercurial) Install(repository *msg.Package_Repository, version *msg.Package_Version, destination string) (*common.PackageWrapper, error) {

	err := os.RemoveAll(destination)
	if err != nil {
		return nil, err
	}

	err = m.cloneRepository(repository.Url, version.Revision, destination)
	if err != nil {
		return nil, err
	}

	return common.LoadPackage(destination)
}
Exemplo n.º 6
0
Arquivo: github.go Projeto: benlau/qpm
func extract(fileName string, destination string) (*common.PackageWrapper, error) {

	file, err := os.Open(fileName)

	if err != nil {
		return nil, err
	}

	defer file.Close()

	var fileReader io.ReadCloser = file

	// add a filter to handle gzipped file
	if strings.HasSuffix(fileName, ".gz") {
		if fileReader, err = gzip.NewReader(file); err != nil {
			return nil, err
		}
		defer fileReader.Close()
	}

	tarBallReader := tar.NewReader(fileReader)
	var topDir string

	for {
		header, err := tarBallReader.Next()
		if err != nil {
			if err == io.EOF {
				break
			}
			return nil, err
		}

		filename := destination + string(filepath.Separator) + header.Name

		switch header.Typeflag {
		case tar.TypeDir:
			tokens := strings.Split(header.Name, string(filepath.Separator))
			topDir = tokens[0]
			err = os.MkdirAll(filename, os.FileMode(header.Mode)) // or use 0755
			if err != nil {
				return nil, err
			}

		case tar.TypeReg:
			writer, err := os.Create(filename)
			if err != nil {
				return nil, err
			}
			io.Copy(writer, tarBallReader)
			err = os.Chmod(filename, os.FileMode(header.Mode))
			if err != nil {
				return nil, err
			}
			writer.Close()

		case tar.TypeXGlobalHeader:
		// Ignore this

		default:
			//i.Info("Unable to extract type : %c in file %s\n", header.Typeflag, filename)
		}
	}

	if topDir != "" {

		src := filepath.Join(destination, topDir)

		pkg, err := common.LoadPackage(src)
		if err != nil {
			return pkg, err
		}

		path := filepath.Join(destination, pkg.QrcPrefix())

		if err := os.MkdirAll(path, 0755); err != nil {
			return pkg, err
		}

		os.RemoveAll(path)

		if err = os.Rename(src, path); err != nil {
			return pkg, err
		}

		return pkg, err
	}

	return nil, nil
}
Exemplo n.º 7
0
func (i *InstallCommand) Run() error {

	packageName := i.fs.Arg(0)

	var err error
	i.pkg, err = common.LoadPackage("")
	if err != nil {
		// A missing package file is only an error if packageName is empty
		if os.IsNotExist(err) {
			if packageName == "" {
				err = fmt.Errorf("No %s file found", core.PackageFile)
				i.Error(err)
				return err
			} else {
				// Create a new package
				file, err := filepath.Abs(core.PackageFile)
				if err != nil {
					i.Error(err)
					return err
				}
				i.pkg = common.NewPackageWrapper(file)
			}
		} else {
			i.Error(err)
			return err
		}
	}

	var packageNames []string
	if packageName == "" {
		packageNames = i.pkg.Dependencies
	} else {
		packageNames = []string{packageName}
	}

	// Get list of dependencies from the server
	response, err := i.Ctx.Client.GetDependencies(context.Background(), &msg.DependencyRequest{
		packageNames,
		i.pkg.License,
	})
	if err != nil {
		i.Error(err)
		return err
	}

	if len(response.Dependencies) == 0 {
		i.Info("No package(s) found")
		return nil
	}

	// Show info, warnings, errors and address prompts before continuing
	for _, msg := range response.Messages {
		fmt.Printf("%s: %s\n", msg.Type.String(), msg.Title)

		if msg.Body != "" {
			fmt.Println(msg.Body)
		}

		if msg.Prompt {
			continueAnyway := <-Prompt("Continue anyway?", "Y/n")
			if len(continueAnyway) == 0 || strings.ToLower(string(continueAnyway[0])) == "y" {
				continue
			} else {
				return fmt.Errorf("Installation aborted.")
			}
		}
	}

	// create the vendor directory if needed
	if _, err = os.Stat(i.vendorDir); err != nil {
		err = os.Mkdir(i.vendorDir, 0755)
	}

	// Download and extract the packages
	packages := []*common.PackageWrapper{}
	for _, d := range response.Dependencies {
		p, err := i.install(d)
		if err != nil {
			return err
		}
		packages = append(packages, p)
	}

	// Save the dependencies in the package file
	err = i.save(packages)
	// FIXME: should we continue installing ?
	if err != nil {
		return err
	}

	err = i.postInstall()
	// FIXME: should we continue installing ?
	if err != nil {
		return err
	}

	return nil
}
Exemplo n.º 8
0
func (u *UninstallCommand) Run() error {

	packageName := u.fs.Arg(0)

	if packageName == "" {
		err := fmt.Errorf("Must supply a package to uninstall")
		u.Error(err)
		return err
	}

	dependencyMap, err := common.LoadPackages(u.vendorDir)
	if err != nil {
		u.Error(err)
		return err
	}

	toRemove, exists := dependencyMap[packageName]
	if !exists {
		err := fmt.Errorf("Package %s was not found", packageName)
		u.Error(err)
		return err
	}

	// Does the current directory contain a package file that needs updating?
	pkg, err := common.LoadPackage("")
	if err != nil && !os.IsNotExist(err) {
		u.Error(err)
		return err
	} else if err == nil {
		pkg.RemoveDependency(toRemove)
		if err := pkg.Save(); err != nil {
			u.Error(err)
			return err
		}
	}

	fmt.Println("Uninstalling", toRemove.Name)

	// Final step is to delete the dependency's directory. This should
	// be done last since after this step, the info about the package is
	// gone.

	if err := os.RemoveAll(toRemove.RootDir()); err != nil {
		u.Error(err)
		return err
	}

	// Cleanup empty leaf directories in parent dirs
	dir := path.Clean(toRemove.RootDir() + "/..")
	for dir != u.vendorDir {
		if _, empty := u.isEmpty(dir); empty {
			os.Remove(dir)
		}
		dir = path.Clean(dir + "/..")
	}

	// Regenerate vendor.pri
	if err := GenerateVendorPri(u.vendorDir, pkg); err != nil {
		u.Error(err)
		return err
	}

	return nil
}
Exemplo n.º 9
0
Arquivo: sign.go Projeto: benlau/qpm
func (s *SignCommand) Run() error {

	var err error
	s.pkg, err = common.LoadPackage("")
	if err != nil {
		s.Error(err)
		return err
	}

	// Hash the repo

	hash, err := hashRepo()
	if err != nil {
		s.Error(err)
		return err
	}
	fmt.Println("Package SHA-256: " + hash)

	// Sign the SHA

	fmt.Println("Loading the GnuPG private key")

	if s.pkg.Version.Fingerprint == "" {
		err = fmt.Errorf("no fingerprint set in " + core.PackageFile)
		s.Error(err)
		return err
	}

	signer, err := entityFromLocal("secring.gpg", s.pkg.Version.Fingerprint)
	if err != nil {
		s.Error(err)
		return err
	}

	fmt.Println("Creating the signature")
	sig, err := Sign(hash, signer)
	if err != nil {
		s.Error(err)
		return err
	}

	// Write the signature file

	fmt.Println("Creating " + core.SignatureFile)
	file, err := os.Create(core.SignatureFile)
	if err != nil {
		s.Error(err)
		return err
	}
	defer file.Close()

	_, err = file.Write(sig)
	if err != nil {
		s.Error(err)
		return err
	}

	// Verify the signature

	fmt.Println("Verifying the signature")
	entity, err := entityFromLocal("pubring.gpg", s.pkg.Version.Fingerprint)
	if err != nil {
		s.Error(err)
		return err
	}

	err = Verify(hash, sig, entity.PrimaryKey)
	if err != nil {
		s.Error(err)
		return err
	}

	fmt.Println("Done")

	return nil
}