xash3d-installscript/install-xash3d.sh

430 lines
11 KiB
Bash
Raw Normal View History

2022-08-21 23:57:56 +02:00
#!/bin/bash
2022-08-21 15:06:00 +02:00
2022-09-11 23:57:12 +02:00
# include /etc/os-type for distri specific packages
2022-09-11 23:58:47 +02:00
. /etc/os-release
2022-09-11 23:57:12 +02:00
OS=$ID
OS_VER=$VERSION_ID
2022-09-11 16:16:52 +02:00
## check if variables for installation are predefined otherwise set defaults
for xashvar in BUILD_DIR INSTALL_DIR DS_PORT
do
2022-09-11 16:16:52 +02:00
# build helpervariable
xashvarname=XASH_$xashvar
2022-09-11 16:16:52 +02:00
#
if [ -z ${!xashvarname} ]
then
2022-09-11 15:39:13 +02:00
case ${xashvar} in
2022-09-11 15:33:23 +02:00
BUILD_DIR) XASH_BUILD_DIR=$(pwd)/build ;;
INSTALL_DIR) XASH_INSTALL_DIR=$(pwd)/xash3d ;;
DS_PORT) XASH_DS_PORT=27015 ;;
esac
fi
done
2022-09-11 17:42:44 +02:00
## these variables are from github.com/FWGS/xashds-docker, nice to have :)
hlds_build=8684
amxmod_version=1.8.2
jk_botti_version=1.43
steamcmd_url="https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz"
hlds_url="https://github.com/DevilBoy-eXe/hlds/releases/download/$hlds_build/hlds_build_$hlds_build.zip"
metamod_url="https://github.com/mittorn/metamod-p/releases/download/1/metamod.so"
amxmod_url="http://www.amxmodx.org/release/amxmodx-$amxmod_version-base-linux.tar.gz"
jk_botti_url="http://koti.kapsi.fi/jukivili/web/jk_botti/jk_botti-$jk_botti_version-release.tar.xz"
# colors for colored output 8)
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
ENDCOLOR="\e[0m"
2022-08-21 15:06:00 +02:00
2022-08-26 01:14:27 +02:00
showhelp() {
2022-09-11 16:16:52 +02:00
echo "Usage: $0 [server|client] [install|update] [0.19|0.20]
Description: Script to install an Xash3D engine full game client or dedicated server with game data from steamcmd
Server tested on Debian 11 ; Client tested on Ubuntu 20.04
Origin: https://git.la10cy.net/DeltaLima/xash3d-installscript
You can override following variables default values:
XASH_INSTALL_DIR, XASH_DS_PORT and XASH_BUILD_DIR
Example:
1) Install server version '0.19' into '~/opt/xashds_oldengine'
XASH_INSTALL_DIR=~/opt/xashds_old $0 server install 0.19
2) Update client version 0.20 located in ~/Games/Xash3D where the build directory is as well
XASH_INSTALL_DIR=~/Games/Xash3D XASH_BUILD_DIR=\$XASH_INSTALL_DIR/build $0 client update 0.20
Resources we are using:
$steamcmd_url
$hlds_url
0.20: https://github.com/FWGS/xash3d-fwgs
0.19: https://gitlab.com/tyabus/xash3d"
2022-08-23 11:48:26 +02:00
exit 1
2022-08-26 01:14:27 +02:00
}
2022-09-11 17:42:44 +02:00
function message() {
case $1 in
info)
MESSAGE_TYPE="${GREEN}INFO${ENDCOLOR}"
;;
warn)
MESSAGE_TYPE="${YELLOW}WARN${ENDCOLOR}"
;;
error)
MESSAGE_TYPE="${RED}ERROR${ENDCOLOR}"
;;
esac
echo -e "[${MESSAGE_TYPE}] $2"
}
function checkerror() {
if [ $1 -gt 0 ]
then
message error "Something went wrong, got wrong exit code ${RED}ERROR${ENDCOLOR}"
message error "Exit here."
exit 1
fi
}
case $3 in
"0.19")
XASH_GIT_URL="https://gitlab.com/tyabus/xash3d"
2022-08-26 01:14:27 +02:00
;;
"0.20")
XASH_GIT_URL="https://github.com/FWGS/xash3d-fwgs"
2022-08-26 01:14:27 +02:00
;;
2022-08-26 01:14:27 +02:00
*)
showhelp
2022-08-26 01:14:27 +02:00
;;
esac
XASH_INSTALL_VERSION=$3
2022-08-26 01:14:27 +02:00
case $2 in
"update")
;;
"install")
;;
*)
showhelp
;;
2022-08-23 11:50:45 +02:00
esac
XASH_INSTALL_MODE=$2
2022-09-11 23:30:00 +02:00
# client libsdl2-dev:i386 libfreetype6-dev:i386 libfontconfig-dev:i386
# both g++-multilib git curl build-essential cmake zip xz-utils libstdc++6:i386 lib32gcc1-s1 gnupg2 gcc-multilib ca-certificates
2022-09-11 23:57:12 +02:00
case $OS in
debian)
2022-09-12 00:25:19 +02:00
PACKAGES_OSSPECIFIC="lib32gcc-s1"
2022-09-11 23:57:12 +02:00
;;
ubuntu)
case $OS_VER in
20.04|21.10|22.04)
2022-09-12 00:01:30 +02:00
PACKAGES_OSSPECIFIC="lib32gcc1"
2022-09-11 23:57:12 +02:00
;;
*)
PACKAGES_OSSPECIFIC="lib32gcc1-s1"
;;
2022-09-11 23:58:20 +02:00
esac
2022-09-11 23:57:12 +02:00
;;
esac
2022-09-12 00:02:42 +02:00
XASH_APT_PACKAGES="${PACKAGES_OSSPECIFIC} g++-multilib git curl build-essential cmake zip xz-utils libstdc++6:i386 gnupg2 gcc-multilib ca-certificates python"
case $1 in
"client")
2022-09-11 23:30:00 +02:00
XASH_APT_PACKAGES+=" libsdl2-dev:i386 libfreetype6-dev:i386 libfontconfig-dev:i386"
case $XASH_INSTALL_VERSION in
0.19)
CMAKE_OPTIONS='-DXASH_DOWNLOAD_DEPENDENCIES=yes -DXASH_STATIC=ON-DXASH_DLL_LOADER=ON -DXASH_VGUI=ON -DMAINUI_USE_STB=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_FLAGS="-m32" -DCMAKE_CXX_FLAGS="-m32"'
;;
0.20)
WAF_OPTIONS="--enable-utils --enable-stb"
;;
esac
2022-09-12 00:25:19 +02:00
;;
"server")
case $XASH_INSTALL_VERSION in
0.19)
CMAKE_OPTIONS='-DXASH_DEDICATED=ON -DCMAKE_C_FLAGS="-m32" -DCMAKE_CXX_FLAGS="-m32"'
;;
0.20)
2022-09-11 23:18:23 +02:00
WAF_OPTIONS="-d"
;;
esac
;;
*)
showhelp
;;
esac
XASH_INSTALL_TYPE=$1
export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig
2022-08-21 23:35:06 +02:00
2022-09-11 17:42:44 +02:00
message info "Creating directories"
XASH_GIT_DIR="$(echo ${XASH_GIT_URL} | cut -d / -f5)"
2022-09-11 17:42:44 +02:00
if [ ! -d $XASH_INSTALL_DIR ]
then
mkdir -p $XASH_INSTALL_DIR && message info "created ${YELLOW}${XASH_INSTALL_DIR}${ENDCOLOR}"
checkerror $?
fi
if [ ! -d $XASH_BUILD_DIR ]
then
mkdir -p $XASH_BUILD_DIR && message info "created ${YELLOW}${XASH_BUILD_DIR}${ENDCOLOR}"
checkerror $?
fi
2022-08-21 15:06:00 +02:00
if [ "$XASH_INSTALL_MODE" == "install" ]
2022-08-26 01:14:27 +02:00
then
2022-09-11 17:42:44 +02:00
message info "Performing apt install"
2022-08-26 01:14:27 +02:00
sudo dpkg --add-architecture i386
sudo apt update
2022-09-11 23:18:23 +02:00
sudo apt-get install -y --no-install-recommends $XASH_APT_PACKAGES
2022-08-26 01:14:27 +02:00
fi
2022-08-21 15:28:03 +02:00
2022-09-11 17:42:44 +02:00
message info "Prepare ${YELLOW}${XASH_GIT_DIR}${ENDCOLOR}"
2022-08-21 15:28:03 +02:00
## compile xash3ds
2022-09-11 16:16:52 +02:00
# prepare and configure for compiling
cd $XASH_BUILD_DIR
case $XASH_INSTALL_MODE in
2022-08-26 01:14:27 +02:00
"install")
2022-09-11 17:42:44 +02:00
git clone --recursive $XASH_GIT_URL
checkerror $?
test -d ${XASH_GIT_DIR} || mkdir -p ${XASH_GIT_DIR}/bin/
2022-09-11 17:58:34 +02:00
if [ ! -d ${XASH_GIT_DIR}/bin ]
then
mkdir -p ${XASH_GIT_DIR}/bin && message info "created ${YELLOW}${XASH_GIT_DIR}/bin${ENDCOLOR}"
checkerror $?
fi
2022-09-11 17:42:44 +02:00
checkerror $?
2022-09-11 16:16:52 +02:00
case $XASH_INSTALL_VERSION in
0.19)
cd ${XASH_GIT_DIR}/bin
;;
0.20)
cd ${XASH_GIT_DIR}
;;
esac
2022-08-26 01:14:27 +02:00
;;
"update")
cd ${XASH_GIT_DIR}
case $XASH_INSTALL_VERSION in
0.19)
cd bin
cmake --cmake-clean-cache ../
2022-09-11 17:42:44 +02:00
checkerror $?
cd ../
2022-09-11 17:42:44 +02:00
if [ "$(ls -A bin)" ]
then
rm -Rf bin/*
checkerror $?
fi
git pull
2022-09-11 17:42:44 +02:00
checkerror $?
cd bin
;;
0.20)
./waf clean
2022-09-11 17:42:44 +02:00
checkerror $?
if [ "$(ls -A bin)" ]
then
rm -Rf bin/*
checkerror $?
fi
checkerror $?
git pull
2022-09-11 17:42:44 +02:00
checkerror $?
;;
esac
2022-08-26 01:14:27 +02:00
;;
*)
exit 1
;;
esac
2022-09-03 22:01:36 +02:00
## build
2022-09-11 17:42:44 +02:00
message info "Compiling ${YELLOW}${XASH_GIT_DIR}${ENDCOLOR}"
case $XASH_INSTALL_VERSION in
0.19)
cmake $CMAKE_OPTIONS ../
2022-09-11 17:42:44 +02:00
checkerror $?
make -j2 #VERBOSE=1
2022-09-11 17:42:44 +02:00
checkerror $?
;;
0.20)
./waf configure -T release $WAF_OPTIONS
2022-09-11 17:42:44 +02:00
checkerror $?
./waf -p build
2022-09-11 17:42:44 +02:00
checkerror $?
./waf install --destdir=bin/
2022-09-11 17:42:44 +02:00
checkerror $?
;;
esac
2022-08-21 23:22:25 +02:00
2022-08-21 15:06:00 +02:00
## here we fetch half-life from steam server
if [ "$XASH_INSTALL_MODE" == "install" ]
2022-08-26 01:14:27 +02:00
then
2022-09-11 17:55:20 +02:00
message info "prepare steamcmd for downloading gamedata"
mkdir -p $XASH_BUILD_DIR/steam
2022-09-11 17:42:44 +02:00
checkerror $?
cd $XASH_BUILD_DIR/steam
2022-08-26 01:14:27 +02:00
## an steamcmd automation
echo "login anonymous
force_install_dir $XASH_INSTALL_DIR
2022-08-21 15:06:00 +02:00
app_set_config 90 mod valve
app_update 90
app_update 90
app_update 90 validate
app_update 90 validate
quit" > $XASH_BUILD_DIR/steam/hlds.install
2022-09-11 17:42:44 +02:00
checkerror $?
2022-08-21 15:06:00 +02:00
2022-08-26 01:14:27 +02:00
## fetch steamcmd
2022-09-11 17:42:44 +02:00
message info "getting steamcmd binary"
2022-08-26 01:14:27 +02:00
curl -L "$steamcmd_url" | tar xzvf -
2022-09-11 17:42:44 +02:00
checkerror $?
2022-08-26 01:14:27 +02:00
## run half-life download from steam server with steamcmd
## If grep find Error then fetch the hlds zip from github
2022-09-11 17:45:41 +02:00
message info "downloading gamedata with steamcmd from valve - this takes a while"
2022-09-11 05:51:25 +02:00
if ./steamcmd.sh +runscript hlds.install | grep Error
2022-08-26 01:14:27 +02:00
then
2022-09-11 17:42:44 +02:00
message warn "${YELLOW}!!${ENDCOLOR} There was an error fetching Half-Life with steamcmd. Fallback download it from github ${YELLOW}!!${ENDCOLOR}"
message info "$hlds_url"
2022-08-26 01:14:27 +02:00
## this is just another source you can use instead of steamcmd.
curl -LJO "$hlds_url"
2022-09-11 17:42:44 +02:00
checkerror $?
2022-08-26 01:14:27 +02:00
unzip "hlds_build_$hlds_build.zip" -d "hlds_build_$hlds_build"
2022-09-11 17:42:44 +02:00
checkerror $?
2022-09-12 00:08:18 +02:00
cp -a "hlds_build_$hlds_build/hlds_build_$hlds_build"/* $XASH_INSTALL_DIR
2022-09-12 00:11:49 +02:00
checkerror $?
2022-08-26 01:14:27 +02:00
fi
2022-08-23 11:48:26 +02:00
fi
## copy xash3d binaries to result
2022-08-21 23:22:25 +02:00
## place Xash3D binaries in result and overwrite all
2022-09-11 17:42:44 +02:00
message info "copy xash3d binaries to ${YELLOW}${XASH_INSTALL_DIR}${ENDCOLOR}"
case $XASH_INSTALL_VERSION in
0.19)
cd $XASH_BUILD_DIR/$XASH_GIT_DIR/bin
case $XASH_INSTALL_TYPE in
server)
cp -R engine/xash3d $XASH_INSTALL_DIR/xash
2022-09-11 17:42:44 +02:00
checkerror $?
;;
client)
cp -R engine/xash3d mainui/libxashmenu.so vgui_support/libvgui_support.so vgui_support/vgui.so $XASH_INSTALL_DIR
2022-09-11 17:42:44 +02:00
checkerror $?
;;
esac
;;
0.20)
cp -R $XASH_BUILD_DIR/$XASH_GIT_DIR/bin/* $XASH_INSTALL_DIR
2022-09-11 17:42:44 +02:00
checkerror $?
;;
esac
2022-09-11 18:13:34 +02:00
# copy icon for desktop file to install dir
if [ "$XASH_INSTALL_TYPE" == "client" ] && [ "$XASH_INSTALL_MODE" == "install" ]
then
cp ${XASH_BUILD_DIR}/${XASH_GIT_DIR}/game_launch/icon-xash-material.ico ${XASH_INSTALL_DIR}
fi
2022-08-21 15:06:00 +02:00
2022-09-03 22:01:36 +02:00
2022-08-22 01:32:13 +02:00
# it seems that the build actually (21.08.2022) is buggy and does not exec server.cfg by its own
2022-09-11 05:41:22 +02:00
if [ "$XASH_INSTALL_MODE" == "install" ]
2022-08-23 11:59:12 +02:00
then
2022-09-11 05:41:22 +02:00
case $XASH_INSTALL_TYPE in
server)
2022-09-11 17:42:44 +02:00
message info "Creating start.sh script for dedicated server in ${YELLOW}${XASH_INSTALL_DIR}${ENDCOLOR}"
# all 0.19 xash3d versions are using +port and 0.20 -port
2022-09-11 05:41:22 +02:00
case $XASH_INSTALL_VERSION in
0.19)
2022-09-11 05:51:25 +02:00
lol="+port"
2022-09-11 05:41:22 +02:00
;;
0.20)
2022-09-11 05:51:25 +02:00
lol="-port"
2022-09-11 05:41:22 +02:00
;;
esac
2022-09-11 06:00:39 +02:00
echo "#!/bin/bash
2022-09-11 17:42:44 +02:00
./xash +ip 0.0.0.0 ${lol} ${XASH_DS_PORT} -pingboost 1 -timeout 3 +map boot_camp +exec server.cfg
echo screenname xash_${XASH_INSTALL_VERSION}_${XASH_DS_PORT}" > $XASH_INSTALL_DIR/start.sh
2022-09-11 17:42:44 +02:00
checkerror $?
2022-09-11 05:51:25 +02:00
chmod +x $XASH_INSTALL_DIR/start.sh
2022-09-11 17:42:44 +02:00
checkerror $?
2022-09-11 06:08:56 +02:00
echo "After=network.target
[Service]
User=$(whoami)
WorkingDirectory=${XASH_INSTALL_DIR}
2022-09-11 18:13:34 +02:00
#Type=oneshot
2022-09-11 06:08:56 +02:00
#StandardOutput=journal
ExecStart=${XASH_INSTALL_DIR}/start.sh
2022-09-11 06:08:56 +02:00
ExecStop=/bin/kill -9 \$MAINPID
[Install]
WantedBy=multi-user.target" > $XASH_INSTALL_DIR/xashds_${XASH_INSTALL_VERSION}_${XASH_DS_PORT}.service
2022-09-11 17:42:44 +02:00
checkerror $?
2022-09-11 06:08:56 +02:00
touch $XASH_INSTALL_DIR/valve/listip.cfg
touch $XASH_INSTALL_DIR/valve/banned.cfg
2022-09-11 17:42:44 +02:00
message info "If you need an example config for a public server, have a look into ${YELLOW}https://github.com/FWGS/xashds-docker/tree/master/valve${ENDCOLOR}"
2022-09-11 05:12:04 +02:00
;;
2022-09-11 05:41:22 +02:00
client)
echo "[Desktop Entry]
2022-09-11 18:13:34 +02:00
Name=Xash3D ${XASH_INSTALL_VERSION}
2022-09-11 05:41:22 +02:00
GenericName=Half-Life
2022-09-11 18:13:34 +02:00
Comment=OpenSource Half-Life Engine
2022-09-11 18:42:55 +02:00
Exec=${XASH_INSTALL_DIR}/xash3d
Icon=${XASH_INSTALL_DIR}/icon-xash-material.ico
2022-09-11 05:41:22 +02:00
Terminal=false
Type=Application
StartupNotify=false
Categories=Game;
2022-09-11 18:42:55 +02:00
X-Desktop-File-Install-Version=0.24" > $XASH_INSTALL_DIR/Xash3D_$(echo ${XASH_INSTALL_VERSION} | sed 's/\.//').desktop
2022-09-11 17:42:44 +02:00
checkerror $?
2022-09-11 05:12:04 +02:00
;;
esac
2022-08-23 11:59:12 +02:00
fi
2022-09-11 17:42:44 +02:00
2022-09-11 17:54:01 +02:00
case $XASH_INSTALL_MODE in
2022-09-11 17:42:44 +02:00
install)
message info "${GREEN}DONE!!${ENDCOLOR} Installation completed without erros."
message info "Your ready to run Xash3D installation is located in"
message info "${YELLOW}${XASH_INSTALL_DIR}${ENDCOLOR}"
2022-09-11 17:54:01 +02:00
case $XASH_INSTALL_TYPE in
2022-09-11 17:42:44 +02:00
client)
message info "You can run the game with ${YELLOW}'./xash3d'${ENDCOLOR} from the install location"
2022-09-11 18:42:55 +02:00
message info "To install the game into your applications menu, run:"
message info "${YELLOW}'desktop-file-install --dir=\$HOME/.local/share/applications ${XASH_INSTALL_DIR}/Xash3D_$(echo $XASH_INSTALL_VERSION | sed 's/\.//').desktop'${ENDCOLOR}"
2022-09-11 17:42:44 +02:00
;;
server)
message info "You can start the server with ${YELLOW}'./start.sh'${ENDCOLOR} from the install location"
;;
esac
;;
update)
message info "${GREEN}DONE!!${ENDCOLOR} Update completed without errors."
;;
esac