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