-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerater.sh
executable file
·125 lines (94 loc) · 3.05 KB
/
generater.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
BASE_DIR=$(dirname $0)
DOCKERFILE_SUFFIX=.tmp.Dockerfile
echo 'Generating Dockerfile suffix:' "${DOCKERFILE_SUFFIX}"
[ -n "$DEFAULT_JAVA" ] || DEFAULT_JAVA=17
[ -n "$PYTHON_VERSION" ] || PYTHON_VERSION=3.11
if ! [ -n "$NO_MCDR" ]; then
[ -n "$MCDR_VERSION" ] || { echo 'FAULT: You must set the mcdreforged version at `MCDR_VERSION`'; exit 2; }
echo 'Generating mcdr version:' "v${MCDR_VERSION}"
fi
[ -n "${JAVA_VERSIONS[*]}" ] || JAVA_VERSIONS=(8 11 17)
echo 'Generating Java versions:' "${JAVA_VERSIONS[*]}"
SI_REPO='kmcsr/server-installer'
function fetchGithubLatestTagForServerInstaller(){
prefix="location: https://github.com/$SI_REPO/releases/tag/"
location=$(curl -fsSI "https://github.com/$SI_REPO/releases/latest" | grep "$prefix" | tr -d "\r")
[ $? = 0 ] || return 1
export SI_LATEST_TAG="${location#${prefix}}"
}
fetchGithubLatestTagForServerInstaller || { echo "Could not fetch the latest tag for $SI_REPO"; exit 1; }
si_src="https://github.com/$SI_REPO/releases/download/$SI_LATEST_TAG/minecraft_installer-linux-amd64"
echo "==> Downloading $si_src"
curl -fL -o "minecraft_installer.tmp" "$si_src" || exit $?
function gen_vanilla(){
_JAVA=$1
[ -n "$_JAVA" ] || _JAVA=$DEFAULT_JAVA
_FILE="java${_JAVA}${DOCKERFILE_SUFFIX}"
echo ">>> generating ${_FILE}"
cat >"$_FILE" <<EOF
# syntax=docker/dockerfile:1
FROM alpine:latest
RUN apk add --no-cache openjdk${_JAVA}-jre && \\
java -version
WORKDIR /minecraft
COPY ${BASE_DIR}/entry_point.sh /root/entry_point.sh
COPY ${BASE_DIR}/init_vanilla.sh /root/init.sh
ENV COMMAND="/usr/bin/env java -jar"
ENV ARGS=minecraft.jar
COPY ./minecraft_installer.tmp /usr/local/bin/minecraft_installer
RUN chmod 0755 /usr/local/bin/minecraft_installer
STOPSIGNAL SIGINT
ENTRYPOINT ["/root/entry_point.sh", "/root/init.sh"]
CMD []
EOF
}
function gen_mcdr(){
_JAVA=$1
[ -n "$_JAVA" ] || _JAVA=$DEFAULT_JAVA
_FILE="java${_JAVA}-mcdr${MCDR_VERSION}${DOCKERFILE_SUFFIX}"
echo ">>> generating ${_FILE}"
cat >"$_FILE" <<EOF
# syntax=docker/dockerfile:1
FROM craftmine/server-installer:latest AS server_installer
FROM python:${PYTHON_VERSION}-alpine
RUN apk add --no-cache --virtual .install-deps \\
gcc \\
gdbm-dev \\
libc-dev \\
libffi-dev \\
libnsl-dev \\
libtirpc-dev \\
linux-headers \\
make \\
&& \\
pip3 install 'mcdreforged~=${MCDR_VERSION}' && \\
python3 --version && \\
apk del --no-network .install-deps;
RUN apk add --no-cache openjdk${_JAVA}-jre && \\
java -version
WORKDIR /minecraft
COPY ${BASE_DIR}/entry_point.sh /root/entry_point.sh
COPY ${BASE_DIR}/init_mcdr.sh /root/init.sh
ENV COMMAND="/usr/bin/env python3 -m mcdreforged"
ENV ARGS=
COPY ./minecraft_installer.tmp /usr/local/bin/minecraft_installer
RUN chmod 0755 /usr/local/bin/minecraft_installer
STOPSIGNAL SIGINT
ENTRYPOINT ["/root/entry_point.sh", "/root/init.sh"]
CMD []
EOF
}
function generate(){
gen_vanilla "$@"
if ! [ -n "$NO_MCDR" ]; then
gen_mcdr "$@"
fi
}
echo
echo '==> Clearing old tmp dockerfiles'
rm *"${DOCKERFILE_SUFFIX}"
echo
for j in ${JAVA_VERSIONS[@]}; do
generate $j
done