syspkg

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 6 Imported by: 2

README

SysPkg

Go Reference Go Report Card [License]

SysPkg is a unified CLI tool and Golang library for managing system packages across different package managers (apt, snap, flatpak, yum, dnf, and more). It simplifies the process of working with various package managers by providing a consistent interface and API through an abstraction layer.

Features

  • A unified package management interface for various package managers
  • Supports popular package managers such as APT, Snap, Flatpak, and more
  • Easy-to-use API for package installation, removal, search, listing, and system upgrades
  • Expandable architecture to support more package managers in the future

API Documentation

See the Go Reference for the full API documentation.

Getting Started

Prerequisites
  • Go 1.16 or later (1.20+ preferred)
Installation

Install the library using the go get command:

go get github.com/bluet/syspkg

Usage

Here's an example demonstrating how to use SysPkg as a Go library:

package main

import (
 "fmt"
 "github.com/bluet/syspkg"
)

func main() {
 // Initialize SysPkg with all available package managers on current system
 includeOptions := syspkg.IncludeOptions{
  AllAvailable: true,
 }
 syspkgManager, err := syspkg.New(includeOptions)
 if err != nil {
  fmt.Printf("Error initializing SysPkg: %v\n", err)
  return
 }

 // List installed packages using APT
 aptManager := syspkgManager.GetPackageManager("apt")
 installedPackages, err := aptManager.ListInstalled(nil)
 if err != nil {
  fmt.Printf("Error listing installed packages: %v\n", err)
  return
 }

 fmt.Println("Installed packages:")
 for _, pkg := range installedPackages {
  fmt.Printf("- %s (%s)\n", pkg.Name, pkg.Version)
 }
}

For more examples and real use cases, see the cmd/syspkg-cli/ directory.

Supported Package Managers

Package Manager Install Remove Search Upgrade List Installed List Upgradable Get Package Info
APT
SNAP
Flatpak
Your favorite package manager here! 🚀 🚀 🚀 🚀 🚀 🚀 🚀

Please open an issue (or PR ❤️) if you'd like to see support for any unlisted specific package manager.

TODO
  • Add support for more package managers
  • Improve error handling
  • Enhance return values and status codes

Contributing

We welcome contributions to Go-SysPkg! Please read our CONTRIBUTING.md for more information on how to contribute.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Overview

Package syspkg provides a unified interface for interacting with multiple package management systems. It allows you to query, install, and remove packages, and supports package managers like Apt, Snap, and Flatpak.

To get started, create a new SysPkg instance by calling the New() function with the desired IncludeOptions. After obtaining a SysPkg instance, you can use the FindPackageManagers() function to find available package managers on the system, and GetPackageManager() to get a specific package manager.

Example:

includeOptions := syspkg.IncludeOptions{
    AllAvailable: true,
}
sysPkg, err := syspkg.New(includeOptions)
if err != nil {
    log.Fatal(err)
}
aptManager := sysPkg.GetPackageManager("apt")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IncludeOptions

type IncludeOptions struct {
	AllAvailable bool
	Apk          bool
	Apt          bool
	Dnf          bool
	Flatpak      bool
	Snap         bool
	Zypper       bool
}

IncludeOptions specifies which package managers to include when creating a SysPkg instance.

type PackageInfo

type PackageInfo = manager.PackageInfo

PackageInfo represents a package's information.

type PackageManager

type PackageManager interface {
	// IsAvailable checks if the package manager is available on the current system.
	IsAvailable() bool

	// GetPackageManager returns the name of the package manager.
	GetPackageManager() string

	// Install installs the specified packages using the package manager.
	Install(pkgs []string, opts *manager.Options) ([]manager.PackageInfo, error)

	// Delete removes the specified packages using the package manager.
	Delete(pkgs []string, opts *manager.Options) ([]manager.PackageInfo, error)

	// Find searches for packages using the specified keywords.
	Find(keywords []string, opts *manager.Options) ([]manager.PackageInfo, error)

	// ListInstalled lists all installed packages.
	ListInstalled(opts *manager.Options) ([]manager.PackageInfo, error)

	// ListUpgradable lists all upgradable packages.
	ListUpgradable(opts *manager.Options) ([]manager.PackageInfo, error)

	// Upgrade upgrades all packages or only the specified ones.
	UpgradeAll(opts *manager.Options) ([]manager.PackageInfo, error)

	// Refresh refreshes the package index.
	Refresh(opts *manager.Options) error

	// GetPackageInfo returns information about the specified package.
	GetPackageInfo(pkg string, opts *manager.Options) (manager.PackageInfo, error)
}

PackageManager is the interface that defines the methods for interacting with various package managers.

type SysPkg

type SysPkg interface {
	// FindPackageManagers returns a map of available package managers based on the specified IncludeOptions.
	// If the AllAvailable option is set to true, all available package managers will be returned.
	// Otherwise, only the specified package managers will be returned.
	// If no suitable package managers are found, an error is returned.
	FindPackageManagers(include IncludeOptions) (map[string]PackageManager, error)

	// RefreshPackageManagers refreshes the internal package manager list based on the specified IncludeOptions, and returns the new list.
	// If the AllAvailable option is set to true, all available package managers will be included.
	// Otherwise, only the specified package managers will be included.
	// If no suitable package managers are found, an error is returned.
	RefreshPackageManagers(include IncludeOptions) (map[string]PackageManager, error)

	// GetPackageManager returns a PackageManager instance based on the specified name, from the list of available package managers specified in the IncludeOptions.
	// If the name is empty, the first available package manager will be returned.
	// If no suitable package manager is found, an error is returned.
	// Note: only package managers that are specified in the IncludeOptions when creating the SysPkg instance (with New() method) will be returned. If you want to use package managers that are not specified in the IncludeOptions, you should use the FindPackageManagers() method to get a list of all available package managers, or use RefreshPackageManagers() with the IncludeOptions parameter to refresh the package manager list.
	GetPackageManager(name string) PackageManager
}

SysPkg is the interface that defines the methods for interacting with the SysPkg library.

func New

func New(include IncludeOptions) (SysPkg, error)

New creates a new SysPkg instance with the specified IncludeOptions.

Directories

Path Synopsis
cmd
syspkg-cli command
Package main contains the syspkg CLI tool, a universal system package manager.
Package main contains the syspkg CLI tool, a universal system package manager.
Package manager provides utilities for managing the application.
Package manager provides utilities for managing the application.
apt
Package apt provides an implementation of the syspkg manager interface for the apt package manager.
Package apt provides an implementation of the syspkg manager interface for the apt package manager.
flatpak
Package flatpak provides an implementation of the syspkg manager interface for the Flatpak package manager.
Package flatpak provides an implementation of the syspkg manager interface for the Flatpak package manager.
snap
Package snap provides an implementation of the syspkg manager interface for the snap package manager.
Package snap provides an implementation of the syspkg manager interface for the snap package manager.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL