Esempio n. 1
0
/*
Check to see if a package is installed on the operating system
*/
func (pkg *Package) GetPackageStatus(name string) (string, string, error) {
	distro, err := helpers.GetDistro()
	if err != nil {
		return "", "", err
	}

	switch distro.Family {
	case "debian":
		status, version, err := pkg.GetDpkgPackage(name)
		if err != nil {
			return "", "", err
		}
		switch status {
		case "ii":
			return "installed", version, nil
		case "rc":
			return "removed", version, nil
		case "":
			return "purged", version, nil
		default:
			return "", "", fmt.Errorf("Package %s is in an unknown state: %s", name, status)
		}
	default:
		return "", "", fmt.Errorf("Unsupported operating system: %s", distro.Family)
	}
}
Esempio n. 2
0
/*
Check if the specified service name is running on the operating system.
*/
func (service *Service) serviceRunning(name string) (bool, error) {
	distro, err := helpers.GetDistro()
	if err != nil {
		return false, err
	}
	switch distro.InitSystem {
	case "systemd":
		return service.systemdUnitRunning(name)
	default:
		return false, fmt.Errorf("Unsupported init system %s", distro.InitSystem)
	}
}
Esempio n. 3
0
/*
Update the service state, may be "running" or "stopped"
*/
func (service *Service) changeServiceState(name string, running bool) error {
	distro, err := helpers.GetDistro()
	if err != nil {
		return err
	}
	switch distro.InitSystem {
	case "systemd":
		if running {
			return service.startSystemdUnit(name)
		} else {
			return service.stopSystemdUnit(name)
		}
	default:
		return fmt.Errorf("Unsupported init system %s", distro.InitSystem)
	}
}
Esempio n. 4
0
/*
Remove a package from the operating system
*/
func (pkg *Package) RemovePackage(name string) error {
	distro, err := helpers.GetDistro()
	if err != nil {
		return err
	}
	switch distro.Family {
	case "debian":
		err := pkg.removeAptPackage(name)
		if err != nil {
			return err
		}
	default:
		return fmt.Errorf("Unsupported operating system: %s", distro.Family)
	}
	return nil
}
Esempio n. 5
0
/*
Install a package on the operating system
*/
func (pkg *Package) InstallPackage(name, version string) error {
	distro, err := helpers.GetDistro()
	if err != nil {
		return err
	}
	switch distro.Family {
	case "debian":
		if version != "" {
			name = name + fmt.Sprintf("==%s", version)
		}
		err := pkg.installAptPackage(name)
		if err != nil {
			return err
		}
	default:
		return fmt.Errorf("Unsupported operating system: %s", distro.Family)
	}
	return nil
}