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

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

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.
                     17: COMPRESSBIN="/bin/gzip"
                     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:
                     81: if [ ! -e "$CURDIR/dgamelaunch" ]; then
                     82:    errorexit "Cannot find dgamelaunch in $CURDIR"
                     83: fi
                     84:
                     85: DGLFILE="dgamelaunch.`date +%Y%m%d`"
                     86:
                     87: echo "Setting up chroot in $CHROOT"
                     88:
                     89: LIBS="`findlibs dgamelaunch`"
                     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
                     95: cp "$CURDIR/dgamelaunch" "$DGLFILE"
                     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"
                    113:   fi
                    114: fi
                    115:
                    116:
                    117: if [ -n "$COMPRESSBIN" -a -e "`which $COMPRESSBIN`" ]; then
                    118:   COMPRESSDIR="`dirname $COMPRESSBIN`"
                    119:   COMPRESSDIR="`echo ${COMPRESSDIR%/}`"
                    120:   COMPRESSDIR="`echo ${COMPRESSDIR#/}`"
                    121:   echo "Copying $COMPRESSBIN to $COMPRESSDIR"
                    122:   mkdir -p "$COMPRESSDIR"
                    123:   cp "`which $COMPRESSBIN`" "$COMPRESSDIR/"
                    124:   LIBS="$LIBS `findlibs $COMPRESSBIN`"
                    125: fi
                    126:
                    127:
                    128: mkdir -p dev
                    129: cd dev
                    130: mknod urandom c 1 9
                    131: cd ..
                    132:
                    133:
                    134: cd etc
                    135: cp "$CURDIR/examples/dgamelaunch.conf" .
                    136: echo "Edit $CHROOT/etc/dgamelaunch.conf to suit your needs."
                    137: [ -f /etc/localtime ] && cp /etc/localtime .
                    138: cd ..
                    139:
                    140:
                    141: cd bin
                    142: cp "$CURDIR/ee" .
                    143: cp "$CURDIR/virus" .
                    144: echo "Copied text editors 'ee' and 'virus' to chroot."
                    145: cd ..
                    146:
                    147:
                    148: cp "$CURDIR/examples/dgl_menu_main_anon.txt" .
                    149: cp "$CURDIR/examples/dgl_menu_main_user.txt" .
                    150: cp "$CURDIR/examples/dgl_menu_watchmenu_help.txt" .
                    151: cp "$CURDIR/examples/dgl-banner" .
                    152: cp "$CURDIR/dgl-default-rcfile" "dgl-default-rcfile.nh343"
                    153: chmod go+r dgl_menu_main_anon.txt dgl_menu_main_user.txt dgl-banner dgl-default-rcfile.nh343
                    154:
                    155: NHSUBDIR="`echo ${NHSUBDIR%/}`"
                    156: NHSUBDIR="`echo ${NHSUBDIR#/}`"
                    157:
                    158: mkdir "$CHROOT/$NHSUBDIR"
                    159:
                    160: if [ -n "$NETHACKBIN" -a ! -e "$NETHACKBIN" ]; then
                    161:   errorexit "Cannot find NetHack binary $NETHACKBIN"
                    162: fi
                    163:
                    164: if [ -n "$NETHACKBIN" -a -e "$NETHACKBIN" ]; then
                    165:   echo "Copying $NETHACKBIN"
                    166:   cd "$NHSUBDIR"
                    167:   NHBINFILE="`basename $NETHACKBIN`.`date +%Y%m%d`"
                    168:   cp "$NETHACKBIN" "$NHBINFILE"
                    169:   ln -s "$NHBINFILE" nethack
                    170:   LIBS="$LIBS `findlibs $NETHACKBIN`"
                    171:   cd "$CHROOT"
                    172: fi
                    173:
                    174:
                    175: NH_PLAYGROUND_FIXED="`echo ${NH_PLAYGROUND_FIXED%/}`"
                    176:
                    177: if [ -n "$NH_PLAYGROUND_FIXED" -a -d "$NH_PLAYGROUND_FIXED" ]; then
                    178:   echo "Copying NetHack playground stuff."
                    179:   NHFILES="*.lev *.dat cmdhelp data dungeon help hh history license opthelp options oracles recover rumors wizhelp"
                    180:   for fil in $NHFILES; do
                    181:     cp $NH_PLAYGROUND_FIXED/$fil "$CHROOT/$NHSUBDIR/"
                    182:   done
                    183: fi
                    184:
                    185:
                    186: NH_VAR_PLAYGROUND="`echo ${NH_VAR_PLAYGROUND%/}`"
                    187: NH_VAR_PLAYGROUND="`echo ${NH_VAR_PLAYGROUND#/}`"
                    188:
                    189: echo "Creating NetHack variable dir stuff."
                    190: if [ -n "$NH_VAR_PLAYGROUND" ]; then
                    191:   mkdir -p "$CHROOT/$NH_VAR_PLAYGROUND"
                    192:   chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND"
                    193: fi
                    194: mkdir -p "$CHROOT/$NH_VAR_PLAYGROUND/save"
                    195: chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND/save"
                    196: touch "$CHROOT/$NH_VAR_PLAYGROUND/logfile"
                    197: touch "$CHROOT/$NH_VAR_PLAYGROUND/perm"
                    198: touch "$CHROOT/$NH_VAR_PLAYGROUND/record"
                    199: touch "$CHROOT/$NH_VAR_PLAYGROUND/xlogfile"
                    200:
                    201: chown -R "$USRGRP" "$CHROOT/$NHSUBDIR"
                    202: chown -R "$USRGRP" "$CHROOT/$NH_VAR_PLAYGROUND"
                    203:
                    204:
                    205:
                    206: # Curses junk
                    207: if [ -n "$TERMDATA" ]; then
                    208:     echo "Copying termdata files from $TERMDATA"
                    209:     for termdat in $TERMDATA; do
                    210:        mkdir -p "$CHROOT`dirname $termdat`"
                    211:        if [ -d $termdat/. ]; then
                    212:                cp -LR $termdat/. $CHROOT$termdat
                    213:        else
                    214:                cp $termdat $CHROOT`dirname $termdat`
                    215:        fi
                    216:     done
                    217: fi
                    218:
                    219:
                    220: LIBS=`for lib in $LIBS; do echo $lib; done | sort | uniq`
                    221: echo "Copying libraries:" $LIBS
                    222: for lib in $LIBS; do
                    223:         mkdir -p "$CHROOT`dirname $lib`"
                    224:         cp $lib "$CHROOT$lib"
                    225: done
                    226:
                    227:
                    228: echo "Finished."
                    229:
                    230:

CVSweb