forked from paxed/dgamelaunch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dgl-create-chroot
executable file
·226 lines (171 loc) · 5.98 KB
/
dgl-create-chroot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/sh
# Ideas and some parts from the original dgl-create-chroot (by [email protected], modifications by [email protected])
# This one by [email protected]
#
# 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 (leave blank to skip)
#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`"
mkdir -p "$CHROOT" || errorexit "Cannot create chroot"
cd "$CHROOT"
mkdir dgldir etc lib mail usr bin
chown "$USRGRP" dgldir mail
cp "$CURDIR/dgamelaunch" "$DGLFILE"
ln -s "$DGLFILE" dgamelaunch
mkdir -p "$CHROOT/dgldir/inprogress-nh343"
mkdir -p "$CHROOT/dgldir/userdata"
chown "$USRGRP" "$CHROOT/dgldir/inprogress-nh343"
chown "$USRGRP" "$CHROOT/dgldir/userdata"
if [ -n "$SQLITE_DBFILE" ]; then
if [ "x`which sqlite3`" = "x" ]; then
errorexit "No sqlite3 found."
else
echo "Creating SQLite database at $SQLITE_DBFILE"
SQLITE_DBFILE="`echo ${SQLITE_DBFILE%/}`"
SQLITE_DBFILE="`echo ${SQLITE_DBFILE#/}`"
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"
fi
fi
if [ -n "$COMPRESSBIN" -a -e "`which $COMPRESSBIN`" ]; then
COMPRESSDIR="`dirname $COMPRESSBIN`"
COMPRESSDIR="`echo ${COMPRESSDIR%/}`"
COMPRESSDIR="`echo ${COMPRESSDIR#/}`"
echo "Copying $COMPRESSBIN to $COMPRESSDIR"
mkdir -p "$COMPRESSDIR"
cp "`which $COMPRESSBIN`" "$COMPRESSDIR/"
LIBS="$LIBS `findlibs $COMPRESSBIN`"
fi
mkdir -p dev
cd dev
mknod urandom c 1 9
cd ..
cd etc
cp "$CURDIR/examples/dgamelaunch.conf" .
echo "Edit $CHROOT/etc/dgamelaunch.conf to suit your needs."
[ -f /etc/localtime ] && cp /etc/localtime .
cd ..
cd bin
cp "$CURDIR/ee" .
cp "$CURDIR/virus" .
echo "Copied text editors 'ee' and 'virus' to chroot."
cd ..
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
NHSUBDIR="`echo ${NHSUBDIR%/}`"
NHSUBDIR="`echo ${NHSUBDIR#/}`"
mkdir "$CHROOT/$NHSUBDIR"
if [ -n "$NETHACKBIN" -a ! -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`"
cp "$NETHACKBIN" "$NHBINFILE"
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
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
mkdir -p "$CHROOT/$NH_VAR_PLAYGROUND"
chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND"
fi
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"
chown -R "$USRGRP" "$CHROOT/$NHSUBDIR"
chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND"
# Curses junk
if [ -n "$TERMDATA" ]; then
echo "Copying termdata files from $TERMDATA"
for termdat in $TERMDATA; do
mkdir -p "$CHROOT`dirname $termdat`"
if [ -d $termdat/. ]; then
cp -LR $termdat/. $CHROOT$termdat
else
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
mkdir -p "$CHROOT`dirname $lib`"
cp $lib "$CHROOT$lib"
done
echo "Finished."