diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..0dc877d --- /dev/null +++ b/LICENCE @@ -0,0 +1,21 @@ +MIT License + +Copyright © 2021 Canonical Ltd. + +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. diff --git a/snap/gui/com.etlegacy.ETLegacy.desktop b/snap/gui/com.etlegacy.ETLegacy.desktop new file mode 100644 index 0000000..3b9c484 --- /dev/null +++ b/snap/gui/com.etlegacy.ETLegacy.desktop @@ -0,0 +1,13 @@ +[Desktop Entry] +Type=Application +Name=ET: Legacy +GenericName=World War II first-person shooter +Comment=World War II first-person shooter +Icon=${SNAP}/usr/local/share/icons/hicolor/scalable/apps/etl.svg +Exec=etlegacy.etl +Terminal=false +MimeType=x-scheme-handler/et; +Categories=Game;ActionGame; +StartupNotify=false +Keywords=team-based;multiplayer;tactical;WWII;enemy;territory;etl;etlegacy; +PrefersNonDefaultGPU=true diff --git a/snap/hooks/configure b/snap/hooks/configure new file mode 100644 index 0000000..719dd8e --- /dev/null +++ b/snap/hooks/configure @@ -0,0 +1,20 @@ +#!/bin/bash +set -euo pipefail + +daemon=$(snapctl get daemon) +case "$daemon" in + true) + # start the daemon + if snapctl services "$SNAP_INSTANCE_NAME" | grep -q inactive; then + snapctl start --enable "$SNAP_INSTANCE_NAME" 2>&1 || true + fi + ;; + false) + # stop the daemon + snapctl stop --disable "$SNAP_INSTANCE_NAME" 2>&1 || true + ;; + *) + echo "ERROR: Set 'daemon' to one of true|false" + exit 1 + ;; +esac diff --git a/snap/hooks/install b/snap/hooks/install new file mode 100644 index 0000000..c479393 --- /dev/null +++ b/snap/hooks/install @@ -0,0 +1,11 @@ +#!/bin/sh +set -x + +if [ "$(snapctl get daemon)" = "" ] +then + if grep -q -e snap_core= -e snapd_recovery_mode= /proc/cmdline + then snapctl set daemon=true + else snapctl set daemon=false + fi +fi + diff --git a/snap/hooks/post-refresh b/snap/hooks/post-refresh new file mode 100644 index 0000000..c479393 --- /dev/null +++ b/snap/hooks/post-refresh @@ -0,0 +1,11 @@ +#!/bin/sh +set -x + +if [ "$(snapctl get daemon)" = "" ] +then + if grep -q -e snap_core= -e snapd_recovery_mode= /proc/cmdline + then snapctl set daemon=true + else snapctl set daemon=false + fi +fi + diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 0000000..871668b --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,177 @@ +name: etlegacy +summary: FPS Game +description: | + Welcome to ET: Legacy, an open source project that aims to create a fully compatible client + and server for the popular online FPS game Wolfenstein: Enemy Territory - whose gameplay + is still considered unmatched by many, despite its great age. +adopt-info: etl + +base: core22 +compression: lzo +confinement: strict + +apps: + etl: + command-chain: &_command-chain + - bin/graphics-core22-wrapper + - bin/wayland-launch + command: &_command bin/run + plugs: &_plugs + - opengl + - wayland + - hardware-observe + - audio-playback + - joystick + - network + - alsa + environment: &_environment + PULSE_SERVER: unix:$XDG_RUNTIME_DIR/../pulse/native + PULSE_SYSTEM: 1 + PULSE_RUNTIME_PATH: /var/run/pulse + LD_LIBRARY_PATH: ${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${SNAP}/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}:${SNAP}/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/pulseaudio + + etlded: + command: bin/runded + plugs: + - hardware-observe + - network + - network-bind + environment: + LD_LIBRARY_PATH: ${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${SNAP}/usr/lib/${SNAPCRAFT_ARCH_TRIPLET} + + daemon: + daemon: simple + restart-delay: 3s + restart-condition: always + command-chain: *_command-chain + command: *_command + plugs: *_plugs + environment: *_environment + +# This is one of four snippets that relate to providing the userspace graphics needed by your application. +# You can treat this as "magic" so long as you don't need to make changes. +# On the Mir website there's a lot more detail on [the graphics-core22 Snap interface](https://mir-server.io/docs/the-graphics-core22-snap-interface) and it's use. +plugs: + graphics-core22: + interface: content + target: $SNAP/graphics + default-provider: mesa-core22 + +environment: + # Other, generally useful environment settings... + # XDG config + XDG_CACHE_HOME: $SNAP_USER_COMMON/.cache + XDG_CONFIG_HOME: $SNAP_USER_DATA/.config + XDG_CONFIG_DIRS: $SNAP/etc/xdg + XDG_DATA_DIRS: $SNAP/usr/local/share:$SNAP/usr/share + # XKB config + XKB_CONFIG_ROOT: $SNAP/usr/share/X11/xkb + +# The `layout` ensures that files can be found by applications where they are expected by the toolkit or application. +layout: + /usr/share/libdrm: + bind: $SNAP/graphics/libdrm + /usr/share/drirc.d: + symlink: $SNAP/graphics/drirc.d + # Other, generally useful paths + /usr/share/fonts: + bind: $SNAP/usr/share/fonts + /usr/share/icons: + bind: $SNAP/usr/share/icons + /usr/share/sounds: + bind: $SNAP/usr/share/sounds + /etc/fonts: + bind: $SNAP/etc/fonts + /usr/share/alsa: + bind: $SNAP/usr/share/alsa + +parts: + etl: + plugin: cmake + cmake-parameters: + - -DCROSS_COMPILE32=OFF + - -DBUNDLED_LIBS=OFF + - -DRENDERER_DYNAMIC=OFF + - -DINSTALL_OMNIBOT=OFF + - -DBUILD_MOD_PK3=OFF + source-type: git + source-branch: master + source: https://github.com/etlegacy/etlegacy + parse-info: [usr/local/share/metainfo/com.etlegacy.ETLegacy.metainfo.xml] + build-packages: + - g++ + - gcc + - make + - libcurl4-openssl-dev + - libsdl2-dev + - liblua5.4-dev + - libopenal-dev + - libtheora-dev + - libglew-dev + - libogg-dev + - libvorbis-dev + - libgl1-mesa-dev + - freeglut3-dev + - zlib1g-dev + - libminizip-dev + - libturbojpeg0-dev + - libssl-dev + - libcjson-dev + - libfreetype6-dev + - libpng-dev + - libsqlite3-dev + - libx11-dev + - libc-devtools + - libc6-dev + - nasm + - zip + + stage-packages: + - libsdl2-2.0-0 + - libcjson1 + - libcurl4 + - libminizip1 + - libtheora-bin + - libvorbisfile3 + - libglew2.2 + - libgl1 + - libglu1-mesa + - freeglut3 + - libjpeg8 + - libstdc++6 + - liblua5.4-0 + - libsqlite3-0 + - wget + - curl + - unzip + + # Some utility scripts for setting up the Wayland environment + setup: + plugin: dump + source: wayland-launch + override-build: | + # The plugs needed to run Wayland. (wayland-launch checks them, setup.sh connects them) + # You may add further plugs here if you want these options + PLUGS="opengl wayland graphics-core22 hardware-observe audio-playback joystick network" + sed --in-place "s/%PLUGS%/$PLUGS/g" $CRAFT_PART_BUILD/bin/wayland-launch + sed --in-place "s/%PLUGS%/$PLUGS/g" $CRAFT_PART_BUILD/bin/setup.sh + craftctl default + stage-packages: + - inotify-tools + + graphics-core22: + after: + # Your application packaging + - setup + source: https://github.com/MirServer/graphics-core22.git + plugin: dump + override-prime: | + craftctl default + ${CRAFT_PART_SRC}/bin/graphics-core22-cleanup mesa-core22 nvidia-core22 + cd "$CRAFT_PRIME/usr/share/" + rm -rf bug drirc.d glvnd libdrm lintian man + rm -rf applications apport bash-completion dbus-1 doc-base doc gtk-doc\ + help pkgconfig libthai metainfo themes thumbnailers xml + prime: + - bin/graphics-core22-wrapper + diff --git a/wayland-launch/bin/run b/wayland-launch/bin/run new file mode 100644 index 0000000..c8a9109 --- /dev/null +++ b/wayland-launch/bin/run @@ -0,0 +1,53 @@ +#!/bin/sh +set -e + +pack_downloader() { +if [ -f /usr/bin/curl ]; then + curl -P ${SNAP_USER_DATA}/.etlegacy/etmain $1 +else + wget -P ${SNAP_USER_DATA}/.etlegacy/etmain $1 +fi +} + +for dir in */ ; +do + if [ ! -d ${SNAP_USER_DATA}/.etlegacy ]; then + mkdir ${SNAP_USER_DATA}/.etlegacy + + if [ ! -d ${SNAP_USER_DATA}/.etlegacy/etmain ]; then + mkdir ${SNAP_USER_DATA}/.etlegacy/etmain + cp -R ${SNAP}/usr/local/lib/etlegacy/etmain ${SNAP_USER_DATA}/.etlegacy + fi + + if [ ! -d ${SNAP_USER_DATA}/.etlegacy/legacy ]; then + mkdir ${SNAP_USER_DATA}/.etlegacy/legacy + cp -R ${SNAP}/usr/local/lib/etlegacy/legacy ${SNAP_USER_DATA}/.etlegacy + wget `curl https://www.etlegacy.com/download | grep "All supported archive" | grep -Eoi ']+>' | grep -Eo 'href=\"[^\\\"]+\"' | grep -Eo '(http|https):\/\/[^\"]+'` -O ${SNAP_USER_DATA}/.etlegacy/etl.zip + unzip ${SNAP_USER_DATA}/.etlegacy/etl.zip -d ${SNAP_USER_DATA}/.etlegacy/etl + mv ${SNAP_USER_DATA}/.etlegacy/etl/*.pk3 ${SNAP_USER_DATA}/.etlegacy/legacy + rm -rf ${SNAP_USER_DATA}/.etlegacy/etl + rm -rf ${SNAP_USER_DATA}/.etlegacy/*.zip + fi + + if [ ! -f ${SNAP_USER_DATA}/.etlegacy/etmain/pak0.pk3 ]; then + pack_downloader https://mirror.etlegacy.com/etmain/pak0.pk3 + fi + + if [ ! -f ${SNAP_USER_DATA}/.etlegacy/etmain/pak1.pk3 ]; then + pack_downloader https://mirror.etlegacy.com/etmain/pak1.pk3 + fi + + if [ ! -f ${SNAP_USER_DATA}/.etlegacy/etmain/pak2.pk3 ]; then + pack_downloader https://mirror.etlegacy.com/etmain/pak2.pk3 + fi + fi +done + +case "${SNAP_ARCH}" in + amd64) + ${SNAP}/usr/local/bin/etl.x86_64 ;; + arm64) + # We will launch etl with prefix since snapcraft compiled it with it. + ${SNAP}/usr/local/bin/etl.aarch64 ;; +esac + diff --git a/wayland-launch/bin/runded b/wayland-launch/bin/runded new file mode 100644 index 0000000..507dfab --- /dev/null +++ b/wayland-launch/bin/runded @@ -0,0 +1,53 @@ +#!/bin/sh +set -e + +pack_downloader() { +if [ -f /usr/bin/curl ]; then + curl -P ${SNAP_USER_DATA}/.etlded/etmain $1 +else + wget -P ${SNAP_USER_DATA}/.etlded/etmain $1 +fi +} + +for dir in */ ; +do + if [ ! -d ${SNAP_USER_DATA}/.etlded ]; then + mkdir ${SNAP_USER_DATA}/.etlded + + if [ ! -d ${SNAP_USER_DATA}/.etlded/etmain ]; then + mkdir ${SNAP_USER_DATA}/.etlded/etmain + cp -R ${SNAP}/usr/local/lib/etlegacy/etmain ${SNAP_USER_DATA}/.etlded + fi + + if [ ! -d ${SNAP_USER_DATA}/.etlded/legacy ]; then + mkdir ${SNAP_USER_DATA}/.etlded/legacy + cp -R ${SNAP}/usr/local/lib/etlegacy/legacy ${SNAP_USER_DATA}/.etlded + wget `curl https://www.etlegacy.com/download | grep "All supported archive" | grep -Eoi ']+>' | grep -Eo 'href=\"[^\\\"]+\"' | grep -Eo '(http|https):\/\/[^\"]+'` -O ${SNAP_USER_DATA}/.etlded/etl.zip + unzip ${SNAP_USER_DATA}/.etlded/etl.zip -d ${SNAP_USER_DATA}/.etlded/etl + mv ${SNAP_USER_DATA}/.etlded/etl/*.pk3 ${SNAP_USER_DATA}/.etlded/legacy + rm -rf ${SNAP_USER_DATA}/.etlded/etl + rm -rf ${SNAP_USER_DATA}/.etlded/*.zip + fi + + if [ ! -f ${SNAP_USER_DATA}/.etlded/etmain/pak0.pk3 ]; then + pack_downloader https://mirror.etlegacy.com/etmain/pak0.pk3 + fi + + if [ ! -f ${SNAP_USER_DATA}/.etlded/etmain/pak1.pk3 ]; then + pack_downloader https://mirror.etlegacy.com/etmain/pak1.pk3 + fi + + if [ ! -f ${SNAP_USER_DATA}/.etlded/etmain/pak2.pk3 ]; then + pack_downloader https://mirror.etlegacy.com/etmain/pak2.pk3 + fi + fi +done + +case "${SNAP_ARCH}" in + amd64) + ${SNAP}/usr/local/bin/etlded.x86_64 +set fs_homepath ${SNAP_USER_DATA}/.etlded +set g_protect 1 +set omnibot_enable 1 +set omnibot_path "${SNAP_USER_DATA}/.etlded/legacy/omni-bot" +exec etl_server.cfg ;; + arm64) + # We will launch etl with prefix since snapcraft compiled it with it. + ${SNAP}/usr/local/bin/etlded.aarch64 +set fs_homepath ${SNAP_USER_DATA}/.etlded +set g_protect 1 +set omnibot_enable 1 +set omnibot_path "${SNAP_USER_DATA}/.etlded/legacy/omni-bot" +exec etl_server.cfg ;; +esac + diff --git a/wayland-launch/bin/setup.sh b/wayland-launch/bin/setup.sh new file mode 100644 index 0000000..87e3b45 --- /dev/null +++ b/wayland-launch/bin/setup.sh @@ -0,0 +1,31 @@ +#!/bin/sh +set -e + +SNAP_INSTANCE_NAME="$(readlink -f $0 | cut -f 3 -d /)" + +snap_connect_harder() { + # Note the available slot providers + if ! snap connections ${SNAP_INSTANCE_NAME} | grep --quiet "^content.*${SNAP_INSTANCE_NAME}:$1.*$"; then + available_providers="$(snap interface "$1" | sed -e '1,/slots:/d')" + else + available_providers="$(snap interface content | sed -e '1,/slots:/d' | grep "$1")" + fi + + # For wayland try some well known providers + if [ "wayland" = "$1" ]; then + for PROVIDER in ubuntu-frame mir-kiosk; do + if echo "$available_providers" | grep --quiet "\- ${PROVIDER}"; then + sudo snap connect "${SNAP_INSTANCE_NAME}:$1" "${PROVIDER}:$1" + return 0 + fi + done + fi + + echo "Warning: Failed to connect '$1'. Please connect manually, available providers are:\n$available_providers" +} + +for PLUG in %PLUGS%; do + if ! snap connections ${SNAP_INSTANCE_NAME} | grep --quiet "^.*${SNAP_INSTANCE_NAME}:${PLUG}.*${PLUG}.*$"; then + sudo snap connect "${SNAP_INSTANCE_NAME}:${PLUG}" 2> /dev/null || snap_connect_harder ${PLUG} + fi +done diff --git a/wayland-launch/bin/wayland-launch b/wayland-launch/bin/wayland-launch new file mode 100644 index 0000000..8a8982a --- /dev/null +++ b/wayland-launch/bin/wayland-launch @@ -0,0 +1,46 @@ +#!/bin/sh +set -e + +for PLUG in %PLUGS%; do + if ! snapctl is-connected ${PLUG} + then + echo "WARNING: ${PLUG} interface not connected! Please run: /snap/${SNAP_INSTANCE_NAME}/current/bin/setup.sh" + fi +done + +if ! command -v inotifywait > /dev/null +then + echo "ERROR: inotifywait could not be found, mir-kiosk-snap-launch expects:" + echo " . . : stage-packages:" + echo " . . : - inotify-tools" + exit 1 +fi + +wait_for() +{ + until + until + inotifywait --event create "$(dirname "$1")"& + inotify_pid=$! + [ -e "$1" ] || sleep 2 && [ -e "$1" ] + do + wait "${inotify_pid}" + done + kill "${inotify_pid}" + [ -O "$1" ] + do + sleep 1 + done +} + +real_xdg_runtime_dir=$(dirname "${XDG_RUNTIME_DIR}") +export WAYLAND_DISPLAY="${real_xdg_runtime_dir}/${WAYLAND_DISPLAY:-wayland-0}" + +# On core systems may need to wait for real XDG_RUNTIME_DIR +wait_for "${real_xdg_runtime_dir}" +wait_for "${WAYLAND_DISPLAY}" + +mkdir -p "$XDG_RUNTIME_DIR" -m 700 +unset DISPLAY + +exec "$@"