Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
b693f0cda9 | |||
16f2f26236 | |||
dc9b3a7262 | |||
da099a11ce | |||
1723c26ba9 |
34
.gitignore
vendored
34
.gitignore
vendored
@ -1,23 +1,21 @@
|
|||||||
# ---> Go
|
# ---> Rust
|
||||||
# If you prefer the allow list template instead of the deny list, see community template:
|
# Generated by Cargo
|
||||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
# will have compiled files and executables
|
||||||
#
|
debug/
|
||||||
# Binaries for programs and plugins
|
target/
|
||||||
*.exe
|
|
||||||
*.exe~
|
|
||||||
*.dll
|
|
||||||
*.so
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Test binary, built with `go test -c`
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
*.test
|
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||||
|
Cargo.lock
|
||||||
|
|
||||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
# These are backup files generated by rustfmt
|
||||||
*.out
|
**/*.rs.bk
|
||||||
|
|
||||||
# Dependency directories (remove the comment below to include it)
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
# vendor/
|
*.pdb
|
||||||
|
|
||||||
# Go workspace file
|
|
||||||
go.work
|
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
30
.woodpecker.yml
Normal file
30
.woodpecker.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
pipeline:
|
||||||
|
tests:
|
||||||
|
image: rust:1.63
|
||||||
|
commands:
|
||||||
|
- "cargo test"
|
||||||
|
|
||||||
|
build_release:
|
||||||
|
image: rust:1.63
|
||||||
|
commands:
|
||||||
|
- "cargo install cargo-deb cargo-generate-rpm"
|
||||||
|
- "cargo build --release"
|
||||||
|
- "cargo deb"
|
||||||
|
- "cargo generate-rpm"
|
||||||
|
- "mv target/release/mcst target/release/mcst-${CI_COMMIT_TAG}-linux-x86_64"
|
||||||
|
when:
|
||||||
|
event: tag
|
||||||
|
|
||||||
|
gitea_release:
|
||||||
|
image: plugins/gitea-release
|
||||||
|
settings:
|
||||||
|
api_key:
|
||||||
|
from_secret: gitea_api_key
|
||||||
|
base_url: https://git.metaunix.net
|
||||||
|
files:
|
||||||
|
- "target/release/*${CI_COMMIT_TAG}-linux-x86_64"
|
||||||
|
- "target/debian/mcst*.deb"
|
||||||
|
- "target/generate-rpm/mcst*.rpm"
|
||||||
|
title: "${CI_COMMIT_TAG}"
|
||||||
|
when:
|
||||||
|
event: tag
|
30
Cargo.toml
Normal file
30
Cargo.toml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
[package]
|
||||||
|
name = "mcst"
|
||||||
|
description = "Bit Goblin Minecraft server management tool."
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
readme = "README.md"
|
||||||
|
license = "BSD 2-Clause"
|
||||||
|
authors = ["Gregory Ballantine <gballantine@bitgoblin.tech>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clap = { version = "3.2", features = ["derive"] }
|
||||||
|
reqwest = { version = "0.11", features = ["blocking"] }
|
||||||
|
shellexpand = "2.1"
|
||||||
|
|
||||||
|
[package.metadata.deb]
|
||||||
|
license-file = "LICENSE"
|
||||||
|
depends = "openjdk-17-jre"
|
||||||
|
section = "games"
|
||||||
|
assets = [
|
||||||
|
["target/release/mcst", "usr/bin/mcst", "755"],
|
||||||
|
["README.md", "usr/share/doc/zealot/README", "644"]
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.metadata.generate-rpm]
|
||||||
|
assets = [
|
||||||
|
{ source = "target/release/mcst", dest = "/usr/bin/mcst", mode = "755" },
|
||||||
|
{ source = "README.md", dest = "/usr/share/doc/mcst/README", mode = "644"}
|
||||||
|
]
|
||||||
|
[package.metadata.generate-rpm.requires]
|
||||||
|
java-17-openjdk = "*"
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) <year> <owner>
|
Copyright (c) 2022 Bit Goblin
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
2
src/cmd/mod.rs
Normal file
2
src/cmd/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod new;
|
||||||
|
pub mod start;
|
37
src/cmd/new.rs
Normal file
37
src/cmd/new.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
extern crate reqwest;
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
use std::io;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
|
||||||
|
pub fn new_command(server_name: &str, minecraft_version: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("Creating new server with name '{}' using version '{}'.", server_name, minecraft_version);
|
||||||
|
|
||||||
|
let home_path = shellexpand::tilde("~");
|
||||||
|
let server_directory_path = format!("{}/{}", home_path, server_name);
|
||||||
|
let server_file_path = format!("{}/server_{}.jar", server_directory_path, minecraft_version);
|
||||||
|
|
||||||
|
// create the server directory
|
||||||
|
println!("Creating server directory {}.", server_directory_path);
|
||||||
|
fs::create_dir(&server_directory_path)?;
|
||||||
|
|
||||||
|
// download the Minecraft server JAR file
|
||||||
|
let server_jar_url = "https://piston-data.mojang.com/v1/objects/f69c284232d7c7580bd89a5a4931c3581eae1378/server.jar";
|
||||||
|
println!("Downloading {} to {}.", server_jar_url, server_file_path);
|
||||||
|
let mut resp = reqwest::blocking::get(server_jar_url)?;
|
||||||
|
let mut out = fs::File::create(server_file_path)?;
|
||||||
|
io::copy(&mut resp, &mut out)?;
|
||||||
|
|
||||||
|
// create the start.sh shell script
|
||||||
|
let script_file_path = format!("{}/start.sh", server_directory_path);
|
||||||
|
println!("Creating start.sh script.");
|
||||||
|
let mut script_file = fs::File::create(script_file_path)?;
|
||||||
|
let script_file_contents = format!("#!/bin/sh\n\ncd {}\njava -Xmx2048M -Xms2048M -jar server_{}.jar nogui", server_directory_path, minecraft_version);
|
||||||
|
script_file.write_all(script_file_contents.as_bytes())?;
|
||||||
|
// set the file permissions on the start.sh script
|
||||||
|
script_file.set_permissions(fs::Permissions::from_mode(0o755))?;
|
||||||
|
|
||||||
|
// return empty result to signify everything is okay
|
||||||
|
Ok(())
|
||||||
|
}
|
27
src/cmd/start.rs
Normal file
27
src/cmd/start.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
|
pub fn start_command(server_name: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("Starting server {}.", server_name);
|
||||||
|
|
||||||
|
// set up our path variables
|
||||||
|
let home_path = shellexpand::tilde("~");
|
||||||
|
let server_directory_path = format!("{}/{}", home_path, server_name);
|
||||||
|
let script_file_path = format!("{}/start.sh", server_directory_path);
|
||||||
|
let eula_file_path = format!("{}/eula.txt", server_directory_path);
|
||||||
|
|
||||||
|
// check if eula.txt exists - if it doesn't then warn the user they'll need to accept it and possibly modify server settings
|
||||||
|
if !std::path::Path::new(&eula_file_path).exists() {
|
||||||
|
println!("The eula.txt does not exist - you will need to accept the EULA located at {} by changing 'false' to 'true'.", eula_file_path);
|
||||||
|
println!("This appears to be a new server instance. Don't forget to modify server.properties!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// run the start command
|
||||||
|
Command::new(script_file_path)
|
||||||
|
.stdin(Stdio::null())
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.stderr(Stdio::null())
|
||||||
|
.spawn()?;
|
||||||
|
|
||||||
|
// return okay signal
|
||||||
|
Ok(())
|
||||||
|
}
|
45
src/main.rs
Normal file
45
src/main.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
mod cmd;
|
||||||
|
|
||||||
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[clap(name = "Minecraft server management tool", author, version, about = "Bit Goblin's Minecraft server management tool.", long_about = None)]
|
||||||
|
#[clap(propagate_version = true)]
|
||||||
|
struct Cli {
|
||||||
|
#[clap(subcommand)]
|
||||||
|
command: Commands,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
enum Commands {
|
||||||
|
// new server subcommand
|
||||||
|
#[clap(name = "new", about = "Create a new Minecraft java edition server instance.")]
|
||||||
|
New {
|
||||||
|
#[clap(short = 'n', long, required = true, help = "[REQUIRED] The name for your new server.")]
|
||||||
|
server_name: String,
|
||||||
|
#[clap(short = 'm', long, required = true, help = "[REQUIRED] Minecraft Java Edition server version to use.")]
|
||||||
|
minecraft_version: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[clap(name = "start", about = "Start a Minecraft java edition server instance.")]
|
||||||
|
Start {
|
||||||
|
#[clap(short = 'n', long, required = true, help = "[REQUIRED] The name of your Minecraft server instance.")]
|
||||||
|
server_name: String,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// start the Clap CLI
|
||||||
|
let cli = Cli::parse();
|
||||||
|
|
||||||
|
// map subcommands back to the main command
|
||||||
|
let res = match &cli.command {
|
||||||
|
Commands::New { server_name, minecraft_version } => cmd::new::new_command(&server_name, &minecraft_version),
|
||||||
|
Commands::Start { server_name } => cmd::start::start_command(&server_name),
|
||||||
|
};
|
||||||
|
|
||||||
|
match res {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(e) => panic!("MCST ran into an error: {}", e),
|
||||||
|
};
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user