Repository navigation
Expand file tree
/
Copy pathrustservermod.sh
More file actions
199 lines (172 loc) · 6.11 KB
/
Copy pathrustservermod.sh
File metadata and controls
199 lines (172 loc) · 6.11 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
#!/bin/bash
# Rust Administration & Control System - RUSTACS
#
# Rust server mod framework installer
#
# This script installs either Carbon or Oxide on an existing Rust server.
# The selected framework is downloaded from its current Linux release and
# extracted directly into the Rust server installation directory.
#
# Carbon and Oxide must not be installed together. This script checks for an
# existing installation of the other framework and aborts if one is found.
#
# The Rust server service MUST be inactive before this script will continue.
#
### IMPORTANT NOTES:
#
# The dot-env (.rustserver.env) file is a prerequisite for this script to
# run. It needs to be present on the system with the correct permissions
# beforehand.
#
# curl is required for downloading Carbon or Oxide. unzip is also required
# when installing Oxide.
#
### USAGE:
#
# Copy this script into a user directory - e.g. /home/rust/bin/
# Make the script executable:
#
# chmod 770 /home/rust/bin/rustservermod.sh
#
# Install Carbon:
#
# /home/rust/bin/rustservermod.sh carbon
#
# Install Oxide:
#
# /home/rust/bin/rustservermod.sh oxide
#
### MIT License:
#
# Copyright © 2026 Penthux.NET (rust.penthux.net)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the “Software”), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
###
# Load Rust server .env settings
. /home/rust/.rustacs/.rustserver.env
# Variables
PRGNAM="$(basename "${BASH_SOURCE[0]}" .sh)"
RUST_DIR="${RUST_INSTALL_WORKDIR}"
RUST_SERVICE="${RUST_SERVICE_PATH}"
LOG_DIR="${RUST_LOGDIR}"
LOG_FILE="${LOG_DIR}/${PRGNAM}.log"
TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/${PRGNAM}.XXXXXX")"
CARBON_URL="https://github.com/CarbonCommunity/Carbon.Core/releases/download/production_build/Carbon.Linux.Release.tar.gz"
CARBON_ARCHIVE="${TMP_DIR}/Carbon.Linux.Release.tar.gz"
OXIDE_URL="https://umod.org/games/rust/download"
OXIDE_ARCHIVE="${TMP_DIR}/Oxide.Rust-linux.zip"
# Progress log function
log() {
printf "%(%F %T)T : %s: %s\n" "-1" "${PRGNAM}" "${1}" 2>&1 | tee -a "${LOG_FILE}"
}
# Remove temporary download directory
cleanup() {
rm -rf -- "${TMP_DIR}"
}
trap cleanup EXIT
# Verify command argument
case "${1:-}" in
carbon|oxide)
MOD_FRAMEWORK="${1}"
;;
*)
echo "Usage: ${PRGNAM}.sh carbon|oxide" >&2
exit 1
;;
esac
# Verify Rust server installation directory exists
if [ ! -d "${RUST_DIR}" ]; then
log "ERROR! - Rust server installation directory not found: ${RUST_DIR}" >&2
exit 1
fi
# Verify Rust server service unit exists and is inactive
if [ ! -f "${RUST_SERVICE}" ]; then
log "ERROR! - Rust server [systemd] service unit not found: ${RUST_SERVICE}" >&2
exit 1
elif /usr/bin/systemctl is-active --quiet "$(basename "${RUST_SERVICE}")"; then
log "ERROR! - Rust server service is currently active! Aborting..." >&2
exit 1
fi
# Verify required tools
if ! command -v curl >/dev/null 2>&1; then
log "ERROR! - curl not found!" >&2
exit 1
fi
if [ "${MOD_FRAMEWORK}" = "oxide" ] && ! command -v unzip >/dev/null 2>&1; then
log "ERROR! - unzip not found!" >&2
exit 1
fi
# Refuse mixed Carbon and Oxide installations
if [ "${MOD_FRAMEWORK}" = "carbon" ] && [ -d "${RUST_DIR}/oxide" ]; then
log "ERROR! - Existing Oxide installation detected!" >&2
log "ERROR! - Carbon and Oxide cannot be installed together. Aborting..." >&2
exit 1
fi
if [ "${MOD_FRAMEWORK}" = "oxide" ] && [ -d "${RUST_DIR}/carbon" ]; then
log "ERROR! - Existing Carbon installation detected!" >&2
log "ERROR! - Carbon and Oxide cannot be installed together. Aborting..." >&2
exit 1
fi
case "${MOD_FRAMEWORK}" in
carbon)
log "Downloading current Carbon Linux production release..."
if ! curl -fL --retry 3 --connect-timeout 10 \
-o "${CARBON_ARCHIVE}" "${CARBON_URL}"; then
log "ERROR! - Unable to download Carbon!" >&2
exit 1
fi
if [ ! -s "${CARBON_ARCHIVE}" ]; then
log "ERROR! - Carbon download is empty!" >&2
exit 1
fi
log "Installing Carbon into ${RUST_DIR}..."
if ! tar -xzf "${CARBON_ARCHIVE}" -C "${RUST_DIR}"; then
log "ERROR! - Unable to extract Carbon archive!" >&2
exit 1
fi
;;
oxide)
log "Downloading current Oxide Linux release..."
if ! curl -fL --retry 3 --connect-timeout 10 \
-o "${OXIDE_ARCHIVE}" "${OXIDE_URL}"; then
log "ERROR! - Unable to download Oxide!" >&2
exit 1
fi
if [ ! -s "${OXIDE_ARCHIVE}" ]; then
log "ERROR! - Oxide download is empty!" >&2
exit 1
fi
log "Installing Oxide into ${RUST_DIR}..."
if ! unzip -oq "${OXIDE_ARCHIVE}" -d "${RUST_DIR}"; then
log "ERROR! - Unable to extract Oxide archive!" >&2
exit 1
fi
;;
esac
# Set Rust server installation ownership
if ! sudo -n /usr/bin/chown -R \
"${RUST_USERNAME}:${RUST_USERGROUP}" "${RUST_DIR}"; then
log "ERROR! - Unable to set Rust server installation ownership!" >&2
exit 1
fi
# Done
log "$(tr '[:lower:]' '[:upper:]' <<< "${MOD_FRAMEWORK:0:1}")${MOD_FRAMEWORK:1} installation completed successfully!"
log "######"
exit 0
#EOF<*>