From 87140179f272fa66af254c9e9c2512cc22b4b0fa Mon Sep 17 00:00:00 2001 From: "Daniel L. Polanco" Date: Wed, 4 Mar 2015 16:55:57 -0700 Subject: [PATCH] Add option for Vanilla or Forge server --- minecraft-server/Dockerfile | 1 + minecraft-server/minecraftforge_spider.py | 68 ----------------------- minecraft-server/start-minecraft.sh | 59 ++++++++++++++------ 3 files changed, 44 insertions(+), 84 deletions(-) delete mode 100644 minecraft-server/minecraftforge_spider.py diff --git a/minecraft-server/Dockerfile b/minecraft-server/Dockerfile index ef686025..84b9accb 100644 --- a/minecraft-server/Dockerfile +++ b/minecraft-server/Dockerfile @@ -26,4 +26,5 @@ ENV UID 1000 ENV MOTD A Minecraft Server Powered by Docker ENV LEVEL world ENV JVM_OPTS -Xmx1024M -Xms1024M +ENV TYPE VANILLA ENV VERSION LATEST diff --git a/minecraft-server/minecraftforge_spider.py b/minecraft-server/minecraftforge_spider.py deleted file mode 100644 index 799d0fb2..00000000 --- a/minecraft-server/minecraftforge_spider.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- coding: utf-8 -*- -import scrapy -from scrapy.contrib.spiders import CrawlSpider, Rule -from scrapy.contrib.linkextractors import LinkExtractor -from scrapy.selector import Selector - -import re - -class Forge(scrapy.Item): - versions = scrapy.Field() - latest = scrapy.Field() - -class ForgeVersions(scrapy.Item): - id = scrapy.Field() - minecraft = scrapy.Field() - type = scrapy.Field() - time = scrapy.Field() - url = scrapy.Field() - -class ForgeLatest(scrapy.Item): - forge_latest = scrapy.Field() - forge_recommended = scrapy.Field() - -class ForgeSpider(CrawlSpider): - name = "ForgeSpider" - allowed_domains = ["minecraftforge.net"] - start_urls = ['http://files.minecraftforge.net'] - - def parse(self, response): - forge = Forge() - forge['versions'] = [] - forge['latest'] = ForgeLatest() - - selector = Selector(response) - rows = selector.xpath('//table[@id="promotions_table"]//tr') - header = rows.pop(0) - for row in rows: - cells = row.xpath('td') - - id = cells[1].xpath('text()').extract() - minecraft = cells[2].xpath('text()').extract() - type = cells[0].xpath('text()') - time = cells[3].xpath('text()') - url = cells[4].xpath('a[text()="Installer"]/@href') - - #if has version - has_version = re.match('(.+)\-.+', ''.join(type.extract())) - if has_version: - download = ForgeVersions() - download['id'] = id - download['minecraft'] = minecraft - download['type'] = 'forge_' + ''.join(type.re('([a-zA-Z]+)')).lower() - download['time'] = time.extract() - download['url'] = url.re('http://adf.ly/\d+/(.+)') - - forge['versions'].append(download) - else: - is_recommended = re.match('Recommended', ''.join(type.extract())) - if is_recommended: - download = ForgeLatest() - forge['latest']['forge_recommended'] = id - else: - download = ForgeLatest() - forge['latest']['forge_latest'] = id - - - return forge - diff --git a/minecraft-server/start-minecraft.sh b/minecraft-server/start-minecraft.sh index 568a7d5b..ba469853 100755 --- a/minecraft-server/start-minecraft.sh +++ b/minecraft-server/start-minecraft.sh @@ -15,22 +15,49 @@ if [ ! -e /data/eula.txt ]; then fi fi -case $VERSION in - LATEST) - export VERSION=`wget -O - https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | jsawk -n 'out(this.latest.release)'` - ;; - - SNAPSHOT) - export VERSION=`wget -O - https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | jsawk -n 'out(this.latest.snapshot)'` - ;; -esac - cd /data -if [ ! -e minecraft_server.$VERSION.jar ]; then - echo "Downloading minecraft_server.$VERSION.jar ..." - wget -q https://s3.amazonaws.com/Minecraft.Download/versions/$VERSION/minecraft_server.$VERSION.jar -fi +case $TYPE in + VANILLA) + case $VERSION in + LATEST) + export VANILLA_VERSION=`wget -O - https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | jsawk -n 'out(this.latest.release)'` + ;; + SNAPSHOT) + export VANILLA_VERSION=`wget -O - https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | jsawk -n 'out(this.latest.snapshot)'` + ;; + esac + export SERVER="minecraft_server.$VANILLA_VERSION" + + if [ ! -e $SERVER ]; then + echo "Downloading $SERVER ..." + wget -q https://s3.amazonaws.com/Minecraft.Download/versions/$VANILLA_VERSION/$SERVER + fi + ;; + + FORGE) + case $VERSION in + LATEST) + export FORGE_VERSION=`wget -O - http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json \ + | jsawk -n 'out(this.promos.recommended)'` + ;; + SNAPSHOT) + export FORGE_VERSION=`wget -O - http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json \ + | jsawk -n 'out(this.promos.latest)'` + ;; + esac + export FORGE_INSTALLER="forge-$VERSION-$FORGE_VERSION-installer.jar" + export SERVER="forge-$VERSION-$FORGE_VERSION-universal.jar" + + if [ ! -e $SERVER ]; then + echo "Downloading $SERVER ..." + wget -q http://files.minecraftforge.net/maven/net/minecraftforge/forge/$VERSION-$FORGE_VERSION/$FORGE_INSTALLER + fi + + echo "Installing $SERVER" + exec java -jar $FORGE_INSTALLER --installServer + ;; +esac if [ ! -e server.properties ]; then cp /tmp/server.properties . @@ -62,7 +89,7 @@ if [ ! -e server.properties ]; then exit 1 ;; esac - + sed -i "/gamemode\s*=/ c gamemode=$MODE" /data/server.properties fi fi @@ -85,5 +112,5 @@ if [ -n "$ICON" -a ! -e server-icon.png ]; then fi fi -exec java $JVM_OPTS -jar minecraft_server.$VERSION.jar +exec java $JVM_OPTS -jar $SERVER