This repository was archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnewdev.sh
More file actions
235 lines (207 loc) · 5.78 KB
/
Copy pathnewdev.sh
File metadata and controls
235 lines (207 loc) · 5.78 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
cd "$(dirname "$0")"
# Helper function for urlencoding variables
urlencode() {
local string="${1}"
local strlen=${#string}
local encoded=""
local pos c o
for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) printf -v o '%%%02x' "'$c"
esac
encoded+="${o}"
done
echo "${encoded}"
RETURN="${encoded}"
}
# Grab credentials
if [ "$#" -eq 4 ]; then
GU="$1"
GP="$2"
MU="$3"
MP="$4"
else
printf "Usage:\t$0\n\t$0 <gitlab-user> <gitlab-pass> <maven-user> <maven-pass>\n\nEnsure your password is properly escaped if passed on the command line.\n\n"
printf "GitLab Username: "
read GU
stty -echo
printf "GitLab Password: "
read GP
stty echo
printf "\nMaven Username: "
read MU
stty -echo
printf "Maven Password: "
read MP
stty echo
echo ""
fi
GUE="$(urlencode ${GU})"
GPE="$(urlencode ${GP})"
# Detect OS and install required system packages
if [ -n "$(command -v apt-get)" ]; then
echo "Detected Debian-like OS"
apt-get -y update
apt-get -y install curl git openjdk-8-jre maven screen wget
else
if [ -n "$(command -v yum)" ]; then
echo "Detected RHEL-like OS"
yum -y update
yum -y install curl git openjdk-8-jre maven screen wget
else
if [ -n "$(command -v )" ]; then
echo "Detected Arch-like OS"
pacman -Sy curl git jre8-openjdk maven screen wget
else
echo "[*] Unsupported OS!"
exit 1
fi
fi
fi
# Add walrus user
if ! id walrus > /dev/null 2>&1; then
useradd walrus
fi
HOME="$(getent passwd "walrus" | cut -d: -f6)"
ROOT="${HOME}/devserver"
# Establish settings file
cat <<EOT > "${HOME}/.m2/settings.xml"
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>${HOME}/.m2/repository</localRepository>
<interactiveMode>true</interactiveMode>
<offline>false</offline>
<servers>
<server>
<id>walrus-private</id>
<username>${MU}</username>
<password>${MP}</password>
</server>
</servers>
</settings>
EOT
chown walrus:walrus "${HOME}/.m2/settings.xml"
# Run remaining commands as walrus user
su - walrus <<'EOF'
cd ~
HOME="$(pwd)"
# Initialize directory & file structure
mkdir -p devserver
cd devserver
ROOT="$(pwd)"
echo "eula=true" > "${ROOT}/eula.txt"
mkdir -p "${ROOT}/plugins/GameManager/components"
git config --global user.email "dev@walrus.gg"
git config --global user.name "Walrus Developer"
mkdir -p ~/.m2
# Clone and build SportPaper
echo "Fetching SportPaper (this will take a few minutes!)..."
git clone https://gitlab.com/WalrusNetwork/minecraft/sportpaper
"${ROOT}/sportpaper/sportpaper" build
sportpath="$(find ${ROOT}/sportpaper/SportPaper-Server/ -name 'sportpaper*.jar')"
if [ "${sportpath}" == "" ] || [ ! -f "${sportpath}" ]; then
echo "[*] It appears sportpaper had a problem being created! Please correct the errors and run this again."
exit 1
fi
ln -s "${sportpath}" sportpaper.jar
echo "Initializing server instance..."
screen -dmS SportPaper bash -c "java -jar '${ROOT}/sportpaper.jar'"
sleep 1
screen -S SportPaper -X stuff "stop
"
# Clone and build Walrus Minecraft plugins
echo "Fetching Walrus repository..."
EOF
su - walrus <<EOF
cd ~
HOME="$(pwd)"
ROOT="${HOME}/devserver"
cd "${ROOT}"
git clone "https://${GUE}:${GPE}@gitlab.com/WalrusNetwork/minecraft/walrus"
EOF
su - walrus <<'EOF'
cd ~
HOME="$(pwd)"
ROOT="${HOME}/devserver"
cd "${ROOT}"
cd "${ROOT}/walrus"
mvn clean install
cd "${ROOT}"
gamescore="$(find ${ROOT}/walrus/ -name 'games-core*.jar')"
gamesoctc="$(find ${ROOT}/walrus/ -name 'games-octc*.jar')"
nervebukkit="$(find ${ROOT}/walrus/ -name 'nerve-bukkit*.jar')"
ubiquitouisbukkit="$(find ${ROOT}/walrus/ -name 'ubiquitous-bukkit*.jar')"
if [ ! -f "${gamescore}" ] || [ ! -f "${gamesoctc}" ] || [ ! -f "${nervebukkit}" ] || [ ! -f "${ubiquitouisbukkit}" ]; then
echo "[*] It appears the walrus plugins couldn't be built! Please correct the errors and run this again."
exit 1
fi
ln -s "${gamescore}" "${ROOT}/plugins/"
ln -s "${nervebukkit}" "${ROOT}/plugins/"
ln -s "${ubiquitouisbukkit}" "${ROOT}/plugins/"
ln -s "${gamesoctc}" "${ROOT}/plugins/GameManager/components/"
# Rerun server for file creation
echo "Re-initializing server instance..."
screen -dmS SportPaper2 bash -c "java -jar '${ROOT}/sportpaper.jar'"
sleep 5
screen -S SportPaper2 -X stuff "stop
"
# Clone and build Walrus Minecraft plugins
EOF
su - walrus <<EOF
echo "Fetching Walrus repositories..."
cd ~
HOME="$(pwd)"
ROOT="${HOME}/devserver"
cd "${ROOT}"
git clone "https://${GUE}:${GPE}@gitlab.com/WalrusNetwork/infrastructure/config"
EOF
su - walrus <<'EOF'
cd ~
HOME="$(pwd)"
ROOT="${HOME}/devserver"
cd "${ROOT}"
cp ${ROOT}/config/* ${ROOT}/ -R
EOF
su - walrus <<EOF
cd ~
HOME="$(pwd)"
ROOT="${HOME}/devserver"
cd "${ROOT}"
git clone "https://${GUE}:${GPE}@gitlab.com/WalrusNetwork/ux-ui/minecraft-ui"
EOF
su - walrus <<'EOF'
cd ~
HOME="$(pwd)"
ROOT="${HOME}/devserver"
cd "${ROOT}"
cp ${ROOT}/minecraft-ui/* ${ROOT}/ -R
git clone "https://github.com/WalrusNetwork/translations"
cp ${ROOT}/translations/* ${ROOT}/ -R
sed -i "s:../translations:${ROOT}/translations:g" "${ROOT}/plugins/Ubiquitous/config.yml"
sed -i "s:../minecraft-ui:${ROOT}/minecraft-ui:g" "${ROOT}/plugins/Ubiquitous/config.yml"
# Configure Maps
echo "Downloading maps..."
EOF
su - walrus <<EOF
echo "Fetching Walrus repositories..."
cd ~
HOME="$(pwd)"
ROOT="${HOME}/devserver"
cd "${ROOT}"
git clone "https://${GUE}:${GPE}@gitlab.com/WalrusNetwork/maps/maps"
EOF
su - walrus <<'EOF'
cd ~
HOME="$(pwd)"
ROOT="${HOME}/devserver"
cd "${ROOT}"
sed -i "s:../maps:${ROOT}/maps:g" "${ROOT}/plugins/GameManager/config.yml"
# TODO: Setup API
echo "[!] You'll have to set up the API yourself. Configure ${ROOT}/plugins/Nerve/config.yml"
echo "Done."
EOF