2003-12-30 22:32:15 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2009-10-17 19:34:36 +02:00
|
|
|
# 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"
|
2004-01-03 22:50:40 +01:00
|
|
|
# fixed data to copy (leave blank to skip)
|
2009-10-17 19:34:36 +02:00
|
|
|
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/"
|
2006-07-09 09:04:09 +02:00
|
|
|
|
2009-10-17 19:34:36 +02:00
|
|
|
# only define this if dgl was configured with --enable-sqlite
|
|
|
|
SQLITE_DBFILE="/dgldir/dgamelaunch.db"
|
|
|
|
|
|
|
|
# END OF CONFIG
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
errorexit()
|
2004-01-03 22:50:40 +01:00
|
|
|
{
|
2009-10-17 19:34:36 +02:00
|
|
|
echo "Error: $@" >&2
|
|
|
|
exit 1
|
2004-01-03 22:50:40 +01:00
|
|
|
}
|
2009-10-17 19:34:36 +02:00
|
|
|
|
|
|
|
findlibs()
|
2004-01-03 22:50:40 +01:00
|
|
|
{
|
2009-10-17 19:34:36 +02:00
|
|
|
for i in "$@"; do
|
2010-03-13 20:08:31 +01:00
|
|
|
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
|
2009-10-17 19:34:36 +02:00
|
|
|
done
|
2004-01-03 22:50:40 +01:00
|
|
|
}
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2009-10-17 19:34:36 +02:00
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
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%/}`"
|
|
|
|
|
2004-01-03 22:50:40 +01:00
|
|
|
set -e
|
|
|
|
umask 022
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2009-10-17 19:34:36 +02:00
|
|
|
if [ -e "$CHROOT" ]; then
|
|
|
|
errorexit "Chroot $CHROOT already exists."
|
2004-01-03 22:50:40 +01:00
|
|
|
fi
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2009-10-17 19:34:36 +02:00
|
|
|
CURDIR="`pwd`"
|
|
|
|
|
|
|
|
if [ ! -e "$CURDIR/dgamelaunch" ]; then
|
|
|
|
errorexit "Cannot find dgamelaunch in $CURDIR"
|
2004-01-03 22:50:40 +01:00
|
|
|
fi
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2009-10-17 19:34:36 +02:00
|
|
|
DGLFILE="dgamelaunch.`date +%Y%m%d`"
|
|
|
|
|
|
|
|
echo "Setting up chroot in $CHROOT"
|
|
|
|
|
|
|
|
LIBS="`findlibs dgamelaunch`"
|
|
|
|
|
2011-01-14 22:08:44 +01:00
|
|
|
mkdir -p "$CHROOT" || errorexit "Cannot create chroot"
|
2009-10-17 19:34:36 +02:00
|
|
|
cd "$CHROOT"
|
2011-01-14 22:08:44 +01:00
|
|
|
mkdir dgldir etc lib mail usr bin
|
|
|
|
chown "$USRGRP" dgldir mail
|
|
|
|
cp "$CURDIR/dgamelaunch" "$DGLFILE"
|
|
|
|
ln -s "$DGLFILE" dgamelaunch
|
2009-10-17 19:34:36 +02:00
|
|
|
|
2011-01-14 22:08:44 +01:00
|
|
|
mkdir -p "$CHROOT/dgldir/inprogress-nh343"
|
|
|
|
mkdir -p "$CHROOT/dgldir/userdata"
|
|
|
|
chown "$USRGRP" "$CHROOT/dgldir/inprogress-nh343"
|
|
|
|
chown "$USRGRP" "$CHROOT/dgldir/userdata"
|
2009-10-17 19:34:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
if [ -n "$SQLITE_DBFILE" ]; then
|
|
|
|
echo "Creating SQLite database at $SQLITE_DBFILE"
|
|
|
|
SQLITE_DBFILE="`echo ${SQLITE_DBFILE%/}`"
|
|
|
|
SQLITE_DBFILE="`echo ${SQLITE_DBFILE#/}`"
|
2011-01-14 22:08:44 +01:00
|
|
|
sqlite3 "$CHROOT/$SQLITE_DBFILE" "create table dglusers (id integer primary key, username text, email text, env text, password text, flags integer);"
|
|
|
|
chown "$USRGRP" "$CHROOT/$SQLITE_DBFILE"
|
2004-01-03 22:50:40 +01:00
|
|
|
fi
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2009-10-17 19:34:36 +02:00
|
|
|
|
|
|
|
if [ -n "$COMPRESSBIN" -a -e "`which $COMPRESSBIN`" ]; then
|
|
|
|
COMPRESSDIR="`dirname $COMPRESSBIN`"
|
|
|
|
COMPRESSDIR="`echo ${COMPRESSDIR%/}`"
|
|
|
|
COMPRESSDIR="`echo ${COMPRESSDIR#/}`"
|
|
|
|
echo "Copying $COMPRESSBIN to $COMPRESSDIR"
|
2011-01-14 22:08:44 +01:00
|
|
|
mkdir -p "$COMPRESSDIR"
|
|
|
|
cp "`which $COMPRESSBIN`" "$COMPRESSDIR/"
|
2009-10-17 19:34:36 +02:00
|
|
|
LIBS="$LIBS `findlibs $COMPRESSBIN`"
|
2004-01-03 22:50:40 +01:00
|
|
|
fi
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2009-10-17 19:34:36 +02:00
|
|
|
|
2011-01-14 22:08:44 +01:00
|
|
|
mkdir -p dev
|
2009-10-17 19:34:36 +02:00
|
|
|
cd dev
|
2011-01-14 22:08:44 +01:00
|
|
|
mknod urandom c 1 9
|
2009-10-17 19:34:36 +02:00
|
|
|
cd ..
|
|
|
|
|
|
|
|
|
|
|
|
cd etc
|
2011-01-14 22:08:44 +01:00
|
|
|
cp "$CURDIR/examples/dgamelaunch.conf" .
|
2009-10-17 19:34:36 +02:00
|
|
|
echo "Edit $CHROOT/etc/dgamelaunch.conf to suit your needs."
|
2011-01-14 22:08:44 +01:00
|
|
|
[ -f /etc/localtime ] && cp /etc/localtime .
|
2009-10-17 19:34:36 +02:00
|
|
|
cd ..
|
|
|
|
|
|
|
|
|
2010-05-18 22:39:32 +02:00
|
|
|
cd bin
|
2011-01-14 22:08:44 +01:00
|
|
|
cp "$CURDIR/ee" .
|
|
|
|
cp "$CURDIR/virus" .
|
2010-05-18 22:39:32 +02:00
|
|
|
echo "Copied text editors 'ee' and 'virus' to chroot."
|
|
|
|
cd ..
|
|
|
|
|
2009-10-17 19:34:36 +02:00
|
|
|
|
2011-01-14 22:08:44 +01:00
|
|
|
cp "$CURDIR/examples/dgl_menu_main_anon.txt" .
|
|
|
|
cp "$CURDIR/examples/dgl_menu_main_user.txt" .
|
|
|
|
cp "$CURDIR/examples/dgl_menu_watchmenu_help.txt" .
|
|
|
|
cp "$CURDIR/examples/dgl-banner" .
|
|
|
|
cp "$CURDIR/dgl-default-rcfile" "dgl-default-rcfile.nh343"
|
|
|
|
chmod go+r dgl_menu_main_anon.txt dgl_menu_main_user.txt dgl-banner dgl-default-rcfile.nh343
|
2009-10-17 19:34:36 +02:00
|
|
|
|
|
|
|
NHSUBDIR="`echo ${NHSUBDIR%/}`"
|
|
|
|
NHSUBDIR="`echo ${NHSUBDIR#/}`"
|
|
|
|
|
2011-01-14 22:08:44 +01:00
|
|
|
mkdir "$CHROOT/$NHSUBDIR"
|
2009-10-17 19:34:36 +02:00
|
|
|
|
|
|
|
if [ ! -e "$NETHACKBIN" ]; then
|
|
|
|
errorexit "Cannot find NetHack binary $NETHACKBIN"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$NETHACKBIN" -a -e "$NETHACKBIN" ]; then
|
|
|
|
echo "Copying $NETHACKBIN"
|
2009-10-18 11:58:21 +02:00
|
|
|
cd "$NHSUBDIR"
|
|
|
|
NHBINFILE="`basename $NETHACKBIN`.`date +%Y%m%d`"
|
2011-01-14 22:08:44 +01:00
|
|
|
cp "$NETHACKBIN" "$NHBINFILE"
|
|
|
|
ln -s "$NHBINFILE" nethack
|
2009-10-17 19:34:36 +02:00
|
|
|
LIBS="$LIBS `findlibs $NETHACKBIN`"
|
2009-10-18 11:58:21 +02:00
|
|
|
cd "$CHROOT"
|
2009-10-17 19:34:36 +02:00
|
|
|
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
|
2011-01-14 22:08:44 +01:00
|
|
|
cp $NH_PLAYGROUND_FIXED/$fil "$CHROOT/$NHSUBDIR/"
|
2009-10-17 19:34:36 +02:00
|
|
|
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
|
2011-01-14 22:08:44 +01:00
|
|
|
mkdir -p "$CHROOT/$NH_VAR_PLAYGROUND"
|
|
|
|
chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND"
|
2009-10-17 19:34:36 +02:00
|
|
|
fi
|
2011-01-14 22:08:44 +01:00
|
|
|
mkdir -p "$CHROOT/$NH_VAR_PLAYGROUND/save"
|
|
|
|
chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND/save"
|
|
|
|
touch "$CHROOT/$NH_VAR_PLAYGROUND/logfile"
|
|
|
|
touch "$CHROOT/$NH_VAR_PLAYGROUND/perm"
|
|
|
|
touch "$CHROOT/$NH_VAR_PLAYGROUND/record"
|
|
|
|
touch "$CHROOT/$NH_VAR_PLAYGROUND/xlogfile"
|
2009-10-17 19:34:36 +02:00
|
|
|
|
2011-01-14 22:08:44 +01:00
|
|
|
chown -R "$USRGRP" "$CHROOT/$NHSUBDIR"
|
|
|
|
chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND"
|
2009-10-17 19:34:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2003-12-30 22:32:15 +01:00
|
|
|
# Curses junk
|
2009-10-17 19:34:36 +02:00
|
|
|
if [ -n "$TERMDATA" ]; then
|
|
|
|
echo "Copying termdata files from $TERMDATA"
|
|
|
|
for termdat in $TERMDATA; do
|
2011-01-14 22:08:44 +01:00
|
|
|
mkdir -p "$CHROOT`dirname $termdat`"
|
2009-10-17 19:34:36 +02:00
|
|
|
if [ -d $termdat/. ]; then
|
2011-01-14 22:08:44 +01:00
|
|
|
cp -LR $termdat/. $CHROOT$termdat
|
2004-01-16 17:36:33 +01:00
|
|
|
else
|
2011-01-14 22:08:44 +01:00
|
|
|
cp $termdat $CHROOT`dirname $termdat`
|
2004-01-16 17:36:33 +01:00
|
|
|
fi
|
2009-10-17 19:34:36 +02:00
|
|
|
done
|
2004-01-03 22:50:40 +01:00
|
|
|
fi
|
|
|
|
|
2009-10-17 19:34:36 +02:00
|
|
|
|
|
|
|
LIBS=`for lib in $LIBS; do echo $lib; done | sort | uniq`
|
|
|
|
echo "Copying libraries:" $LIBS
|
|
|
|
for lib in $LIBS; do
|
2011-01-14 22:08:44 +01:00
|
|
|
mkdir -p "$CHROOT`dirname $lib`"
|
|
|
|
cp $lib "$CHROOT$lib"
|
2004-01-03 22:50:40 +01:00
|
|
|
done
|
|
|
|
|
2009-10-17 19:34:36 +02:00
|
|
|
|
2004-01-03 22:50:40 +01:00
|
|
|
echo "Finished."
|
2009-10-17 19:34:36 +02:00
|
|
|
|
|
|
|
|