summaryrefslogtreecommitdiffstats
path: root/templates/enter_dev_chroot.sh
blob: 8f5eb40a1bf636127920ca80510dad8bb0f729f8 (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
MYDIR=`pwd`
BROOT=$MYDIR/build_root.REPLACEME
MIRROR_DIR=$MYDIR/pkg_repo
TOOLS_DIR='LinHES-dev'
ARCH=REPLACEME



# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi



if [ ! -d $BROOT ]
then
	echo "build_root directory not found"
	exit 1
fi



if [ -d LinHES-PKGBUILD ]
    then
        echo "Found LinHES-PKGBUILD"
    else
        echo "***********************************************************************************************"
        echo "* Couldn't find LinHES-PKGBUILD                                                               *"
        echo "* Please checkout the repository into the current directory                                   *"
        echo "* The LinHES-PKGBUILD git repoistory is at knoppmyth.net/mount/repository/LinHES-PKGBUILD.git *"
        echo "***********************************************************************************************"
        exit 1
    fi

mounted=`mount`
umountlist=" "



echo $mounted | grep -q $BROOT/proc
status=$?
if [  ! status = 0 ]
then
	mount -t proc proc $BROOT/proc
    umountlist="$umountlist proc"
else
	echo "proc alredy mounted"
fi




echo $mounted | grep -q $BROOT/sys
status=$?
if [ ! $status = 0 ]
then
	mount -t sysfs sysfs $BROOT/sys
    umountlist="$umountlist sys"
else
	echo "sys alredy mounted"
fi

[ -e $BROOT/dev/random ] || mknod $BROOT/dev/random  c  1 8
[ -e $BROOT/dev/urandom ] || mknod $BROOT/dev/urandom c  1 9
[ -e $BROOT/dev/tty ] || mknod $BROOT/dev/tty c 5 0




echo $mounted | grep -q $BROOT/dev/pts
status=$?
if [ ! $status = 0 ]
then
    [ -e  $BROOT/dev/pts  ] || mkdir -p $BROOT/dev/pts
    mount -t devpts devpts $BROOT/dev/pts
    umountlist="$umountlist dev/pts"
else
	echo "/dev/pts alredy mounted"
fi



#create dir for build_tools
if [ ! -e $BROOT/build_tools ]
then
    mkdir $BROOT/build_tools
fi
#mount build_tools
echo $mounted | grep -q $BROOT/build_tools
status=$?
if [ ! $status = 0 ]
then
    mount --bind $MYDIR/$TOOLS_DIR/build_tools $BROOT/build_tools
     umountlist="$umountlist build_tools"
else
    echo "/build_tools alredy mounted"
fi


#create dir for the PKGBUILDS
if [ ! -e $BROOT/data/LinHES-PKGBUILD ]
then
    mkdir -p $BROOT/data/LinHES-PKGBUILD
fi

#mount pkg_repo
echo $mounted | grep -q $BROOT/data/LinHES-PKGBUILD
status=$?
if [ ! $status = 0 ]
then
    mount --bind $MYDIR/LinHES-PKGBUILD $BROOT/data/LinHES-PKGBUILD
    umountlist="$umountlist data/LinHES-PKGBUILD"
else
    echo "pkg_repo alredy mounted"
fi



#create dir for pkg_repo / local mirror
if [ ! -e $BROOT/data/pkg_repo ]
then
    mkdir -p $BROOT/data/pkg_repo
fi

#mount pkg_repo
echo $mounted | grep -q $BROOT/data/pkg_repo
status=$?
if [ ! $status = 0 ]
then
    mount --bind $MYDIR/pkg_repo $BROOT/data/pkg_repo
    umountlist="$umountlist data/pkg_repo"
else
    echo "pkg_repo alredy mounted"
fi








#copy in some files
[ -e  $BROOT/etc/resolv.conf  ] || cp -f /etc/resolv.conf $BROOT/etc/resolv.conf

if [ ! -f $BROOT/etc/bashrc ]
then
	cp -f $MYDIR/$TOOLS_DIR/templates/etc/bashrc $BROOT/etc/
	cp -f $MYDIR/$TOOLS_DIR/templates/etc/kmdev.sh $BROOT/etc/profile.d/kmdev.sh
	cp -f $MYDIR/$TOOLS_DIR/templates/etc/.bashrc $BROOT/root/
	cp -f $MYDIR/$TOOLS_DIR/templates/etc/.bash_profile $BROOT/root/
	chmod 755 $BROOT/root/.bashrc
	chmod 755 $BROOT/root/.bash_profile
	chmod 755 $BROOT/etc/profile.d/kmdev.sh
fi


#change the "xterm" title so we know it's a chroot
echo -e "\e]0;chroot-pkgbuild\a"
#used for Konsole
echo -e "\e]30;chroot-pkgbuild\a"
env -i /usr/sbin/chroot $BROOT /bin/bash --login



for i in $umountlist
do
    #echo "unmounting $BROOT/$i"
    umount $BROOT/$i
done


echo -e "\e]30;normal\a"
echo -e "\e]0;normal\a"