[PATCH] gnu: Add bsd-games.

DoneSubmitted by Vitaliy Shatrov.
2 participants
  • Vitaliy Shatrov
  • Nicolas Goaziou
Vitaliy Shatrov wrote on 24 Apr 2020 15:54
(name . guix-patches@gnu.org)(address . guix-patches@gnu.org)
The most important thing to review is rights. This package assumes that all score-files and save-games are placed in /var/tmp/bsd-games. The first user owns the files, and the wrapper script do `chmod ug+w`. If the SETGUID approach, despite the games age is better, i'll rework this. Though sys-admin (or the first user) can simply change the permissions, or group to restrict the access.

Sent with [ProtonMail](https://protonmail.com) Secure Email.
Attachment: file
From 17085e907738f1d92879e05e482a375821ac50c4 Mon Sep 17 00:00:00 2001
From: Vitaliy Shatrov <D0dyBo0D0dyBo0@protonmail.com>
Date: Fri, 24 Apr 2020 20:18:31 +0700
Subject: [PATCH] gnu: Add bsd-games.

* gnu/packages/games.scm (bsd-games): a new variable.

New patches, taken from Arch and Debian:
* gnu/packages/patches/bsd-games-2.17-64bit.patch
* gnu/packages/patches/bsd-games-bad-ntohl-cast.patch
* gnu/packages/patches/bsd-games-fix-number-test.patch
* gnu/packages/patches/bsd-games-gamescreen.h.patch
* gnu/packages/patches/bsd-games-getline.patch
* gnu/packages/patches/bsd-games-null-check.patch
* gnu/packages/patches/bsd-games-number.c.patch
* gnu/packages/patches/bsd-games-stdio.h.patch

New patches:
* gnu/packages/patches/bsd-games-add-configure-config.patch
* gnu/packages/patches/bsd-games-add-word-list.patch
* gnu/packages/patches/bsd-games-add-wrapper.patch
* gnu/packages/patches/bsd-games-dont-install-empty-files.patch
* gnu/packages/patches/bsd-games-use-anthology-style-naming.patch
gnu/packages/games.scm | 136 +
.../patches/bsd-games-2.17-64bit.patch | 43 +
.../bsd-games-add-configure-config.patch | 17 +
.../patches/bsd-games-add-word-list.patch | 77659 ++++++++++++++++
.../patches/bsd-games-add-wrapper.patch | 217 +
.../patches/bsd-games-bad-ntohl-cast.patch | 22 +
.../bsd-games-dont-install-empty-files.patch | 87 +
.../patches/bsd-games-fix-number-test.patch | 32 +
.../patches/bsd-games-gamescreen.h.patch | 15 +
gnu/packages/patches/bsd-games-getline.patch | 194 +
.../patches/bsd-games-null-check.patch | 24 +
gnu/packages/patches/bsd-games-number.c.patch | 156 +
gnu/packages/patches/bsd-games-stdio.h.patch | 14 +
...bsd-games-use-anthology-style-naming.patch | 641 +
14 files changed, 79257 insertions(+)
create mode 100644 gnu/packages/patches/bsd-games-2.17-64bit.patch
create mode 100644 gnu/packages/patches/bsd-games-add-configure-config.patch
create mode 100644 gnu/packages/patches/bsd-games-add-word-list.patch
create mode 100644 gnu/packages/patches/bsd-games-add-wrapper.patch
create mode 100644 gnu/packages/patches/bsd-games-bad-ntohl-cast.patch
create mode 100644 gnu/packages/patches/bsd-games-dont-install-empty-files.patch
create mode 100644 gnu/packages/patches/bsd-games-fix-number-test.patch
create mode 100644 gnu/packages/patches/bsd-games-gamescreen.h.patch
create mode 100644 gnu/packages/patches/bsd-games-getline.patch
create mode 100644 gnu/packages/patches/bsd-games-null-check.patch
create mode 100644 gnu/packages/patches/bsd-games-number.c.patch
create mode 100644 gnu/packages/patches/bsd-games-stdio.h.patch
create mode 100644 gnu/packages/patches/bsd-games-use-anthology-style-naming.patch

Toggle diff (79348 lines)
diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm
index 10b3a072b9..e4e4981f1a 100644
--- a/gnu/packages/games.scm
+++ b/gnu/packages/games.scm
@@ -447,6 +447,142 @@ possible, while battling many vicious aliens.")
+(define-public bsd-games
+  (package
+    (name "bsd-games")
+    (version "2.17.0")
+    (source
+     (origin
+       (method url-fetch)
+       (uri "https://ibiblio.org/pub/linux/games/bsd-games-2.17.tar.gz")
+       (sha256
+        (base32
+         "0q7zdyyfvn15y0w4g54kq3gza89h61py727m8slmw73cxx594vq6"))
+       (patches
+        (search-patches
+         ;; thanks Arch, and Debian
+         "bsd-games-2.17-64bit.patch"
+         "bsd-games-bad-ntohl-cast.patch"
+         "bsd-games-gamescreen.h.patch"
+         "bsd-games-getline.patch"
+         "bsd-games-null-check.patch"
+         "bsd-games-number.c.patch"
+         "bsd-games-stdio.h.patch"
+         "bsd-games-fix-number-test.patch"
+         ;; Guix customizations
+         "bsd-games-add-word-list.patch"
+         "bsd-games-add-configure-config.patch"
+         "bsd-games-dont-install-empty-files.patch"
+         "bsd-games-add-wrapper.patch"
+         "bsd-games-use-anthology-style-naming.patch"))))
+    (build-system gnu-build-system)
+    (native-inputs
+     `(("flex" ,flex)
+       ("bison" ,bison)))
+    (inputs
+     `(("curses" ,ncurses)
+       ("pager" ,less)
+       ("openssl" ,openssl)))  ;used only by 'factor'
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (replace 'configure
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (bin (string-append out "/bin"))
+                    (doc (string-append out "/share/doc/bsd-games-" ,version))
+                    (man (string-append out "/share/man"))
+                    (static-data (string-append out "/share/games/bsd-games"))
+                    (save-files "/var/tmp/bsd-games"))
+               (substitute* "configure"
+                 (("/usr/share/man") man)
+                 (("/usr/share/doc/bsd-games") doc)
+                 (("/usr/share/[^\n/]*") static-data)
+                 (("/var/games") save-files)
+                 (("/usr/bin/less") (which "less"))
+                 (("(/usr/bin|/usr/games)") bin))
+               ;; Make our wrapper-script work.
+               (substitute* "wrapper"
+                 (("STATIC_DATA") static-data)
+                 (("SAVE_FILES") save-files))
+               ;; For both boggle and hangman.
+               (install-file "words" static-data)
+               (invoke "./configure"))
+             #t))
+         (add-before 'install 'patch-install
+           ;;; Some games need a writable directory containing pre-maded files.
+           ;;; The files get installed to the Store.  The wrapper do the rest.
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (static-data (string-append out "/share/games/bsd-games"))
+                    (save-files "/var/tmp/bsd-games"))
+               ;; We can't install to /var.
+               (substitute* "Makeconfig" ((save-files) static-data)))
+             #t))
+         (add-after 'install 'install-documents
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (doc (string-append out "/share/doc/bsd-games-" ,version)))
+               (rename-file "fortune/Notes" "fortune-Notes")
+               (rename-file "fortune/README" "fortune-README")
+               (rename-file "phantasia/COPYRIGHT" "phantasia-COPYRIGHT")
+               (for-each
+                (lambda(file) (install-file file doc))
+                '("AUTHORS" "BUGS" "README" "SECURITY" "THANKS"
+                  "fortune-Notes" "fortune-README" "phantasia-COPYRIGHT")))
+             #t)))))
+    (home-page "https://github.com/vattam/BSDGames")
+    (synopsis "Collection of the old text-based games and amusements")
+    (description
+     "The BSD-games:
+Action: atc (keep the airplanes safe), hack (explore the dangerous Dungeon),
+hunt (kill the others for the Pair of Boots, multi-player only), robots (avoid
+the evil robots), sail (game of naval warfare with wooden ships), snake (steal
+the $$ from the cave, anger the snake, and get out alive), tetris (game of
+lining up the falling bricks of different shapes), and worm (eat, grow big,
+and neither bite your tail, nor ram the wall).
+Amusements: banner (prints a large banner), bcd & morse & ppt (print a punch
+card, or paper tape, or Morse codes), caesar & rot13 (ciphers and deciphers
+the input), factor (factorizes a number), fortune (prints some random
+message), number (translates numbers into text), pig (translates from English
+to Pig Latin), pom (should print the Moon's phase), primes (generates primes),
+rain & worms (plays an screen-saver in terminal), random (prints randomly
+choosen lines from files, or returns a random exit-code), and wtf (explains
+what do some acronyms mean).
+Board: backgammon (lead the men out of board faster than the friend do),
+boggle (find the words in the square of letters), dab (game of dots and
+boxes), gomoku (game of five in a row), hangman (guess a word before man is
+hanged), and monop (game of monopoly, hot-seat only).  Also the card-games:
+canfield, cribbage, fish (juniors game), and mille.
+Quests: adventure (search for treasures with the help of wizard),
+battlestar (explore the world around, starting from dying spaceship),
+phantasia (role-play as an rogue), trek (hunt the Klingons, and save the
+Federation), and wump (hunt the big smelly Wumpus in a dark cave).
+Quizes: arithmetic, and quiz.")
+    ;; "Auxiliary and data files, distributed with the games in NetBSD, but
+    ;; not bearing copyright notices, probably fall under the terms of the UCB
+    ;; or NetBSD copyrights and licences.  The file "fortune/Notes" contains a
+    ;; warning in regard to the fortune databases."
+    (license (list
+              ;; Most games.  Files: countmail/countmail.6, dab/dab.6,
+              ;; lib/strlcpy.c, wargames/wargames.6
+              license:bsd-3
+              ;; dab and hunt.  Files: adventure/extern.h,
+              ;; backgammon/backgammon/backlocal.h, caesar/rot13.in,
+              ;; countmail/countmail, dm/utmpentry.c, dm/utmpentry.h,
+              ;; hack/extern.h, robots/auto.c, sail/display.h,
+              ;; sail/restart.h, wargames/wargames
+              license:bsd-4
+              ;; wtf
+              license:public-domain
+              ;; phantasia (all but phantasia/pathnames.h.in, which is bsd-3)
+              (license:fsf-free "file:///phantasia/COPYRIGHT")))))
 (define-public cataclysm-dda
     (name "cataclysm-dda")
diff --git a/gnu/packages/patches/bsd-games-2.17-64bit.patch b/gnu/packages/patches/bsd-games-2.17-64bit.patch
new file mode 100644
index 0000000000..a56ea8454b
--- /dev/null
+++ b/gnu/packages/patches/bsd-games-2.17-64bit.patch
@@ -0,0 +1,43 @@
+David Leverton writes about adventure/crc.c:
+The 'adventure' game from the games-misc/bsd-games-2.13 package crashes 
+when saving the game on AMD64 (and probably other 64-bit systems, but I 
+haven't checked).  Find attached to fix this.
+About utmpentry.c:
+the utmpx structure defines the ut_tv member a little differently on 
+64bit hosts so that a 32bit and 64bit structure can be shared.  So the 
+ut_tv is a custom 32bit structure rather than the native 64bit timeval 
+structure.  Work around is to assign the submembers instead.
+--- bsd-games/adventure/crc.c
++++ bsd-games/adventure/crc.c
+@@ -134,7 +134,8 @@
+ 				if (step >= sizeof(crctab) / sizeof(crctab[0]))
+ 					step = 0;
+ 			}
+-			crcval = (crcval << 8) ^ crctab[i];
++			/* Mask to 32 bits. */
++			crcval = ((crcval << 8) ^ crctab[i]) & 0xffffffff;
+ 		}
+-	return crcval & 0xffffffff;	/* Mask to 32 bits. */
++	return crcval;
+ }
+--- bsd-games/dm/utmpentry.c
++++ bsd-games/dm/utmpentry.c
+@@ -291,7 +291,8 @@
+ 	e->line[sizeof(e->line) - 1] = '\0';
+ 	(void)strncpy(e->host, up->ut_host, sizeof(up->ut_host));
+ 	e->name[sizeof(e->host) - 1] = '\0';
+-	e->tv = up->ut_tv;
++	e->tv.tv_sec = up->ut_tv.tv_sec;
++	e->tv.tv_usec = up->ut_tv.tv_usec;
+ 	adjust_size(e);
+ }
+ #endif
diff --git a/gnu/packages/patches/bsd-games-add-configure-config.patch b/gnu/packages/patches/bsd-games-add-configure-config.patch
new file mode 100644
index 0000000000..d61deeae47
--- /dev/null
+++ b/gnu/packages/patches/bsd-games-add-configure-config.patch
@@ -0,0 +1,17 @@
+Remove a few 'setenv's from the definition.
+diff -Naur bsd-games-2.17/config.params bsd-games-patch/config.params
+--- bsd-games-2.17/config.params	1970-01-01 07:00:00.000000000 +0700
++++ bsd-games-patch/config.params	2020-04-22 20:49:40.809695248 +0700
+@@ -0,0 +1,11 @@
++# The offensive fortunes shown only if requested by user.
++# Fix some man-pages: cfscores, morse, ppt, rot13, snscore, teachgammon.
++# Don't build dm, countmail, and wargames.
++# Wargames isn't convenient as a game launcher.
++# dm is a toy to restrict access to bsd-games.
++# countmail require some BSD-package called `from`.
++bsd_games_cfg_no_build_dirs="wargames dm countmail"
diff --git a/gnu/packages/patches/bsd-games-add-word-list.patch b/gnu/packages/patches/bsd-games-add-word-list.patch
new file mode 100644
index 0000000000..67d8616867
--- /dev/null
+++ b/gnu/packages/patches/bsd-games-add-word-list.patch
@@ -0,0 +1,77659 @@
+This adds a word-list needed by two games, boggle and hangman.
+The list should be an "lower-case ASCII" file, with one word a line.
+The file 'american-english' was taken from Arch Linux package 'words'.
+The list was produced with `cat american-english |grep -vE '[^a-z]' > words`.
+diff -Naur bsd-games-2.17/words bsd-games-patch/words
+--- bsd-games-2.17/words	1970-01-01 07:00:00.000000000 +0700
++++ bsd-games-patch/words	2020-04-18 00:58:13.312572569 +0700
+@@ -0,0 +1,77649 @@