2003-12-30 22:32:15 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2004-01-03 22:50:40 +01:00
|
|
|
# Original by joshk@triplehelix.org, modifications by jilles@stack.nl
|
|
|
|
|
|
|
|
# settings
|
|
|
|
# path for chroot
|
|
|
|
chroot_path="/var/lib/dgamelaunch"
|
|
|
|
# uid/gid, must agree with dgamelaunch.h
|
|
|
|
shed_uid=5
|
|
|
|
shed_gid=60
|
|
|
|
# extra libraries to copy (that ldd doesn't find, such as ld-elf.so.1 on
|
|
|
|
# FreeBSD)
|
|
|
|
libs=""
|
|
|
|
# compression binary to copy (found in $PATH if unqualified)
|
|
|
|
# (leave blank to skip)
|
|
|
|
compress_bin="gzip"
|
|
|
|
# nethack binary to copy (leave blank to skip)
|
|
|
|
nethack_bin="/usr/lib/games/nethack/nethack-console"
|
|
|
|
# fixed data to copy (leave blank to skip)
|
|
|
|
playground_fixed="/usr/lib/games/nethack"
|
|
|
|
# variable data to create (leave blank to skip) (may be equal to previous)
|
|
|
|
playground_var="/var/games/nethack"
|
|
|
|
# termcap/terminfo (copied recursively) (leave blank to skip)
|
|
|
|
termdata="/usr/share/terminfo"
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2004-01-03 22:50:40 +01:00
|
|
|
[ -f dgl-create-chroot.conf ] && . dgl-create-chroot.conf
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2004-01-03 22:50:40 +01:00
|
|
|
findlibs()
|
|
|
|
{
|
|
|
|
for i in "$@"; do
|
|
|
|
# () to ignore errors
|
|
|
|
( ldd "$i" 2>/dev/null | awk '{ if ($2=="=>") print $3; }' )
|
|
|
|
done
|
|
|
|
}
|
|
|
|
findinpath()
|
|
|
|
{
|
|
|
|
local IFS
|
|
|
|
IFS=:
|
|
|
|
for dir in $PATH; do
|
|
|
|
if [ -f "$dir/$1" ]; then
|
|
|
|
echo "$dir/$1"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2004-01-03 22:50:40 +01:00
|
|
|
set -e
|
|
|
|
umask 022
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2004-01-03 22:50:40 +01:00
|
|
|
echo "Setting up the chroot in: $chroot_path"
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2004-01-03 22:50:40 +01:00
|
|
|
mkdir -p $chroot_path/bin $chroot_path/etc $chroot_path/var/mail
|
2003-12-30 22:32:15 +01:00
|
|
|
|
|
|
|
# Passwd file
|
2004-01-03 22:50:40 +01:00
|
|
|
echo "games:*:$shed_uid:$shed_gid:games:/nonexistent:" >$chroot_path/etc/passwd
|
|
|
|
echo "games:*:$shed_gid:" >$chroot_path/etc/group
|
2003-12-30 22:32:15 +01:00
|
|
|
|
|
|
|
# Dungeon directory setup
|
2004-01-03 22:50:40 +01:00
|
|
|
mkdir -p $chroot_path/dgldir/inprogress
|
|
|
|
mkdir -p $chroot_path/dgldir/rcfiles
|
|
|
|
mkdir -p $chroot_path/dgldir/ttyrec
|
|
|
|
chown -R $shed_uid:$shed_gid $chroot_path/dgldir
|
|
|
|
chown -R $shed_uid:$shed_gid $chroot_path/var/mail
|
|
|
|
touch $chroot_path/dgl-login
|
|
|
|
touch $chroot_path/dgl-lock
|
2003-12-31 21:21:00 +01:00
|
|
|
|
|
|
|
# Might want to remove these two for packaging?
|
2004-01-03 22:50:40 +01:00
|
|
|
cp dgl-default-rcfile $chroot_path
|
|
|
|
cp dgl-banner $chroot_path
|
2003-12-31 21:21:00 +01:00
|
|
|
|
2004-01-03 22:50:40 +01:00
|
|
|
chown $shed_uid:$shed_gid $chroot_path/dgl-*
|
2003-12-30 22:32:15 +01:00
|
|
|
|
|
|
|
# Needs gzip to compress
|
2004-01-03 22:50:40 +01:00
|
|
|
if [ -n "$compress_bin" ]; then
|
|
|
|
case "$compress_bin" in
|
|
|
|
/*) : ;;
|
|
|
|
*) compress_bin=`findinpath $compress_bin` ;;
|
|
|
|
esac
|
|
|
|
# NetHack wants the compression binary in the exact directory
|
|
|
|
mkdir -p $chroot_path`dirname $compress_bin`
|
|
|
|
cp $compress_bin $chroot_path$compress_bin
|
|
|
|
libs="$libs `findlibs $compress_bin`"
|
|
|
|
fi
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2004-01-03 22:50:40 +01:00
|
|
|
# Copy the nethack binary over
|
|
|
|
if [ -n "$nethack_bin" ]; then
|
|
|
|
cp $nethack_bin $chroot_path/bin/nethack
|
|
|
|
libs="$libs `findlibs $nethack_bin`"
|
|
|
|
fi
|
2003-12-30 22:32:15 +01:00
|
|
|
|
|
|
|
# ...and all the data it needs
|
2004-01-03 22:50:40 +01:00
|
|
|
if [ -n "$playground_var" ]; then
|
|
|
|
mkdir -p $chroot_path$playground_var/save
|
|
|
|
touch $chroot_path$playground_var/record
|
|
|
|
touch $chroot_path$playground_var/perm
|
|
|
|
touch $chroot_path$playground_var/logfile
|
|
|
|
chown -R $shed_uid:$shed_gid $chroot_path$playground_var
|
|
|
|
fi
|
2003-12-30 22:32:15 +01:00
|
|
|
|
2004-01-03 22:50:40 +01:00
|
|
|
if [ -n "$playground_fixed" ]; then
|
|
|
|
mkdir -p $chroot_path$playground_fixed
|
|
|
|
cp $playground_fixed/license $chroot_path$playground_fixed
|
|
|
|
if [ -e $playground_fixed/nhdat ]; then
|
|
|
|
cp $playground_fixed/nhdat $chroot_path$playground_fixed
|
|
|
|
else
|
|
|
|
(
|
|
|
|
cd $playground_fixed
|
|
|
|
cp *.dat cmdhelp data dungeon help hh history \
|
|
|
|
opthelp options perm recover rumors wizhelp \
|
|
|
|
$chroot_path$playground_fixed
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
fi
|
2003-12-30 22:32:15 +01:00
|
|
|
|
|
|
|
# Curses junk
|
2004-01-03 22:50:40 +01:00
|
|
|
if [ -n "$termdata" ]; then
|
|
|
|
mkdir -p $chroot_path`dirname $termdata`
|
|
|
|
cp -RL $termdata $chroot_path`dirname $termdata`
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Necessary libraries
|
|
|
|
# previously libs="/lib/libc.so.6 /lib/libncurses.so.5 /lib/ld-linux.so.2"
|
|
|
|
libs=`for lib in $libs; do echo $lib; done | sort | uniq`
|
|
|
|
echo "Copying libraries:" $libs
|
|
|
|
for lib in $libs; do
|
|
|
|
mkdir -p $chroot_path`dirname $lib`
|
|
|
|
cp $lib $chroot_path$lib
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Finished."
|