slitaz-dev-tools view tazchroot/tazchroot.conf @ rev 154

tazdev: use packages to build a minimal chroot
author Christophe Lincoln <pankso@slitaz.org>
date Tue Mar 13 09:54:24 2012 +0100 (2012-03-13)
parents 0003e1a1474e
children dbcd2b40b915
line source
1 # Tazchroot configuration file.
2 # Allows you to build a chrooted cooking environnment using the last
3 # available package version.
5 # Use SliTaz version.
6 SLITAZ_VERSION=cooking
8 # SLITAZ_DIR (it's mounted on chroot).
9 SLITAZ_DIR=/home/slitaz
11 # Chroot path.
12 chroot_dir=$SLITAZ_DIR/$SLITAZ_VERSION/sandbox
14 # Online repository path.
15 MIRROR=http://mirror.slitaz.org/packages/cooking/
17 # Default SliTaz paths.
18 LOCALSTATE=/var/lib/tazpkg
19 INSTALLED=$LOCALSTATE/installed
21 # Webserver path.
22 # Defines where the webserver should be located.
23 # You have to use the same setup inside & outside the chroot.
24 # Here we use the default setup.
25 # The host system needs php installed to make it work.
26 # Uncomment the following line to use this option.
27 WEBSERVER="/var/www/vhosts/bb"
29 # Default scripts path (these scripts are added to the
30 # $chroot_dir/usr/bin and can be called with tazchroot script)
31 script_dir="/usr/lib/slitaz/chroot-scripts/tazchroot"
33 # List of directories to mount.
34 # They are mounted to an equivalent location in the chroot.
35 # (one per line)
36 list_dir="$SLITAZ_DIR
37 $WEBSERVER"
39 create_chroot()
40 {
41 # Warning message.
42 echo -en "\\033[1;31mWarning:\\033[0m this script is going to use another packages repository other \
43 than the one you generally use. Please don't install packages until the chroot is created or it will \
44 screw your main system. Don't continue to run this script if you're installing something.
46 Continue to run (type 'yes' to continue) ? " | fold -s; read answer
47 [ "$answer" = yes ] || exit
49 if [ -f "$LOCALSTATE/priotity" ]; then
50 mv $LOCALSTATE/priotity $LOCALSTATE/priority.tmp-bak
51 fi
52 tazpkg add-undigest tmp.$SLITAZ_VERSION.mirror "$MIRROR"
53 echo "tmp.$SLITAZ_VERSION.mirror" > /var/lib/tazpkg/priority
54 tazpkg recharge
56 # Install needed packages.
57 mkdir -p $chroot_dir
58 tazpkg get-install busybox --root="$chroot_dir"
59 tazpkg get-install tazchroot --root="$chroot_dir"
60 tazpkg get-install tazpkg --root="$chroot_dir"
61 tazpkg get-install tazwok --root="$chroot_dir"
62 tazpkg get-install libtaz --root="$chroot_dir"
64 rm -r $LOCALSTATE/undigest/tmp.$SLITAZ_VERSION.mirror
65 if [ -f "$LOCALSTATE/priotity.tmp-bak" ]; then
66 mv -f $LOCALSTATE/priotity.tmp-bak $LOCALSTATE/priority
67 fi
68 tazpkg recharge
70 echo -e "\\033[1;31mWarning:\\033[0m Your SliTaz repository configuration is now \
71 back to a normal state." | fold -s
72 }
74 mount_chroot()
75 {
76 # resolv.conf is needed to have network access into chroot.
77 cp -a /etc/resolv.conf "$chroot_dir/etc/resolv.conf"
79 # Setup mirror for chroot.
80 echo "$MIRROR" > "$chroot_dir/var/lib/tazpkg/mirror"
82 # Setup release.
83 echo "$SLITAZ_VERSION" > "$chroot_dir/etc/slitaz-release"
85 # Webserver setup.
86 if [ "$WEBSERVER" ]; then
87 mkdir -p /usr/lib/slitaz
88 [ -d /usr/share/slitaz/web-bb ] || [ -L /usr/share/slitaz/web-bb ] ||
89 ln -s $chroot_dir/usr/share/slitaz/web-bb /usr/share/slitaz/web-bb
91 # Make tazwok act as if php/lighttpd were installed into the sandbox.
92 mkdir -p $chroot_dir$INSTALLED/php
93 mkdir -p $chroot_dir$INSTALLED/lighttpd
94 fi
96 # Mount system directories.
97 mount -o bind /proc $chroot_dir/proc
98 mount -o bind /sys $chroot_dir/sys
99 mount -o bind /dev/pts $chroot_dir/dev/pts
100 mount -o bind /dev/shm $chroot_dir/dev/shm
102 # Mount directories of LIST_DIR.
103 # Create them if needed to avoid errors.
104 for dir in $list_dir; do
105 mkdir -p $dir
106 mkdir -p $chroot_dir$dir
107 mount $dir $chroot_dir$dir
108 done
109 }
111 umount_chroot()
112 {
113 # First umount directories of LIST_DIR.
114 for dir in $list_dir; do
115 umount $chroot_dir$dir
116 done
118 # Then umount system directories.
119 umount $chroot_dir/dev/shm
120 umount $chroot_dir/dev/pts
121 umount $chroot_dir/sys
122 umount $chroot_dir/proc
123 }