Annotation of dgamelaunch-openbsd/dgl-create-chroot, Revision 1.8
1.1 rubenllo 1: #!/bin/sh
2:
3: # Ideas and some parts from the original dgl-create-chroot (by joshk@triplehelix.org, modifications by jilles@stack.nl)
1.8 ! rubenllo 4: # This one by paxed@alt.org, modified by porting@use.startmail.com
1.1 rubenllo 5:
6:
7: #
8: # configure dgl with --with-config-file=/path_to_chroot/etc/dgamelaunch.conf, if you want the conf file inside the chroot.
9: #
10:
11:
12: # Same as chroot_path in dgl config file
13: CHROOT="/opt/nethack/nethack.alt.org/"
14: # the user & group from dgamelaunch config file.
15: USRGRP="games:games"
16: # COMPRESS from include/config.h; the compression binary to copy. leave blank to skip.
1.4 rubenllo 17: COMPRESSBIN="/usr/bin/gzip"
1.1 rubenllo 18: # nethack binary to copy into chroot (leave blank to skip)
19: #NETHACKBIN="/home/paxed/hacking/coding/nethacksource/nethack-3.4.3-nao/nh343/nethack.343-nao"
20: # fixed data to copy (leave blank to skip)
21: #NH_PLAYGROUND_FIXED="/home/paxed/hacking/coding/nethacksource/nethack-3.4.3-nao/nh343/"
22: # HACKDIR from include/config.h; aka nethack subdir inside chroot
23: NHSUBDIR="/nh343/"
24: # VAR_PLAYGROUND from include/unixconf.h
25: NH_VAR_PLAYGROUND="/nh343/var/"
26:
27: # only define this if dgl was configured with --enable-sqlite
28: SQLITE_DBFILE="/dgldir/dgamelaunch.db"
29:
1.6 rubenllo 30: # only define this is dgl was configured without --enable-sqlite
31: #PASSWD_FILE="/dgldir/dgl-login"
32:
1.7 rubenllo 33: # only define this is dgl was configured without --enable-debugfile
34: #DEBUGFILE="/dgldebug.log"
35:
1.1 rubenllo 36: # END OF CONFIG
37: ##############################################################################
38:
39: errorexit()
40: {
41: echo "Error: $@" >&2
42: exit 1
43: }
44:
45: findlibs()
46: {
47: for i in "$@"; do
1.2 rubenllo 48: if [ -z "`ldd "$i" | grep 'not a'`" ]; then
49: if test $(uname -s) == OpenBSD; then
50: echo $(ldd "$i" | awk '{ print $7 }' | egrep -v ^'\(') | cut -d ' ' -f 3-
51: else
52: echo $(ldd "$i" | awk '{ print $3 }' | egrep -v ^'\(')
1.1 rubenllo 53: echo $(ldd "$i" | grep 'ld-linux' | awk '{ print $1 }')
1.2 rubenllo 54: fi
1.1 rubenllo 55: fi
56: done
57: }
58:
59: ##############################################################################
60:
61: if [ -z "$TERMDATA" ]; then
62: SEARCHTERMDATA="/etc/terminfo /usr/share/lib/terminfo /usr/share/terminfo /lib/terminfo"
63: for dir in $SEARCHTERMDATA; do
64: if [ -e "$dir/x/xterm" ]; then
65: TERMDATA="$TERMDATA $dir"
66: fi
67: done
68: if [ -z "$TERMDATA" ]; then
69: errorexit "Couldn't find terminfo definitions. Please specify in 'TERMDATA' variable."
70: fi
71: fi
72:
73:
74:
75: # remove trailing slash, if any
76: CHROOT="`echo ${CHROOT%/}`"
77:
78: set -e
79: umask 022
80:
81: if [ -e "$CHROOT" ]; then
82: errorexit "Chroot $CHROOT already exists."
83: fi
84:
85: CURDIR="`pwd`"
86:
1.4 rubenllo 87: if [ ! -e "$CURDIR/dgamelaunch-openbsd" ]; then
88: errorexit "Cannot find dgamelaunch-openbsd in $CURDIR"
1.1 rubenllo 89: fi
90:
91: DGLFILE="dgamelaunch.`date +%Y%m%d`"
92:
93: echo "Setting up chroot in $CHROOT"
94:
1.4 rubenllo 95: LIBS="`findlibs dgamelaunch-openbsd`"
1.1 rubenllo 96:
97: mkdir -p "$CHROOT" || errorexit "Cannot create chroot"
98: cd "$CHROOT"
99: mkdir dgldir etc lib mail usr bin
100: chown "$USRGRP" dgldir mail
1.4 rubenllo 101: cp "$CURDIR/dgamelaunch-openbsd" "$DGLFILE"
1.1 rubenllo 102: ln -s "$DGLFILE" dgamelaunch
103:
104: mkdir -p "$CHROOT/dgldir/inprogress-nh343"
105: mkdir -p "$CHROOT/dgldir/userdata"
106: chown "$USRGRP" "$CHROOT/dgldir/inprogress-nh343"
107: chown "$USRGRP" "$CHROOT/dgldir/userdata"
108:
109:
110: if [ -n "$SQLITE_DBFILE" ]; then
111: if [ "x`which sqlite3`" = "x" ]; then
112: errorexit "No sqlite3 found."
113: else
114: echo "Creating SQLite database at $SQLITE_DBFILE"
115: SQLITE_DBFILE="`echo ${SQLITE_DBFILE%/}`"
116: SQLITE_DBFILE="`echo ${SQLITE_DBFILE#/}`"
117: sqlite3 "$CHROOT/$SQLITE_DBFILE" "create table dglusers (id integer primary key, username text, email text, env text, password text, flags integer);"
118: chown "$USRGRP" "$CHROOT/$SQLITE_DBFILE"
1.5 rubenllo 119: chmod 0700 "$CHROOT/$SQLITE_DBFILE"
1.1 rubenllo 120: fi
121: fi
122:
1.6 rubenllo 123: if [ -n "PASSWD_FILE" ]; then
124: echo "Creating password file at $PASSWD_FILE"
125: touch "$CHROOT/$PASSWD_FILE"
1.7 rubenllo 126: chown "$USRGRP" "$CHROOT/$PASSWD_FILE"
1.6 rubenllo 127: chmod 0700 "$CHROOT/$PASSWD_FILE"
1.7 rubenllo 128: fi
129:
130: if [ -n "DEBUGFILE" ]; then
131: echo "Creating debugfile at $DEBUGFILE"
132: touch "$CHROOT/$DEBUGFILE"
133: chown "$USRGRP" "$CHROOT/$DEBUGFILE"
134: chmod 0700 "$CHROOT/$DEBUGFILE"
1.6 rubenllo 135: fi
1.1 rubenllo 136:
137: if [ -n "$COMPRESSBIN" -a -e "`which $COMPRESSBIN`" ]; then
138: COMPRESSDIR="`dirname $COMPRESSBIN`"
139: COMPRESSDIR="`echo ${COMPRESSDIR%/}`"
140: COMPRESSDIR="`echo ${COMPRESSDIR#/}`"
141: echo "Copying $COMPRESSBIN to $COMPRESSDIR"
142: mkdir -p "$COMPRESSDIR"
143: cp "`which $COMPRESSBIN`" "$COMPRESSDIR/"
144: LIBS="$LIBS `findlibs $COMPRESSBIN`"
145: fi
146:
147:
148: mkdir -p dev
149: cd dev
1.3 rubenllo 150: if test $(uname -s) == OpenBSD; then
151: mknod urandom c 45 0
152: else
153: mknod urandom c 1 9
154: fi
1.1 rubenllo 155: cd ..
156:
157:
158: cd etc
159: cp "$CURDIR/examples/dgamelaunch.conf" .
160: echo "Edit $CHROOT/etc/dgamelaunch.conf to suit your needs."
161: [ -f /etc/localtime ] && cp /etc/localtime .
162: cd ..
163:
164:
165: cd bin
166: cp "$CURDIR/ee" .
167: cp "$CURDIR/virus" .
168: echo "Copied text editors 'ee' and 'virus' to chroot."
169: cd ..
170:
171:
172: cp "$CURDIR/examples/dgl_menu_main_anon.txt" .
173: cp "$CURDIR/examples/dgl_menu_main_user.txt" .
174: cp "$CURDIR/examples/dgl_menu_watchmenu_help.txt" .
175: cp "$CURDIR/examples/dgl-banner" .
176: cp "$CURDIR/dgl-default-rcfile" "dgl-default-rcfile.nh343"
177: chmod go+r dgl_menu_main_anon.txt dgl_menu_main_user.txt dgl-banner dgl-default-rcfile.nh343
178:
179: NHSUBDIR="`echo ${NHSUBDIR%/}`"
180: NHSUBDIR="`echo ${NHSUBDIR#/}`"
181:
182: mkdir "$CHROOT/$NHSUBDIR"
183:
184: if [ -n "$NETHACKBIN" -a ! -e "$NETHACKBIN" ]; then
185: errorexit "Cannot find NetHack binary $NETHACKBIN"
186: fi
187:
188: if [ -n "$NETHACKBIN" -a -e "$NETHACKBIN" ]; then
189: echo "Copying $NETHACKBIN"
190: cd "$NHSUBDIR"
191: NHBINFILE="`basename $NETHACKBIN`.`date +%Y%m%d`"
192: cp "$NETHACKBIN" "$NHBINFILE"
193: ln -s "$NHBINFILE" nethack
194: LIBS="$LIBS `findlibs $NETHACKBIN`"
195: cd "$CHROOT"
196: fi
197:
198:
199: NH_PLAYGROUND_FIXED="`echo ${NH_PLAYGROUND_FIXED%/}`"
200:
201: if [ -n "$NH_PLAYGROUND_FIXED" -a -d "$NH_PLAYGROUND_FIXED" ]; then
202: echo "Copying NetHack playground stuff."
203: NHFILES="*.lev *.dat cmdhelp data dungeon help hh history license opthelp options oracles recover rumors wizhelp"
204: for fil in $NHFILES; do
205: cp $NH_PLAYGROUND_FIXED/$fil "$CHROOT/$NHSUBDIR/"
206: done
207: fi
208:
209:
210: NH_VAR_PLAYGROUND="`echo ${NH_VAR_PLAYGROUND%/}`"
211: NH_VAR_PLAYGROUND="`echo ${NH_VAR_PLAYGROUND#/}`"
212:
213: echo "Creating NetHack variable dir stuff."
214: if [ -n "$NH_VAR_PLAYGROUND" ]; then
215: mkdir -p "$CHROOT/$NH_VAR_PLAYGROUND"
216: chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND"
217: fi
218: mkdir -p "$CHROOT/$NH_VAR_PLAYGROUND/save"
219: chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND/save"
220: touch "$CHROOT/$NH_VAR_PLAYGROUND/logfile"
221: touch "$CHROOT/$NH_VAR_PLAYGROUND/perm"
222: touch "$CHROOT/$NH_VAR_PLAYGROUND/record"
223: touch "$CHROOT/$NH_VAR_PLAYGROUND/xlogfile"
224:
225: chown -R "$USRGRP" "$CHROOT/$NHSUBDIR"
226: chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND"
227:
228:
229:
230: # Curses junk
231: if [ -n "$TERMDATA" ]; then
232: echo "Copying termdata files from $TERMDATA"
233: for termdat in $TERMDATA; do
234: mkdir -p "$CHROOT`dirname $termdat`"
235: if [ -d $termdat/. ]; then
236: cp -LR $termdat/. $CHROOT$termdat
237: else
238: cp $termdat $CHROOT`dirname $termdat`
239: fi
240: done
241: fi
242:
243:
244: LIBS=`for lib in $LIBS; do echo $lib; done | sort | uniq`
245: echo "Copying libraries:" $LIBS
246: for lib in $LIBS; do
247: mkdir -p "$CHROOT`dirname $lib`"
248: cp $lib "$CHROOT$lib"
249: done
250:
251:
252: echo "Finished."
253:
254:
CVSweb