Exemplo n.º 1
0
func doInstall(name string, flags InstallFlags, meter progress.Meter) (snapName string, err error) {
	defer func() {
		if err != nil {
			err = &ErrInstallFailed{Snap: name, OrigErr: err}
		}
	}()

	// consume local parts
	if fi, err := os.Stat(name); err == nil && fi.Mode().IsRegular() {
		// we allow unauthenticated package when in developer
		// mode
		//
		// FIXME: this is terrible, we really need a single
		//        bootloader dir like /boot or /boot/loader
		//        instead of having to query the partition code
		if provisioning.InDeveloperMode(partition.BootloaderDir()) {
			flags |= AllowUnauthenticated
		}

		return installClick(name, flags, meter, SideloadedOrigin)
	}

	// check repos next
	mStore := NewMetaStoreRepository()
	installed, err := NewMetaLocalRepository().Installed()
	if err != nil {
		return "", err
	}

	origin := ""
	idx := strings.IndexRune(name, '.')
	if idx > -1 {
		origin = name[idx+1:]
		name = name[:idx]
	}

	found, err := mStore.Details(name, origin)
	if err != nil {
		return "", err
	}

	for _, part := range found {
		cur := FindSnapsByNameAndVersion(QualifiedName(part), part.Version(), installed)
		if len(cur) != 0 {
			return "", ErrAlreadyInstalled
		}
		if PackageNameActive(part.Name()) {
			return "", ErrPackageNameAlreadyInstalled
		}

		// TODO block oem snaps here once the store supports package types

		return part.Install(meter, flags)
	}

	return "", ErrPackageNotFound
}
Exemplo n.º 2
0
func doInstall(name, channel string, flags InstallFlags, meter progress.Meter) (snapName string, err error) {
	defer func() {
		if err != nil {
			err = &ErrInstallFailed{Snap: name, OrigErr: err}
		}
	}()

	// consume local snaps
	if fi, err := os.Stat(name); err == nil && fi.Mode().IsRegular() {
		// we allow unauthenticated package when in developer
		// mode
		if provisioning.InDeveloperMode() {
			flags |= AllowUnauthenticated
		}

		snap, err := (&Overlord{}).Install(name, flags, meter)
		if err != nil {
			return "", err
		}

		return snap.Name(), nil
	}

	// check repos next
	mStore := NewConfiguredUbuntuStoreSnapRepository()
	installed, err := (&Overlord{}).Installed()
	if err != nil {
		return "", err
	}

	snap, err := mStore.Snap(name, channel, nil)
	if err != nil {
		return "", err
	}

	cur := FindSnapsByNameAndVersion(snap.Name(), snap.Version, installed)
	if len(cur) != 0 {
		return "", ErrAlreadyInstalled
	}
	if PackageNameActive(snap.Name()) {
		return "", ErrPackageNameAlreadyInstalled
	}

	return installRemote(mStore, snap, flags, meter)
}
Exemplo n.º 3
0
func doInstall(name string, flags InstallFlags, meter progress.Meter) (snapName string, err error) {
	defer func() {
		if err != nil {
			err = &ErrInstallFailed{Snap: name, OrigErr: err}
		}
	}()

	// consume local parts
	if fi, err := os.Stat(name); err == nil && fi.Mode().IsRegular() {
		// we allow unauthenticated package when in developer
		// mode
		if provisioning.InDeveloperMode() {
			flags |= AllowUnauthenticated
		}

		return installClick(name, flags, meter, SideloadedOrigin)
	}

	// check repos next
	mStore := NewUbuntuStoreSnapRepository()
	installed, err := NewLocalSnapRepository().Installed()
	if err != nil {
		return "", err
	}

	part, err := mStore.Snap(name)
	if err != nil {
		return "", err
	}

	cur := FindSnapsByNameAndVersion(QualifiedName(part), part.Version(), installed)
	if len(cur) != 0 {
		return "", ErrAlreadyInstalled
	}
	if PackageNameActive(part.Name()) {
		return "", ErrPackageNameAlreadyInstalled
	}

	return installRemote(mStore, part, flags, meter)
}