commit 67140d743a487b716a3e9033b1e602772bde2d3c Author: Jerry Aldrich Date: Mon Jun 8 23:47:08 2020 -0700 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2f08b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +**/data +**/dgldir/ +**/nethack_var/ +**/sshd_host_keys/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7c483be --- /dev/null +++ b/Dockerfile @@ -0,0 +1,88 @@ +FROM debian:stable-slim as build + +ARG nethack_version=3.6.6 + +RUN apt-get update -y + +RUN apt-get install -y gcc make flex bison build-essential git libncurses5-dev wget autotools-dev autoconf sqlite3 libsqlite3-dev + +# Build dgamelaunch +WORKDIR / + +RUN git clone git://github.com/paxed/dgamelaunch.git + +WORKDIR dgamelaunch + +RUN ./autogen.sh --enable-sqlite --enable-shmem --with-config-file=/opt/nethack/nethack.jerryaldrichiii.com/etc/dgamelaunch.conf + +RUN make + +COPY dgl-create-chroot.sh dgl-create-chroot.sh +RUN sh dgl-create-chroot.sh + +WORKDIR /opt/nethack/nethack.jerryaldrichiii.com/ + +# Copy libs needed at runtime +RUN cp /lib/x86_64-linux-gnu/libncurses.so.6 lib/x86_64-linux-gnu/ +RUN cp /lib/x86_64-linux-gnu/libnss_files.so.2 lib/x86_64-linux-gnu/libnss_files.so.2 + +COPY dgamelaunch.conf etc/dgamelaunch.conf + +# Build Nethack +WORKDIR / +RUN wget https://github.com/NetHack/NetHack/archive/NetHack-${nethack_version}_Released.tar.gz + +RUN tar xvzf NetHack*.tar.gz + +WORKDIR NetHack-NetHack-${nethack_version}_Released + +COPY ./hints.sh hints.sh + +RUN sh sys/unix/setup.sh hints.sh + +RUN make && make install + +# TODO: Add a custom sysconf? https://nethackwiki.com/wiki/Sysconf +RUN cp -R /root/nethack/chroot/nethack/* /opt/nethack/nethack.jerryaldrichiii.com/nethack +RUN chown games:games /opt/nethack/nethack.jerryaldrichiii.com/nethack/sysconf + +# Could probably use alpine..but I'm too lazy to trackdown libc/musl errors +FROM debian:stable-slim + +LABEL maintainer "jerryaldrichiii@gmail.com" + +RUN apt-get update && apt-get install -y openssh-server && apt-get clean + +COPY --from=build /opt/nethack/nethack.jerryaldrichiii.com/ /opt/nethack/nethack.jerryaldrichiii.com +RUN cp -R /opt/nethack/nethack.jerryaldrichiii.com/dgldir /opt/nethack/nethack.jerryaldrichiii.com/dgldir.orig +RUN cp -R /opt/nethack/nethack.jerryaldrichiii.com/nethack/var /opt/nethack/nethack.jerryaldrichiii.com/nethack_var.orig +RUN cp /opt/nethack/nethack.jerryaldrichiii.com/usr/lib/x86_64-linux-gnu/* /usr/lib/x86_64-linux-gnu/ +COPY dgl_menu_main_user.txt /opt/nethack/nethack.jerryaldrichiii.com/ + +RUN useradd --no-create-home --gid 60 --shell /opt/nethack/nethack.jerryaldrichiii.com/dgamelaunch nethack +RUN passwd -d nethack + +RUN chown -R nethack:games /opt/nethack/nethack.jerryaldrichiii.com/nethack + +# If you figure out how to make this run without suid or root...let me know +RUN chmod 4755 /opt/nethack/nethack.jerryaldrichiii.com/dgamelaunch + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +# Configure SSHD +RUN mkdir -p /srv/sshd/host_keys +COPY sshd_config /srv/sshd/sshd_config +RUN chown -R nethack /srv/sshd +RUN cp /etc/passwd /opt/nethack/nethack.jerryaldrichiii.com/etc +RUN chown nethack /etc/shadow + +EXPOSE 2323 + +VOLUME ["/opt/nethack/nethack.jerryaldrichiii.com/dgldir"] +VOLUME ["/opt/nethack/nethack.jerryaldrichiii.com/nethack/var"] +VOLUME ["/srv/sshd/host_keys"] + +USER nethack + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..74cb21e --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# nethack-server via dgamelaunch + Docker + +## Setup + +Create SSHD host keys (optional): + +``` +mkdir bootstrap +ssh-keygen -N '' -t rsa -f data/sshd_host_keys/sshd_host_rsa_key +``` + +Run the server: + +``` +docker build . -t replaceme/nethack-server:latest + +# These directories will contain your persistent data +mkdir -p data/{dgldir,nethack_var,sshd_host_keys} +sudo chown -R 1000:60 data + +docker run -it --rm \ + -p 2222:2222 \ + -v $(pwd)/data/dgldir:/opt/nethack/nethack.jerryaldrichiii.com/dgldir \ + -v $(pwd)/data/nethack_var:/opt/nethack/nethack.jerryaldrichiii.com/nethack/var \ + -v $(pwd)/data/sshd_host_keys:/srv/sshd/host_keys \ + replaceme/nethack-server:latest +``` + +# Forgive me + +This was a weekend project...it could use some work. + +See: TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..9fb91c8 --- /dev/null +++ b/TODO.md @@ -0,0 +1 @@ +Substitute nethack.jerryaldrichii.com with a variable diff --git a/dgamelaunch.conf b/dgamelaunch.conf new file mode 100644 index 0000000..7db9727 --- /dev/null +++ b/dgamelaunch.conf @@ -0,0 +1,341 @@ +# This is a sample dgamelaunch configuration file. Only bash-style comments +# are allowed, such as this. Each configuration option will be explained +# along with its default value. + +# Global config variables: + + +# Max amount of registered users to allow. Has no effect if dgl was +# compiled with SQLite +maxusers = 64000 + +# Allow registration of new nicks? (yes or no) +allow_new_nicks = yes + +# Max length for newly registered nicks. Must be less than 20. +# By default, NetHack only stores the first 10 chars of a name into +# the record/logfile. +maxnicklen = 10 + +# Set the default watching-screen sorting mode. Can be one of +# "username", "game", "windowsize", "starttime" or "idletime". +# "username" is the default. +#sortmode = "username" + +# Set the columns displayed in the watching-screen. Each column definition +# must have four elements as: +# [ "", "", , "" ] +# +# may be "unsorted", "username", "game", "windowsize", "starttime", +# "duration", "idletime", or (if shmem is enabled) "watchers". +# +# watch_columns = [ ["", "", 1, "%s)"], +# ["User", "username", 4, "%-15s"], +# ["Game", "game", 21, "%-11s"], +# ["Term", "windowsize", 34, "%s"], +# ["Idle", "idletime", 43, "%-10s"], +# ["Watchers", "watchers", 55, "%5s"], +# ["Started", "starttime", 65, "%s"] +# ] + +# Path to a prepared chroot jail. +chroot_path = "/opt/nethack/nethack.jerryaldrichiii.com/" + +# From inside the jail, dgamelaunch's working directory for rcfiles/ttyrec/etc +dglroot = "/dgldir/" + +# Strings to be replaced in every banner +# you can have either direct string replacements, like +# "$FOO" = "BAR", or you can get the server time with +# "$FOO" = timeformat("%F %T") +# for the timeformat parameter string format, see man strftime +bannervars = [ + "$MOTDTIME" = "2011.10.08", + "$SERVERID" = "$ATTR(14)nethack.jerryaldrichiii.com$ATTR()", + "$DATETIME" = timeformat("%F %T") +] + +# From inside the jail, location of a banner file, which is +# shown in submenus that cannot be defined separately. +# Some string substitution is done for every banner file contents: +# - bannervars from above +# - $VERSION replaced with "dgamelaunch v" + dgl version number. +# - $USERNAME replaced with logged-in user's name, or with "[Anonymous]" +# - $INCLUDE(filename) the named file will be inserted here. +banner = "/dgl-banner" + +# The following two options are fairly insecure. They will force us to +# load the password/group database into memory while still having root +# privileges. Replace them with shed_uid/shed_gid entries as soon as +# possible if you decide to use them. dgamelaunch will inform you of +# the uids/gids corresponding to your choices when it loads. +# +# Note that shed_uid and shed_gid will always take precedence over +# shed_user and shed_group if they are specified. + +# shed_user: username to shed privileges to +#shed_user = "games" +# shed_group: group name to shed privileges to +#shed_group = "games" + +# Preferably, you may use the respective gids/uids. This is for Debian: +shed_uid = 1000 +shed_gid = 60 + +# Locale. Leaving this out, dgamelaunch will not explicitly set locale. +locale = "en_US.UTF-8" + +# Default TERM, used if the user's $TERM is unknown. +# If undefined, dgamelaunch will just terminate in that case. +default_term = "xterm" + +# Should dgl send select-UTF8-charset escape code? (that is: ESC % G) +# default is no. +#utf8esc = yes + +# Should dgl allow XON/XOFF? Default is "yes", meaning "don't touch it". +# "no" disables XON/XOFF +#flowcontrol = no + +# Maximum time in seconds user can idle in the dgamelaunch menus +# before dgl exits. Default value is 0, which disables the idling timer. +# Does not apply to external programs or config editors. +# For setting game idle time, use max_idle_time in the game DEFINE. +# menu_max_idle_time = 1024 + +# Passwd refers to the file that stores the user database. +# The default passwd file is "/dgl-login" for flat-text database, and for +# sqlite, whatever value was defined for the sqlite database at compile time. +# This is also used for the shared memory key, if shmem is enabled at compile +# time. +#passwd = "/dgl-login" + +# Lockfile is used only when dgl was compiled without sqlite. +#lockfile = "/dgl-lock" + +# +# define some commands that are run when something happens. format is +# commands [