#!/bin/sh # Ideas and some parts from the original dgl-create-chroot (by joshk@triplehelix.org, modifications by jilles@stack.nl) # This one by paxed@alt.org # # configure dgl with --with-config-file=/path_to_chroot/etc/dgamelaunch.conf, if you want the conf file inside the chroot. # # Same as chroot_path in dgl config file CHROOT="/opt/nethack/nethack.alt.org/" # the user & group from dgamelaunch config file. USRGRP="games:games" # COMPRESS from include/config.h; the compression binary to copy. leave blank to skip. COMPRESSBIN="/bin/gzip" # nethack binary to copy into chroot NETHACKBIN="/home/paxed/hacking/coding/nethacksource/nethack-3.4.3-nao/nh343/nethack.343-nao" # fixed data to copy (leave blank to skip) NH_PLAYGROUND_FIXED="/home/paxed/hacking/coding/nethacksource/nethack-3.4.3-nao/nh343/" # HACKDIR from include/config.h; aka nethack subdir inside chroot NHSUBDIR="/nh343/" # VAR_PLAYGROUND from include/unixconf.h NH_VAR_PLAYGROUND="/nh343/var/" # only define this if dgl was configured with --enable-sqlite SQLITE_DBFILE="/dgldir/dgamelaunch.db" # END OF CONFIG ############################################################################## errorexit() { echo "Error: $@" >&2 exit 1 } findlibs() { for i in "$@"; do if [ -z "`ldd "$i" | grep 'not a dynamic executable'`" ]; then echo $(ldd "$i" | awk '{ print $3 }' | egrep -v ^'\(') echo $(ldd "$i" | grep 'ld-linux' | awk '{ print $1 }') fi done } ############################################################################## if [ -z "$TERMDATA" ]; then SEARCHTERMDATA="/etc/terminfo /usr/share/lib/terminfo /usr/share/terminfo /lib/terminfo" for dir in $SEARCHTERMDATA; do if [ -e "$dir/x/xterm" ]; then TERMDATA="$TERMDATA $dir" fi done if [ -z "$TERMDATA" ]; then errorexit "Couldn't find terminfo definitions. Please specify in 'TERMDATA' variable." fi fi # remove trailing slash, if any CHROOT="`echo ${CHROOT%/}`" set -e umask 022 if [ -e "$CHROOT" ]; then errorexit "Chroot $CHROOT already exists." fi CURDIR="`pwd`" if [ ! -e "$CURDIR/dgamelaunch" ]; then errorexit "Cannot find dgamelaunch in $CURDIR" fi DGLFILE="dgamelaunch.`date +%Y%m%d`" echo "Setting up chroot in $CHROOT" LIBS="`findlibs dgamelaunch`" sudo mkdir -p "$CHROOT" cd "$CHROOT" sudo mkdir dgldir etc lib mail usr sudo chown "$USRGRP" dgldir mail sudo cp "$CURDIR/dgamelaunch" "$DGLFILE" sudo ln -s "$DGLFILE" dgamelaunch sudo mkdir -p "$CHROOT/dgldir/inprogress-nh343" sudo mkdir -p "$CHROOT/dgldir/userdata" sudo chown "$USRGRP" "$CHROOT/dgldir/inprogress-nh343" sudo chown "$USRGRP" "$CHROOT/dgldir/userdata" if [ -n "$SQLITE_DBFILE" ]; then echo "Creating SQLite database at $SQLITE_DBFILE" SQLITE_DBFILE="`echo ${SQLITE_DBFILE%/}`" SQLITE_DBFILE="`echo ${SQLITE_DBFILE#/}`" sudo sqlite3 "$CHROOT/$SQLITE_DBFILE" "create table dglusers (id integer primary key, username text, email text, env text, password text, flags integer);" sudo chown "$USRGRP" "$CHROOT/$SQLITE_DBFILE" fi if [ -n "$COMPRESSBIN" -a -e "`which $COMPRESSBIN`" ]; then COMPRESSDIR="`dirname $COMPRESSBIN`" COMPRESSDIR="`echo ${COMPRESSDIR%/}`" COMPRESSDIR="`echo ${COMPRESSDIR#/}`" echo "Copying $COMPRESSBIN to $COMPRESSDIR" sudo mkdir -p "$COMPRESSDIR" sudo cp "`which $COMPRESSBIN`" "$COMPRESSDIR/" LIBS="$LIBS `findlibs $COMPRESSBIN`" fi sudo mkdir -p dev cd dev sudo mknod urandom c 1 9 cd .. cd etc sudo cp "$CURDIR/examples/dgamelaunch.conf" . echo "Edit $CHROOT/etc/dgamelaunch.conf to suit your needs." [ -f /etc/localtime ] && sudo cp /etc/localtime . cd .. sudo cp "$CURDIR/examples/dgl_menu_main_anon.txt" . sudo cp "$CURDIR/examples/dgl_menu_main_user.txt" . sudo cp "$CURDIR/examples/dgl_menu_watchmenu_help.txt" . sudo cp "$CURDIR/examples/dgl-banner" . sudo cp "$CURDIR/dgl-default-rcfile" "dgl-default-rcfile.nh343" sudo chmod go+r dgl_menu_main_anon.txt dgl_menu_main_user.txt dgl-banner dgl-default-rcfile.nh343 NHSUBDIR="`echo ${NHSUBDIR%/}`" NHSUBDIR="`echo ${NHSUBDIR#/}`" sudo mkdir "$CHROOT/$NHSUBDIR" if [ ! -e "$NETHACKBIN" ]; then errorexit "Cannot find NetHack binary $NETHACKBIN" fi if [ -n "$NETHACKBIN" -a -e "$NETHACKBIN" ]; then echo "Copying $NETHACKBIN" cd "$NHSUBDIR" NHBINFILE="`basename $NETHACKBIN`.`date +%Y%m%d`" sudo cp "$NETHACKBIN" "$NHBINFILE" sudo ln -s "$NHBINFILE" nethack LIBS="$LIBS `findlibs $NETHACKBIN`" cd "$CHROOT" fi NH_PLAYGROUND_FIXED="`echo ${NH_PLAYGROUND_FIXED%/}`" if [ -n "$NH_PLAYGROUND_FIXED" -a -d "$NH_PLAYGROUND_FIXED" ]; then echo "Copying NetHack playground stuff." NHFILES="*.lev *.dat cmdhelp data dungeon help hh history license opthelp options oracles recover rumors wizhelp" for fil in $NHFILES; do sudo cp $NH_PLAYGROUND_FIXED/$fil "$CHROOT/$NHSUBDIR/" done fi NH_VAR_PLAYGROUND="`echo ${NH_VAR_PLAYGROUND%/}`" NH_VAR_PLAYGROUND="`echo ${NH_VAR_PLAYGROUND#/}`" echo "Creating NetHack variable dir stuff." if [ -n "$NH_VAR_PLAYGROUND" ]; then sudo mkdir -p "$CHROOT/$NH_VAR_PLAYGROUND" sudo chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND" fi sudo mkdir -p "$CHROOT/$NH_VAR_PLAYGROUND/save" sudo chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND/save" sudo touch "$CHROOT/$NH_VAR_PLAYGROUND/logfile" sudo touch "$CHROOT/$NH_VAR_PLAYGROUND/perm" sudo touch "$CHROOT/$NH_VAR_PLAYGROUND/record" sudo touch "$CHROOT/$NH_VAR_PLAYGROUND/xlogfile" sudo chown -R "$USRGRP" "$CHROOT/$NHSUBDIR" sudo chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND" # Curses junk if [ -n "$TERMDATA" ]; then echo "Copying termdata files from $TERMDATA" for termdat in $TERMDATA; do sudo mkdir -p "$CHROOT`dirname $termdat`" if [ -d $termdat/. ]; then sudo cp -LR $termdat/. $CHROOT$termdat else sudo cp $termdat $CHROOT`dirname $termdat` fi done fi LIBS=`for lib in $LIBS; do echo $lib; done | sort | uniq` echo "Copying libraries:" $LIBS for lib in $LIBS; do sudo mkdir -p "$CHROOT`dirname $lib`" sudo cp $lib "$CHROOT$lib" done echo "Finished."