bin sh Copyright 2009 Andrey Tolstoy frilak gmail com Distributed unde

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
# Copyright 2009 Andrey Tolstoy <frilak@gmail.com>
# Distributed under the terms of the GNU General Public License v2
#
# This script sets up a gentoo chroot environment and cleans it up
# after exiting.
# You need to specify GENTOO_DIR - directory where stage3 has been
# unpacked. Do that by:
# - specify it as $1 param.
# - specify it below setting GENTOO_DIR
# - GENTOO_DIR will be set as `pwd`/gentoo
GENTOO_DIR=/home/frilak/dev/gentoo
function gentoo_exit()
{
# Cleaning up
umount ${GENTOO_DIR}/proc >/dev/null 2>&1
umount ${GENTOO_DIR}/dev >/dev/null 2>&1
umount ${GENTOO_DIR}/sys >/dev/null 2>&1
umount ${GENTOO_DIR}/usr/src/linux >/dev/null 2>&1
umount ${GENTOO_DIR}/lib/modules >/dev/null 2>&1
}
function error()
{
echo "Something went wrong O_o"
gentoo_exit
exit 1
}
function gentoo_start()
{
# We need working /proc /dev /sys
mount -o bind /proc ${GENTOO_DIR}/proc || error
mount -o bind /dev ${GENTOO_DIR}/dev || error
mount -o bind /sys ${GENTOO_DIR}/sys || error
# We need linux sources as well
if [ ! -d ${GENTOO_DIR}/usr/src/linux ]; then
mkdir ${GENTOO_DIR}/usr/src/linux
fi
mount -o bind /usr/src/linux-`uname -r` ${GENTOO_DIR}/usr/src/linux || error
# And also modules dir
if [ ! -d ${GENTOO_DIR}/lib/modules ]; then
mkdir ${GENTOO_DIR}/lib/modules
fi
mount -o bind /lib/modules ${GENTOO_DIR}/lib/modules || error
cp /etc/resolv.conf ${GENTOO_DIR}/etc/resolv.conf || error
# Finally chrooting
chroot ${GENTOO_DIR} /bin/bash || error
gentoo_exit
exit 0
}
if [ ! -n "${GENTOO_DIR}" ]; then
if [ -n "$1" ]; then
GENTOO_DIR="$1"
else
GENTOO_DIR="`pwd`/gentoo"
fi
fi
if [ ${UID} -ne 0 ]; then
echo "Please run this script as root"
exit 1
fi
echo "Starting gentoo in ${GENTOO_DIR}..."
if [ ! -d ${GENTOO_DIR} ]; then
echo "${GENTOO_DIR} unavailable"
exit 1
fi
gentoo_start
exit 0