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