// checkLicenseAgreement returns nil if it's ok to proceed with installing the // package, as deduced from the license agreement (which might involve asking // the user), or an error that explains the reason why installation should not // proceed. func checkLicenseAgreement(s *snap.Info, snapf snap.File, cur *snap.Info, ag agreer) error { if s.LicenseAgreement != "explicit" { return nil } if ag == nil { return ErrLicenseNotAccepted } license, err := snapf.MetaMember("license.txt") if err != nil || len(license) == 0 { return ErrLicenseNotProvided } // don't ask for the license if // * the previous version also asked for license confirmation, and // * the license version is the same if cur != nil && (cur.LicenseAgreement == "explicit") && cur.LicenseVersion == s.LicenseVersion { return nil } msg := fmt.Sprintf("%s requires that you accept the following license before continuing", s.Name()) if !ag.Agreed(msg, string(license)) { return ErrLicenseNotAccepted } return nil }
// checkLicenseAgreement returns nil if it's ok to proceed with installing the // package, as deduced from the license agreement (which might involve asking // the user), or an error that explains the reason why installation should not // proceed. func (m *packageYaml) checkLicenseAgreement(ag agreer, d snap.File, currentActiveDir string) error { if !m.ExplicitLicenseAgreement { return nil } if ag == nil { return ErrLicenseNotAccepted } license, err := d.MetaMember("license.txt") if err != nil || len(license) == 0 { return ErrLicenseNotProvided } oldM, err := parsePackageYamlFile(filepath.Join(currentActiveDir, "meta", "package.yaml")) if err != nil && !os.IsNotExist(err) { return err } // don't ask for the license if // * the previous version also asked for license confirmation, and // * the license version is the same if err == nil && oldM.ExplicitLicenseAgreement && oldM.LicenseVersion == m.LicenseVersion { return nil } msg := fmt.Sprintf("%s requires that you accept the following license before continuing", m.Name) if !ag.Agreed(msg, string(license)) { return ErrLicenseNotAccepted } return nil }
// extractKernelAssets extracts kernel/initrd/dtb data from the given // Snap to a versionized bootloader directory so that the bootloader // can use it. func extractKernelAssets(s *snap.Info, snapf snap.File, flags InstallFlags, inter progress.Meter) error { if s.Type != snap.TypeKernel { return fmt.Errorf("can not extract kernel assets from snap type %q", s.Type) } bootloader, err := findBootloader() if err != nil { return fmt.Errorf("can not extract kernel assets: %s", err) } // check if we are on a "grub" system. if so, no need to unpack // the kernel if oem, err := getGadget(); err == nil { if oem.Legacy.Gadget.Hardware.Bootloader == "grub" { return nil } } // now do the kernel specific bits blobName := filepath.Base(s.MountFile()) dstDir := filepath.Join(bootloader.Dir(), blobName) if err := os.MkdirAll(dstDir, 0755); err != nil { return err } dir, err := os.Open(dstDir) if err != nil { return err } defer dir.Close() for _, src := range []string{s.Legacy.Kernel, s.Legacy.Initrd} { if src == "" { continue } if err := snapf.Unpack(src, dstDir); err != nil { return err } src = filepath.Join(dstDir, src) dst := filepath.Join(dstDir, dropVersionSuffix(src)) if err := os.Rename(src, dst); err != nil { return err } if err := dir.Sync(); err != nil { return err } } if s.Legacy.Dtbs != "" { src := filepath.Join(s.Legacy.Dtbs, "*") dst := dstDir if err := snapf.Unpack(src, dst); err != nil { return err } } return dir.Sync() }