Awful
[openitg.git] / chroot-arcade.sh
1 #!/bin/sh
2
3 DEBIAN_SARGE_MIRROR="http://archive.debian.org/debian"
4 SARGE_DIST_NAME="sarge"
5 DEBIAN_SARGE_BACKPORTS="deb http://archive.debian.org/debian-backports sarge-backports main contrib"
6
7 usage() {
8 echo "Usage: $0 <path to source code> <chroot location>"
9 exit 1
10 }
11
12 # used to check for needed files/programs
13 verify_prog_requirements() {
14 # debootstrap is needed
15 if [ "x`which debootstrap`" = "x" ]; then
16 echo "$0: cannot continue, please install debootstrap on your system"
17 exit 1
18 fi
19 echo "debootstrap location: `which debootstrap`"
20
21 # user must be root
22 if [ ! "x`whoami`" = "xroot" ]; then
23 echo "$0: you must be root to setup the chroot environment"
24 exit 1
25 fi
26 }
27
28
29 # sets up debian sarge system at the given path, binds src dir to directory within chroot
30 setup_chroot() {
31 CHROOT_DIR="$1"
32 SRC_DIR="$2"
33 echo "Setting up chroot at $CHROOT_DIR..."
34
35 mkdir -p $CHROOT_DIR
36 debootstrap --arch i386 $SARGE_DIST_NAME $CHROOT_DIR $DEBIAN_SARGE_MIRROR/
37 if [ $? != 0 ]; then
38 echo "$0: debootstrap failed, exiting"
39 exit 1
40 fi
41
42 mkdir $CHROOT_DIR/root/openitg-dev
43
44
45 # first time setup script (sets up debian, retrieves correct packages)
46 cat <<! >$CHROOT_DIR/root/first_time_setup.sh
47 #!/bin/sh
48 export LC_ALL=C
49 echo -ne "*******************\n* You are now in the OpenITG AC chroot environment\n*******************\n"
50 echo "Installing necessary dev packages..."
51 # non-free and contrib for the nvidia packages
52 echo "deb $DEBIAN_SARGE_MIRROR $SARGE_DIST_NAME main contrib non-free" >/etc/apt/sources.list
53 echo "$DEBIAN_SARGE_BACKPORTS" >>/etc/apt/sources.list
54 apt-get update
55 apt-get install build-essential gettext automake1.8 gcc g++ libavcodec-dev libavformat-dev libxt-dev libogg-dev libpng-dev libjpeg-dev libvorbis-dev libusb-dev libglu1-mesa-dev libx11-dev libxrandr-dev liblua50-dev liblualib50-dev nvidia-glx-dev libmad0-dev libasound2-dev git-core automake1.7 autoconf gettext
56 echo "OpenITG AC chroot successfully set up!"
57 exec /bin/bash
58 !
59 chmod +x $CHROOT_DIR/root/first_time_setup.sh
60
61 # bootstrap script
62 cat <<! >$CHROOT_DIR/chroot_bootstrap.sh
63 #!/bin/sh
64 mount -o bind /proc $CHROOT_DIR/proc
65 mount -o bind /sys $CHROOT_DIR/sys
66 mount -o bind $SRC_DIR $CHROOT_DIR/root/openitg-dev
67 chroot $CHROOT_DIR /bin/bash
68 !
69 chmod +x $CHROOT_DIR/chroot_bootstrap.sh
70
71 mount -o bind /proc $CHROOT_DIR/proc
72 mount -o bind /sys $CHROOT_DIR/sys
73 mount -o bind $SRC_DIR $CHROOT_DIR/root/openitg-dev
74 chroot $CHROOT_DIR /root/first_time_setup.sh
75 }
76
77 if [ "x$1" = "x" ]; then
78 usage
79 fi
80 if [ "x$2" = "x" ]; then
81 usage
82 fi
83
84 if [ ! -d "$1" ]; then
85 echo "$0: Source code dir not found at $1"
86 exit 1
87 fi
88
89 verify_prog_requirements
90
91 SRC_DIR="`(cd $1; pwd)`"
92 setup_chroot $2 $SRC_DIR
93
94 exit 0;