installer

package module
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: GPL-3.0 Imports: 28 Imported by: 0

README

Minecraft Server Installer License Build Status Downloads

If this project is useful, please give a star :)

Releases Page

Introduction

This is a minecraft server online installer

You can use this cli to easily install minecraft server.
We also support some types of servers and modpacks

Server Type Support
Vanilla true
Fabric true
Forge true
Quilt true
Spigot true
PaperMC TODO
ArcLight TODO
Modpack Type Support
Modrinth true
Curseforge plan/no

Warn: For spigot server, you must install suitable openjdk (not only jre) and git.
See https://www.spigotmc.org/wiki/buildtools/#prerequisites

Flags

Flags:
  -h, -help
        Show this help page
  -name string
        the executable name, without suffix such as '.sh' or '.jar' (default "minecraft")
  -output string
        the path need to be installed (default ".")
  -version string
        the version of the server need to be installed, default is the latest (default "latest")
Args:
  <server_type> string
        type of the server [fabric forge quilt spigot vanilla] (default "vanilla" )
  <modpack_file> filepath | URL
        the modpack's local path or an URL. If it's an URL, installer will download the modpack first

Examples

Install pure servers
# Install minecraft 1.7.10 vanilla server into minecraft.jar
minecraft_installer -name minecraft -version 1.7.10
# Install minecraft 1.19.2 forge server into current directory and the executable is minecraft_server.sh or minecraft_server.bat for windows
minecraft_installer -name minecraft_server -version 1.19.2 -server forge
# Hint: forge installer will make run scripts for the minecraft version that higher or equal than 1.17
#       for version that less than 1.17, you still need to use 'java -jar' to run the server

# Install minecraft 1.16.5 forge server into minecraft_server.jar
minecraft_installer -name minecraft_server -version 1.16.5 -server forge
# Install minecraft 1.19.2 fabric server into server/minecraft_server.jar
minecraft_installer -name minecraft_server -version 1.19.2 -server fabric -path server
Install modpacks
# Install the modpack from local to the current directory
minecraft_installer -name modpack_server modpack /path/to/modrinth-modpack.mrpack
# Hint: Only support modrinth modpack for now, curseforge is in progress
# Install the modpack from internet to the current directory
minecraft_installer -name modpack_server modpack 'https://cdn-raw.modrinth.com/data/sl6XzkCP/versions/i4agaPF2/Automation%20v3.3.mrpack'
# Hint: if you want to install modpack from the internet,
#       you must add the prefixs [https://, http://]
List server avaliable versions
minecraft_installer versions
minecraft_installer -version snapshot versions

TODO

  • PaperMC
  • Search modpacks from modrinth
  • Configurable proxy

Documentation

Index

Constants

View Source
const (
	MrpackEnvRequired    = "required"
	MrpackEnvOptional    = "optional"
	MrpackEnvUnsupported = "unsupported"
)
View Source
const SpigotBuildToolsURI = "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"

Variables

View Source
var DefaultFabricInstaller = &FabricInstaller{
	MetaUrl: "https://meta.fabricmc.net",
}
View Source
var DefaultForgeInstaller = &ForgeInstaller{
	MavenUrl: "https://maven.minecraftforge.net",
}
View Source
var DefaultHTTPClient = &HTTPClient{
	Client: http.Client{
		Timeout: time.Second * 10,
	},
	UserAgent: "github.com/kmcsr/server-installer/" + PkgVersion,
}
View Source
var DefaultQuiltInstaller = &QuiltInstaller{
	MavenUrl: "https://maven.quiltmc.org/repository/release",
}
View Source
var EmptyLinkArrayErr = errors.New("Link array is empty")
View Source
var Installers = make(map[string]Installer, 10)
View Source
var PkgVersion = "dev"
View Source
var TargetAlreadyExistErr = errors.New("Target file already exists, please clean the install directory and retry")
View Source
var VanillaIns = &VanillaInstaller{
	ManifestUrl: "https://launchermeta.mojang.com/mc/game/version_manifest.json",
}

Functions

func GetInstallerNames

func GetInstallerNames() (installers []string)

func SetLogger added in v1.2.0

func SetLogger(newLoger logger.Logger)

Types

type AssetIndex

type AssetIndex struct {
	DownloadInfo
	Id        string `json:"id"`
	TotalSize int64  `json:"totalSize"`
}

type AssetNotFoundErr

type AssetNotFoundErr struct {
	Version string
	Asset   string
}

func (*AssetNotFoundErr) Error

func (e *AssetNotFoundErr) Error() string

type ContentLengthNotMatchErr added in v1.2.0

type ContentLengthNotMatchErr struct {
	ContentLength int64
	Expect        int64
}

func (*ContentLengthNotMatchErr) Error added in v1.2.0

func (e *ContentLengthNotMatchErr) Error() string

type DlCallback added in v1.2.0

type DlCallback = func(n int64, size int64)

type DownloadInfo

type DownloadInfo struct {
	Sha1 string `json:"sha1"`
	Size int64  `json:"size"`
	Url  string `json:"url"`
}

type FabricInstaller

type FabricInstaller struct {
	MetaUrl string // Default is "https://meta.fabricmc.net"
}

func (*FabricInstaller) GetInstallers

func (r *FabricInstaller) GetInstallers() (res []FabricInstallerVersion, err error)

func (*FabricInstaller) Install

func (r *FabricInstaller) Install(path, name string, target string) (installed string, err error)

func (*FabricInstaller) InstallWithLoader added in v1.2.0

func (r *FabricInstaller) InstallWithLoader(path, name string, target string, loader string) (installed string, err error)

func (*FabricInstaller) ListVersions added in v1.2.3

func (r *FabricInstaller) ListVersions(snapshot bool) (versions []string, err error)

type FabricInstallerVersion

type FabricInstallerVersion struct {
	Url     string `json:"url"`
	Maven   string `json:"maven"`
	Version string `json:"version"`
	Stable  bool   `json:"stable"`
}

type ForgeInstaller

type ForgeInstaller struct {
	MavenUrl string // Default is "https://maven.minecraftforge.net"
}

func (*ForgeInstaller) GetInstallerVersions

func (r *ForgeInstaller) GetInstallerVersions() (data MavenMetadata, err error)

func (*ForgeInstaller) GetLatestInstaller

func (r *ForgeInstaller) GetLatestInstaller(target string) (version string, err error)

func (*ForgeInstaller) Install

func (r *ForgeInstaller) Install(path, name string, target string) (installed string, err error)

func (*ForgeInstaller) InstallWithLoader added in v1.2.0

func (r *ForgeInstaller) InstallWithLoader(path, name string, target string, loader string) (installed string, err error)

func (*ForgeInstaller) ListVersions added in v1.2.3

func (r *ForgeInstaller) ListVersions(snapshot bool) (versions []string, err error)

type HTTPClient added in v1.2.0

type HTTPClient struct {
	http.Client

	UserAgent string
}

func (*HTTPClient) Do added in v1.2.0

func (c *HTTPClient) Do(req *http.Request) (res *http.Response, err error)

func (*HTTPClient) Download added in v1.2.0

func (c *HTTPClient) Download(url string, path string, mode os.FileMode, hashes StringMap, size int64, cb DlCallback) (err error)

func (*HTTPClient) DownloadTmp added in v1.2.0

func (c *HTTPClient) DownloadTmp(url string, pattern string, mode os.FileMode, hashes StringMap, size int64, cb DlCallback) (path string, err error)

func (*HTTPClient) Get added in v1.2.0

func (c *HTTPClient) Get(url string) (res *http.Response, err error)

func (*HTTPClient) GetJson added in v1.2.0

func (c *HTTPClient) GetJson(url string, obj any) (err error)

func (*HTTPClient) GetXml added in v1.2.0

func (c *HTTPClient) GetXml(url string, obj any) (err error)

func (*HTTPClient) Head added in v1.2.0

func (c *HTTPClient) Head(url string) (res *http.Response, err error)

func (*HTTPClient) NewRequest added in v1.2.0

func (c *HTTPClient) NewRequest(method string, url string, body io.Reader) (req *http.Request, err error)

func (*HTTPClient) Post added in v1.2.0

func (c *HTTPClient) Post(url string, contentType string, body io.Reader) (res *http.Response, err error)

func (*HTTPClient) PostForm added in v1.2.0

func (c *HTTPClient) PostForm(url string, form url.Values) (res *http.Response, err error)

type HashErr added in v1.2.0

type HashErr struct {
	Hash   string
	Sum    string
	Expect string
}

func (*HashErr) Error added in v1.2.0

func (e *HashErr) Error() string

type HttpStatusError added in v1.2.0

type HttpStatusError struct {
	Code int
}

func (*HttpStatusError) Error added in v1.2.0

func (e *HttpStatusError) Error() string

type Installer

type Installer interface {
	// target == "" means latest
	Install(path, name string, target string) (installed string, err error)
	ListVersions(snapshot bool) (versions []string, err error)
}

func Get

func Get(name string) (installer Installer, ok bool)

type JavaVersion

type JavaVersion struct {
	Component    string `json:"component"`
	MajorVersion int    `json:"majorVersion"`
}

type LibraryDownloadInfo

type LibraryDownloadInfo struct {
	DownloadInfo
	Path string `json:"path"`
}

type LibraryDownloads

type LibraryDownloads struct {
	Artifact    *LibraryDownloadInfo           `json:"artifact,omitempty"`
	Classifiers map[string]LibraryDownloadInfo `json:"classifiers,omitempty"`
}

type LibraryInfo

type LibraryInfo struct {
	Name      string            `json:"name"`
	Downloads LibraryDownloads  `json:"downloads"`
	Rules     []LibraryRule     `json:"rules,omitempty"`
	Extract   map[string]any    `json:"extract,omitempty"`
	Natives   map[string]string `json:"natives,omitempty"`
}

type LibraryRule

type LibraryRule map[string]any // TODO

type MavenMetadata

type MavenMetadata struct {
	GroupId    string                  `xml:"groupId"`
	ArtifactId string                  `xml:"artifactId"`
	Versioning MavenMetadataVersioning `xml:"versioning"`
}

func DecodeMavenMetadata

func DecodeMavenMetadata(body []byte) (data MavenMetadata, err error)

func GetMavenMetadata

func GetMavenMetadata(link string) (data MavenMetadata, err error)

type MavenMetadataVersioning

type MavenMetadataVersioning struct {
	Release     string   `xml:"release"`
	Latest      string   `xml:"latest"`
	LastUpdated string   `xml:"lastUpdated"`
	Versions    []string `xml:"versions>version"`
}

type Mrpack added in v1.2.0

type Mrpack struct {
	MrpackMeta
	// contains filtered or unexported fields
}

func OpenMrpack added in v1.2.0

func OpenMrpack(filename string) (pack *Mrpack, err error)

func (*Mrpack) Close added in v1.2.0

func (p *Mrpack) Close() (err error)

func (*Mrpack) InstallClient added in v1.2.0

func (p *Mrpack) InstallClient(target string) (err error)

func (*Mrpack) InstallClientWithOptional added in v1.2.0

func (p *Mrpack) InstallClientWithOptional(target string, optionalChecker MrpackOptionalChecker) (err error)

func (*Mrpack) InstallServer added in v1.2.0

func (p *Mrpack) InstallServer(target string) (err error)

func (*Mrpack) InstallServerWithOptional added in v1.2.0

func (p *Mrpack) InstallServerWithOptional(target string, optionalChecker MrpackOptionalChecker) (err error)

func (*Mrpack) OverrideClient added in v1.2.0

func (p *Mrpack) OverrideClient(target string) (err error)

func (*Mrpack) OverrideServer added in v1.2.0

func (p *Mrpack) OverrideServer(target string) (err error)

type MrpackFileMeta added in v1.2.0

type MrpackFileMeta struct {
	Path      string    `json:"path"`
	Hashes    StringMap `json:"hashes"`
	Env       StringMap `json:"env"`
	Downloads []string  `json:"downloads"`
	Size      int64     `json:"fileSize"`
}

type MrpackMeta added in v1.2.0

type MrpackMeta struct {
	FormatVersion int    `json:"formatVersion"`
	Game          string `json:"game"`

	VersionId string `json:"versionId"`
	Name      string `json:"name"`
	Summary   string `json:"summary,optional"`

	Files []MrpackFileMeta `json:"files"`
	Deps  StringMap        `json:"dependencies"`
}

type MrpackOptionalChecker added in v1.2.0

type MrpackOptionalChecker func(f MrpackFileMeta) bool

type MrpackVerisonErr added in v1.2.0

type MrpackVerisonErr struct {
	Version  int
	Supports []int
}

func (*MrpackVerisonErr) Error added in v1.2.0

func (e *MrpackVerisonErr) Error() string

type NotLocalPathErr added in v1.2.0

type NotLocalPathErr struct {
	Path string
}

func (*NotLocalPathErr) Error added in v1.2.0

func (e *NotLocalPathErr) Error() string

type QuiltInstaller added in v1.2.0

type QuiltInstaller struct {
	MavenUrl string
}

func (*QuiltInstaller) GetInstallerVersions added in v1.2.1

func (r *QuiltInstaller) GetInstallerVersions() (data MavenMetadata, err error)

func (*QuiltInstaller) GetLatestInstaller added in v1.2.1

func (r *QuiltInstaller) GetLatestInstaller() (version string, err error)

func (*QuiltInstaller) Install added in v1.2.1

func (r *QuiltInstaller) Install(path, name string, target string) (installed string, err error)

func (*QuiltInstaller) InstallWithLoader added in v1.2.1

func (r *QuiltInstaller) InstallWithLoader(path, name string, target string, loader string) (installed string, err error)

func (*QuiltInstaller) ListVersions added in v1.2.3

func (r *QuiltInstaller) ListVersions(snapshot bool) (versions []string, err error)

type SpigotInstaller

type SpigotInstaller struct {
}

func (*SpigotInstaller) Install

func (*SpigotInstaller) Install(path, name string, target string) (installed string, err error)

func (*SpigotInstaller) ListVersions added in v1.2.3

func (r *SpigotInstaller) ListVersions(snapshot bool) (versions []string, err error)

type StringMap added in v1.2.0

type StringMap = map[string]string

type UnsupportGameErr added in v1.2.0

type UnsupportGameErr struct {
	Game string
}

func (*UnsupportGameErr) Error added in v1.2.0

func (e *UnsupportGameErr) Error() string

type VanillaInstaller

type VanillaInstaller struct {
	ManifestUrl string // Default is "https://launchermeta.mojang.com/mc/game/version_manifest.json"
}

func (*VanillaInstaller) GetVersion

func (r *VanillaInstaller) GetVersion(url string) (res VanillaVersion, err error)

func (*VanillaInstaller) GetVersions

func (r *VanillaInstaller) GetVersions() (res VanillaVersions, err error)

func (*VanillaInstaller) Install

func (r *VanillaInstaller) Install(path, name string, target string) (installed string, err error)

func (*VanillaInstaller) ListVersions added in v1.2.3

func (r *VanillaInstaller) ListVersions(snapshot bool) (versions []string, err error)

type VanillaLatestInfo

type VanillaLatestInfo struct {
	Release  string `json:"release"`
	Snapshot string `json:"snapshot"`
}

type VanillaVersion

type VanillaVersion struct {
	Id                     string                  `json:"id"`
	AssetIndex             AssetIndex              `json:"assetIndex"`
	Assets                 string                  `json:"assets"`
	ComplianceLevel        int                     `json:"complianceLevel"`
	Downloads              map[string]DownloadInfo `json:"downloads"`
	JavaVersion            JavaVersion             `json:"javaVersion"`
	Libraries              []LibraryInfo           `json:"libraries"`
	Logging                map[string]any          `json:"logging"` // TODO
	MainClass              string                  `json:"mainClass"`
	MinecraftArguments     string                  `json:"minecraftArguments"`
	MinimumLauncherVersion int                     `json:"minimumLauncherVersion"`
	ReleaseTime            time.Time               `json:"releaseTime"`
	Time                   time.Time               `json:"time"`
	Type                   string                  `json:"type"`
}

type VanillaVersionInfo

type VanillaVersionInfo struct {
	Id          string    `json:"id"`
	Type        string    `json:"type"`
	Url         string    `json:"url"`
	Time        time.Time `json:"time"`
	ReleaseTime time.Time `json:"releaseTime"`
}

type VanillaVersions

type VanillaVersions struct {
	Latest   VanillaLatestInfo    `json:"latest"`
	Versions []VanillaVersionInfo `json:"versions"`
}

type Version

type Version struct {
	Major int
	Minor int
	Patch int
}

func VersionFromString

func VersionFromString(data string) (v Version, err error)

func (Version) Less

func (v Version) Less(o Version) bool

func (Version) String

func (v Version) String() (s string)

type VersionNotFoundErr

type VersionNotFoundErr struct {
	Version string
}

func (*VersionNotFoundErr) Error

func (e *VersionNotFoundErr) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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