func (ip *inproc) uninstall(jirix *jiri.X, cl *uninstallFlagValues, root jiri.RelPath) error { profile := ip.db.LookupProfile(ip.installer, ip.name) if profile == nil { fmt.Fprintf(jirix.Stdout(), "%s is not installed\n", ip.qname) return nil } mgr := profilesmanager.LookupManager(ip.qname) var targets []*profiles.Target if cl.allTargets { targets = profile.Targets() } else { def, err := targetAtDefaultVersion(mgr, cl.target) if err != nil { return err } targets = []*profiles.Target{&def} } for _, target := range targets { if err := mgr.Uninstall(jirix, ip.db, root, *target); err != nil { logResult(jirix, "Uninstall", mgr, *target, err) return err } logResult(jirix, "Uninstall", mgr, *target, nil) } return nil }
func (ip *inproc) packageCmds(jirix *jiri.X, cl *packagesFlagValues, root jiri.RelPath) ([][]string, error) { mgr := profilesmanager.LookupManager(ip.qname) if mgr == nil { return nil, fmt.Errorf("profile %v is not available via this installer %q", ip.qname, ip.installer) } def, err := targetAtDefaultVersion(mgr, cl.target) if err != nil { return nil, err } needed, err := mgr.OSPackages(jirix, ip.db, root, def) if err != nil { return nil, fmt.Errorf("Failed to obtain packages for %v %v: %v", ip.name, cl.target, err) } if !cl.allPackages { if missing, err := profilesutil.MissingOSPackages(jirix, needed); err != nil { return nil, fmt.Errorf("Failed to obtain missing packages for %v %v: %v", ip.name, cl.target, err) } else { needed = missing } } // Dedup & sort. deduped := []string{} m := map[string]bool{} for _, n := range needed { if !m[n] { m[n] = true deduped = append(deduped, n) } } sort.Strings(deduped) return profilesutil.OSPackageInstallCommands(jirix, deduped), nil }
func (ip *inproc) update(jirix *jiri.X, cl *updateFlagValues, root jiri.RelPath) error { profile := ip.db.LookupProfile(ip.installer, ip.name) if profile == nil { // silently ignore uninstalled profile. return nil } mgr := profilesmanager.LookupManager(ip.qname) vi := mgr.VersionInfo() for _, target := range profile.Targets() { if vi.IsTargetOlderThanDefault(target.Version()) { // Check if default target is already installed. defTarget := *target defTarget.SetVersion(vi.Default()) if profiles.FindTarget(profile.Targets(), &defTarget) != nil { // Default target is already installed. Skip. continue } if cl.verbose { fmt.Fprintf(jirix.Stdout(), "Updating %s %s from %q to %s\n", ip.qname, target, target.Version(), vi) } err := mgr.Install(jirix, ip.db, root, defTarget) logResult(jirix, "Update", mgr, defTarget, err) if err != nil { return err } } else { if cl.verbose { fmt.Fprintf(jirix.Stdout(), "%s %s at %q is up to date(%s)\n", ip.qname, target, target.Version(), vi) } } } return nil }
func availableImpl(jirix *jiri.X, cl *availableFlagValues, _ []string) error { if profileInstaller == "" { subcommands := findProfileSubcommands(jirix) if cl.verbose { fmt.Fprintf(jirix.Stdout(), "Available Subcommands: %s\n", strings.Join(subcommands, ", ")) } s := jirix.NewSeq() args := []string{"available"} args = append(args, cl.args()...) out := bytes.Buffer{} for _, sc := range subcommands { if err := s.Capture(&out, nil).Last(sc, args...); err != nil { return err } } if s := strings.TrimSpace(out.String()); s != "" { fmt.Fprintln(jirix.Stdout(), s) } } mgrs := profilesmanager.Managers() if len(mgrs) == 0 { return nil } if cl.verbose { scname := "" if profileInstaller != "" { scname = profileInstaller + ": " } fmt.Fprintf(jirix.Stdout(), "%sAvailable Profiles:\n", scname) for _, name := range mgrs { mgr := profilesmanager.LookupManager(name) vi := mgr.VersionInfo() fmt.Fprintf(jirix.Stdout(), "%s: versions: %s\n", name, vi) } } else { if cl.describe { for _, name := range mgrs { mgr := profilesmanager.LookupManager(name) fmt.Fprintf(jirix.Stdout(), "%s: %s\n", name, strings.Replace(strings.TrimSpace(mgr.Info()), "\n", " ", -1)) } } else { fmt.Fprintf(jirix.Stdout(), "%s\n", strings.Join(mgrs, ", ")) } } return nil }
func initInstallCommand(flags *flag.FlagSet, installer, defaultDBPath, defaultProfilesPath string) { initCommon(flags, &installFlags.commonFlagValues, installer, defaultDBPath, defaultProfilesPath) profiles.RegisterTargetAndEnvFlags(flags, &installFlags.target) flags.BoolVar(&installFlags.force, "force", false, "force install the profile even if it is already installed") for _, name := range profilesmanager.Managers() { profilesmanager.LookupManager(name).AddFlags(flags, profiles.Install) } }
func initUninstallCommand(flags *flag.FlagSet, installer, defaultDBPath, defaultProfilesPath string) { initCommon(flags, &uninstallFlags.commonFlagValues, installer, defaultDBPath, defaultProfilesPath) profiles.RegisterTargetFlag(flags, &uninstallFlags.target) flags.BoolVar(&uninstallFlags.allTargets, "all-targets", false, "apply to all targets for the specified profile(s)") flags.BoolVar(&uninstallFlags.verbose, "v", false, "print more detailed information") for _, name := range profilesmanager.Managers() { profilesmanager.LookupManager(name).AddFlags(flags, profiles.Uninstall) } }
func initPackagesCommand(flags *flag.FlagSet, installer, defaultDBPath, defaultProfilesPath string) { initCommon(flags, &packagesFlags.commonFlagValues, installer, defaultDBPath, defaultProfilesPath) profiles.RegisterTargetAndEnvFlags(flags, &packagesFlags.target) flags.BoolVar(&packagesFlags.allPackages, "all", false, "print commands to install all required OS packages, not just those that are missing") flags.BoolVar(&packagesFlags.installPackages, "install", false, "install the requested packages. This may need to be run as root.") for _, name := range profilesmanager.Managers() { profilesmanager.LookupManager(name).AddFlags(flags, profiles.Install) } }
func (ip *inproc) install(jirix *jiri.X, cl *installFlagValues, root jiri.RelPath) error { mgr := profilesmanager.LookupManager(ip.qname) if mgr == nil { return fmt.Errorf("profile %v is not available via this installer %q", ip.qname, ip.installer) } def, err := targetAtDefaultVersion(mgr, cl.target) if err != nil { return err } err = mgr.Install(jirix, ip.db, root, def) logResult(jirix, "Install", mgr, def, err) return err }
func cleanupGC(jirix *jiri.X, db *profiles.DB, root jiri.RelPath, verbose bool, name string) error { mgr := profilesmanager.LookupManager(name) if mgr == nil { fmt.Fprintf(jirix.Stderr(), "%s is not linked into this binary\n", name) return nil } vi := mgr.VersionInfo() installer, profileName := profiles.SplitProfileName(name) profile := db.LookupProfile(installer, profileName) for _, target := range profile.Targets() { if vi.IsTargetOlderThanDefault(target.Version()) { err := mgr.Uninstall(jirix, db, root, *target) logResult(jirix, "Cleanup: -gc", mgr, *target, err) if err != nil { return err } } } return nil }
func ExampleManager() { pdb := profiles.NewDB() myInstaller := "myProject" myProfile := "myNewProfile" profileName := profiles.QualifiedProfileName(myInstaller, myProfile) var target profiles.Target init := func() { mgr := newProfileMgr(myInstaller, myProfile) profilesmanager.Register(mgr) flags := flag.NewFlagSet("example", flag.ContinueOnError) profiles.RegisterTargetAndEnvFlags(flags, &target) flags.Parse([]string{"--target=arm-linux@1", "--env=A=B,C=D", "--env=E=F"}) } init() profileRoot := jiri.NewRelPath("profiles") mgr := profilesmanager.LookupManager(profileName) if mgr == nil { panic("manager not found for: " + profileName) } jirix := &jiri.X{Context: tool.NewDefaultContext()} // Install myNewProfile for target. if err := mgr.Install(jirix, pdb, profileRoot, target); err != nil { panic("failed to find manager for: " + profileName) } fmt.Println(mgr.String()) filename := tmpFile() defer os.RemoveAll(filepath.Dir(filename)) if err := pdb.Write(jirix, "test", filename); err != nil { panic(err) } // Start with a new profile data base. pdb = profiles.NewDB() // Read the profile database. pdb.Read(jirix, filename) mgr = profilesmanager.LookupManager(profileName) if mgr == nil { panic("manager not found for: " + profileName) } fmt.Println(mgr.String()) mgr.Uninstall(jirix, pdb, profileRoot, target) fmt.Println(mgr.String()) fmt.Println(mgr.VersionInfo().Supported()) fmt.Println(mgr.VersionInfo().Default()) // Output: // Profile: myNewProfile: installed // [arm-linux@1] // // Profile: myNewProfile: installed // [arm-linux@1] // // Profile: myNewProfile: not installed // // [4 3 2] // 3 }