Skip to content

Commit

Permalink
Merge pull request #3
Browse files Browse the repository at this point in the history
储存库结构重置
  • Loading branch information
Ecss11 authored Jun 12, 2021
2 parents 9480e32 + a1fae85 commit 9127c1c
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 341 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mc-server-util 是一个集合多种服务器管理工具的项目,支持 windows/linux 并提供可被调用的接口
minecraft-server-installer 是一个自动化服务端安装工具

## 功能介绍
## 前置需求

请参考文档:https://actiniumcraft.github.io/mc-server-utils/#/README
本脚本基于 Python3 开发。

## 参与贡献
目前暂不支持自动修改配置文件,安装完后需手动按需求修改.

如果您有意参与贡献,可以通过这篇文档开始:https://actiniumcraft.github.io/mc-server-utils/#/contribute
## 下载方法

访问 [Release](https://github.com/ActiniumCraft/minecraft-server-installer/releases) 页面下载初始化安装脚本。
Empty file removed docs/.nojekyll
Empty file.
9 changes: 0 additions & 9 deletions docs/_sidebar.md

This file was deleted.

50 changes: 0 additions & 50 deletions docs/code-of-conduct.md

This file was deleted.

16 changes: 0 additions & 16 deletions docs/contributing.md

This file was deleted.

41 changes: 0 additions & 41 deletions docs/index.html

This file was deleted.

1 change: 0 additions & 1 deletion docs/intro.md

This file was deleted.

23 changes: 0 additions & 23 deletions docs/server-installer.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# -*- coding: utf-8 -*-
import os
import abc
import os
import platform

try:
import wget
print('已检测到 wget 模块 ok')
import requests
print('已检测到 requests 模块 ok')
except ImportError:
print('检测到依赖库缺失,现在开始安装......')
os.system('pip install wget')
os.system('pip install requests')
import wget
import requests
import requests
import wget

PLATFORM = platform.system()
PYTHON_COMMAND = 'python' if PLATFORM == 'Windows' else 'python3'
PIP_COMMAND = 'pip' if PLATFORM == 'Windows' else 'pip3'


class ServerInstaller(object):
Expand All @@ -24,16 +19,6 @@ class ServerInstaller(object):
def install(self):
"""Install new server.
Returns: None.
"""
pass

def check(self):
"""Check server install status.
Returns: The return value. Boolean, True or False.
"""
pass

Expand All @@ -42,6 +27,7 @@ class Vanilla(ServerInstaller):
"""Vanilla factory.
"""

def __init__(self):
self.version_manifest = {}
self.version_json = {}
Expand All @@ -67,8 +53,8 @@ def install(self, version='latest'):
with open('vanilla_start.bat', 'w', encoding='utf-8') as f:
f.write('java -Xms1024M -Xmx2048M -jar server.jar nogui')

def check(self):
return os.path.exists('vanilla_start.bat')
with open('vanilla_start.sh', 'w', encoding='utf-8') as f:
f.write('java -Xms1024M -Xmx2048M -jar server.jar nogui')


class Fabric(ServerInstaller):
Expand All @@ -89,8 +75,8 @@ def install(self, version='latest'):
with open('fabric_start.bat', 'w', encoding='utf-8') as f:
f.write('java -Xms1024M -Xmx2048M -jar fabric-server-launch.jar nogui')

def check(self):
return os.path.exists('fabric_start.bat')
with open('fabric_start.sh', 'w', encoding='utf-8') as f:
f.write('java -Xms1024M -Xmx2048M -jar fabric-server-launch.jar nogui')


class MCDR(ServerInstaller):
Expand All @@ -99,14 +85,11 @@ class MCDR(ServerInstaller):
"""

def install(self):
os.system('pip install mcdreforged')
os.system('python -m mcdreforged')
os.system('{} install mcdreforged'.format(PIP_COMMAND))
os.system('{} -m mcdreforged'.format(PYTHON_COMMAND))

with open('MCDR_start.bat', 'w', encoding='utf-8') as f:
f.write('python -m mcdreforged')

def check(self):
return os.path.exists('MCDR_start.bat')
f.write('{} -m mcdreforged'.format(PYTHON_COMMAND))


def replace_file_line(file, old_line, new_line):
Expand All @@ -122,25 +105,26 @@ def replace_file_line(file, old_line, new_line):
"""
file_data = ''

with open(file, 'r', encoding='utf-8') as f: # 读取文件并获得替换文本
with open(file, 'r', encoding='utf-8') as f:
for line in f:
if old_line in line:
line = line.replace(old_line, new_line)
file_data = file_data + line

with open(file, 'w', encoding='utf-8') as f: # 写入替换文本至文件
with open(file, 'w', encoding='utf-8') as f:
f.write(file_data)


if __name__ == '__main__':
os.system('python -m pip install --upgrade pip')
os.system('{} -m {} install --upgrade {}'.format(PYTHON_COMMAND, PIP_COMMAND, PIP_COMMAND))

print('是否选择安装 MCDR [y/N]')
select_mcdr = str(input('输入: ') or 'n').lower()

if select_mcdr not in {'y', 'yes', 'n', 'no'}:
raise Exception('请选择 y 或 n')
if select_mcdr in {'y', 'yes'}:
print('安装正在进行中,请稍等。。。')
MCDR().install()
os.chdir('./server/')

Expand All @@ -151,8 +135,10 @@ def replace_file_line(file, old_line, new_line):
select_version = str(input('输入: ') or 'latest').lower()

if select_core in {'vanilla', 'v'}:
print('安装正在进行中,请稍等。。。')
Vanilla().install(version=select_version)
elif select_core in {'fabric', 'f'}:
print('安装正在进行中,请稍等。。。')
Fabric().install(version=select_version)
else:
raise Exception('错误的内核')
Loading

0 comments on commit 9127c1c

Please sign in to comment.