[BACK]Return to dgl-create-chroot CVS log [TXT][DIR] Up to [contributed] / dgamelaunch-openbsd

Annotation of dgamelaunch-openbsd/dgl-create-chroot, Revision 1.5

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

CVSweb