| 1 | # emrootfslib : shell library to support root filesystems for Emdebian. |
|---|
| 2 | # |
|---|
| 3 | # This file is POSIX shell, compatible with debootstrap. |
|---|
| 4 | # Do not include or reference pbuilder functions or bash code here. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (C) 2006-2008 Neil Williams <codehelp@debian.org> |
|---|
| 7 | # |
|---|
| 8 | # This package is free software; you can redistribute it and/or modify |
|---|
| 9 | # it under the terms of the GNU General Public License as published by |
|---|
| 10 | # the Free Software Foundation; either version 3 of the License, or |
|---|
| 11 | # (at your option) any later version. |
|---|
| 12 | # |
|---|
| 13 | # This program is distributed in the hope that it will be useful, |
|---|
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | # GNU General Public License for more details. |
|---|
| 17 | # |
|---|
| 18 | # You should have received a copy of the GNU General Public License |
|---|
| 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 20 | # |
|---|
| 21 | |
|---|
| 22 | # This shell library requires perl ! |
|---|
| 23 | |
|---|
| 24 | # Intended solely for use on the build machine. Do not use these functions |
|---|
| 25 | # in second_stage_install ! |
|---|
| 26 | |
|---|
| 27 | OURVERSION=`perl -e 'use Emdebian::Tools; print &tools_version();'` |
|---|
| 28 | |
|---|
| 29 | get_default_arch () |
|---|
| 30 | { |
|---|
| 31 | ARCH=`perl -e 'use Debian::DpkgCross; \ |
|---|
| 32 | &read_config(); \ |
|---|
| 33 | my $arch = &get_architecture(); \ |
|---|
| 34 | print (qq/None.\n/) if (!$arch); \ |
|---|
| 35 | print $arch;';` |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | get_work_dir () |
|---|
| 39 | { |
|---|
| 40 | WORKDIR=`perl -e 'use Cwd; use Emdebian::Tools; use Config::Auto; use Debian::DpkgCross; \ |
|---|
| 41 | &read_config; \ |
|---|
| 42 | my $w = &get_workdir; \ |
|---|
| 43 | $w = cwd if (! -d $w); \ |
|---|
| 44 | $w =~ s/\/$//; \ |
|---|
| 45 | print $w;';` |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | get_work_dir |
|---|
| 49 | get_default_arch |
|---|
| 50 | |
|---|
| 51 | WORKPLACE="${WORKDIR}/pbuilder" |
|---|
| 52 | BASETGZ="${WORKDIR}/emdebian.tgz" |
|---|
| 53 | |
|---|
| 54 | #pbuilder base values |
|---|
| 55 | DEBIAN_BUILDARCH=$ARCH |
|---|
| 56 | # cross-building chroot is same arch as host. |
|---|
| 57 | BUILDRESULT="$WORKPLACE/result/" |
|---|
| 58 | # tidy up // to / |
|---|
| 59 | BUILDRESULT=`echo $BUILDRESULT | tr -s \/` |
|---|
| 60 | APTCACHE="$WORKPLACE/aptcache/" |
|---|
| 61 | # tidy up // to / |
|---|
| 62 | APTCACHE=`echo $APTCACHE | tr -s \/` |
|---|
| 63 | AUTO_DEBSIGN=yes |
|---|
| 64 | APTCACHEHARDLINK="no" |
|---|
| 65 | BUILDPLACE="$WORKPLACE/build" |
|---|
| 66 | |
|---|
| 67 | # the default is to add a PID in the buildplace. |
|---|
| 68 | BASEBUILDPLACE="$BUILDPLACE" |
|---|
| 69 | if [ "${PRESERVE_BUILDPLACE}" != "yes" ]; then |
|---|
| 70 | BUILDPLACE="$BUILDPLACE/$$" |
|---|
| 71 | fi |
|---|
| 72 | |
|---|
| 73 | checkarch () |
|---|
| 74 | { |
|---|
| 75 | ARCH=$ARCH perl -e 'use Debian::DpkgCross; $arch = $ENV{ARCH}; $arch=~s/ //g; \ |
|---|
| 76 | die "Unsupported architecture: $arch Use --arch\n" if (not defined (&check_arch($arch)));' |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | create_emdebiantgz() { |
|---|
| 80 | ( |
|---|
| 81 | if ! cd "$BUILDPLACE"; then |
|---|
| 82 | echo "Error: unexpected error in chdir to $BUILDPLACE" >&2 |
|---|
| 83 | exit 1; |
|---|
| 84 | fi |
|---|
| 85 | while test -f "${BASETGZ}.tmp"; do |
|---|
| 86 | echo " -> Someone else has lock over ${BASETGZ}.tmp, waiting" |
|---|
| 87 | sleep 10s |
|---|
| 88 | done |
|---|
| 89 | echo " -> creating base tarball [${BASETGZ}]" |
|---|
| 90 | if ! sudo tar cfz "${BASETGZ}.tmp" * ; then |
|---|
| 91 | echo " -> failed building base tarball" |
|---|
| 92 | rm -f "${BASETGZ}.tmp" |
|---|
| 93 | exit 1; |
|---|
| 94 | fi |
|---|
| 95 | mv "${BASETGZ}.tmp" "${BASETGZ}" |
|---|
| 96 | ) |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | check_dirs() |
|---|
| 100 | { |
|---|
| 101 | if [ ! -d $BUILDPLACE ] ; then |
|---|
| 102 | mkdir -p $BUILDPLACE |
|---|
| 103 | fi |
|---|
| 104 | if [ ! -d $BUILDRESULT ] ; then |
|---|
| 105 | mkdir -p $BUILDRESULT |
|---|
| 106 | fi |
|---|
| 107 | if [ ! -d $APTCACHE ] ; then |
|---|
| 108 | mkdir -p $APTCACHE |
|---|
| 109 | fi |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | disable_apt_recommends () { |
|---|
| 113 | if [ -d "$BUILDPLACE/etc/apt/apt.conf.d/" ]; then |
|---|
| 114 | if [ ! -f "$BUILDPLACE/etc/apt/apt.conf.d/10disablerecommends" ]; then |
|---|
| 115 | echo " -> disabling Apt::Install-Recommends" |
|---|
| 116 | cat > $BUILDPLACE/etc/apt/apt.conf.d/10disablerecommends << 'EOF' |
|---|
| 117 | APT |
|---|
| 118 | { |
|---|
| 119 | Install-Recommends "false" |
|---|
| 120 | }; |
|---|
| 121 | EOF |
|---|
| 122 | fi |
|---|
| 123 | fi |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | disable_apt_pdiffs () { |
|---|
| 127 | if [ -d "$BUILDPLACE/etc/apt/apt.conf.d/" ]; then |
|---|
| 128 | if [ ! -f "$BUILDPLACE/etc/apt/apt.conf.d/12disablepdiffs" ]; then |
|---|
| 129 | echo " -> disabling Apt::Acquire::PDiffs" |
|---|
| 130 | cat > $BUILDPLACE/etc/apt/apt.conf.d/12disablepdiffs << 'EOF' |
|---|
| 131 | APT |
|---|
| 132 | { |
|---|
| 133 | Acquire::PDiffs "false"; |
|---|
| 134 | }; |
|---|
| 135 | EOF |
|---|
| 136 | fi |
|---|
| 137 | fi |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | apt_autoremove_always () { |
|---|
| 141 | if [ -d "$BUILDPLACE/etc/apt/apt.conf.d/" ]; then |
|---|
| 142 | if [ ! -f "$BUILDPLACE/etc/apt/apt.conf.d/11always_autoremove" ]; then |
|---|
| 143 | echo " -> enabling Apt::AutomaticRemove" |
|---|
| 144 | cat > $BUILDPLACE/etc/apt/apt.conf.d/11always_autoremove << 'EOF' |
|---|
| 145 | APT |
|---|
| 146 | { |
|---|
| 147 | AutomaticRemove "true" |
|---|
| 148 | }; |
|---|
| 149 | EOF |
|---|
| 150 | fi |
|---|
| 151 | fi |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | unpack_debootstrap () { |
|---|
| 155 | info INSTCORE "Starting unpacking in $BUILDPLACE" |
|---|
| 156 | for deb in `ls $BUILDPLACE/var/cache/apt/archives/*.deb`; do |
|---|
| 157 | ver=`dpkg -f $deb Version` |
|---|
| 158 | pkg=`dpkg -f $deb Package` |
|---|
| 159 | info INSTCORE "Unpacking $pkg ($ver) ...." |
|---|
| 160 | dpkg -x $deb $BUILDPLACE/ |
|---|
| 161 | # get the package listing with reduced parsing complexity |
|---|
| 162 | mkdir $BUILDPLACE/listing |
|---|
| 163 | ar -p $deb data.tar.gz > $BUILDPLACE/listing/data.tar.gz |
|---|
| 164 | tar -tzf $BUILDPLACE/listing/data.tar.gz | sed -e 's/^\.//' | sed -e 's/^\/$/\/\./' | sed -e 's/\/$//' > $BUILDPLACE/var/lib/dpkg/info/${pkg}.list |
|---|
| 165 | rm -rf $BUILDPLACE/listing |
|---|
| 166 | rm -rf $BUILDPLACE/tmp/* |
|---|
| 167 | dpkg -e $deb $BUILDPLACE/tmp/ |
|---|
| 168 | for maint in `ls $BUILDPLACE/tmp/`; do |
|---|
| 169 | mv $BUILDPLACE/tmp/$maint $BUILDPLACE/var/lib/dpkg/info/$pkg.$maint |
|---|
| 170 | if [ $maint = "control" ]; then |
|---|
| 171 | cat $BUILDPLACE/var/lib/dpkg/info/$pkg.$maint >> $BUILDPLACE/var/lib/dpkg/available |
|---|
| 172 | cat $BUILDPLACE/var/lib/dpkg/info/$pkg.$maint >> $BUILDPLACE/var/lib/dpkg/status |
|---|
| 173 | echo "" >> $BUILDPLACE/var/lib/dpkg/available |
|---|
| 174 | echo "Status: install ok unpacked" >> $BUILDPLACE/var/lib/dpkg/status |
|---|
| 175 | rm $BUILDPLACE/var/lib/dpkg/info/$pkg.$maint |
|---|
| 176 | fi |
|---|
| 177 | # need a dpkg filter to make this stick |
|---|
| 178 | if [ $maint = "symbols" ]; then |
|---|
| 179 | rm $BUILDPLACE/var/lib/dpkg/info/$pkg.symbols |
|---|
| 180 | fi |
|---|
| 181 | done |
|---|
| 182 | if [ -f $BUILDPLACE/var/lib/dpkg/info/$pkg.conffiles ]; then |
|---|
| 183 | echo "Conffiles:" >> $BUILDPLACE/var/lib/dpkg/status |
|---|
| 184 | info INSTCORE "Processing $pkg.conffiles" |
|---|
| 185 | for line in `cat $BUILDPLACE/var/lib/dpkg/info/$pkg.conffiles`; do |
|---|
| 186 | md5=`md5sum $BUILDPLACE/$line | cut -d" " -f1` |
|---|
| 187 | echo " $line $md5" >> $BUILDPLACE/var/lib/dpkg/status |
|---|
| 188 | done |
|---|
| 189 | fi |
|---|
| 190 | echo "" >> $BUILDPLACE/var/lib/dpkg/status |
|---|
| 191 | done |
|---|
| 192 | # busybox symlinks are best managed in postinst so that dpkg |
|---|
| 193 | # does not complain when they are replaced by Debian packages. |
|---|
| 194 | # this allows more applets to be supported by default. |
|---|
| 195 | if [ -f $BUILDPLACE/usr/share/busybox/busybox.links ]; then |
|---|
| 196 | cd $BUILDPLACE |
|---|
| 197 | # setup busybox |
|---|
| 198 | cp usr/share/busybox/busybox.links . |
|---|
| 199 | cp usr/share/busybox/install.sh . |
|---|
| 200 | # link in the rest of its applets from OUTSIDE the chroot |
|---|
| 201 | info INSTCORE "Symlinking the busybox applets..." |
|---|
| 202 | sh ./install.sh $BUILDPLACE/ --symlinks |
|---|
| 203 | rm $BUILDPLACE/install.sh |
|---|
| 204 | rm $BUILDPLACE/busybox.links |
|---|
| 205 | else |
|---|
| 206 | info INSTCORE "busybox configuration not required" |
|---|
| 207 | fi |
|---|
| 208 | if [ ! -e "$BUILDPLACE/etc/localtime" ]; then |
|---|
| 209 | ln -sf /usr/share/zoneinfo/UTC "$BUILDPLACE/etc/localtime" |
|---|
| 210 | fi |
|---|
| 211 | # a better fix for /usr/sbin/update-rc.d is available via sysv-rc |
|---|
| 212 | if [ ! -f $BUILDPLACE/usr/sbin/update-rc.d ]; then |
|---|
| 213 | echo "#!/bin/sh" > $BUILDPLACE/usr/sbin/update-rc.d |
|---|
| 214 | echo "" >> $BUILDPLACE/usr/sbin/update-rc.d |
|---|
| 215 | chmod 755 $BUILDPLACE/usr/sbin/update-rc.d |
|---|
| 216 | fi |
|---|
| 217 | RC=`head $BUILDPLACE/usr/sbin/update-rc.d | grep /usr/bin/perl || true` |
|---|
| 218 | if [ "$RC" != "" ]; then |
|---|
| 219 | info INSTCORE "Replacing perl update-rc.d" |
|---|
| 220 | echo "#!/bin/sh" > $BUILDPLACE/usr/sbin/update-rc.d |
|---|
| 221 | echo "" >> $BUILDPLACE/usr/sbin/update-rc.d |
|---|
| 222 | chmod 755 $BUILDPLACE/usr/sbin/update-rc.d |
|---|
| 223 | fi |
|---|
| 224 | # invoke-rc.d is usually shell but is being looked at in Debian. |
|---|
| 225 | if [ ! -f $BUILDPLACE/usr/sbin/invoke-rc.d ]; then |
|---|
| 226 | echo '#!/bin/sh' > $BUILDPLACE/usr/sbin/invoke-rc.d |
|---|
| 227 | echo 'exec /etc/init.d/$1 $2' > $BUILDPLACE/usr/sbin/invoke-rc.d |
|---|
| 228 | echo '' >> $BUILDPLACE/usr/sbin/invoke-rc.d |
|---|
| 229 | chmod 755 $BUILDPLACE/usr/sbin/invoke-rc.d |
|---|
| 230 | fi |
|---|
| 231 | info INSTCORE "Removing archives..." |
|---|
| 232 | rm -f $BUILDPLACE/var/cache/apt/archives/*.deb |
|---|
| 233 | # (skip stages in emsecondstage) |
|---|
| 234 | touch $BUILDPLACE/debootstrap/unpacked |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | extra_etc_rcd () |
|---|
| 238 | { |
|---|
| 239 | if [ ! -d $BUILDPLACE/etc/rcS.d ]; then |
|---|
| 240 | mkdir $BUILDPLACE/etc/rcS.d |
|---|
| 241 | fi |
|---|
| 242 | if [ ! -d $BUILDPLACE/etc/rc0.d ]; then |
|---|
| 243 | mkdir $BUILDPLACE/etc/rc0.d |
|---|
| 244 | fi |
|---|
| 245 | if [ ! -d $BUILDPLACE/etc/rc1.d ]; then |
|---|
| 246 | mkdir $BUILDPLACE/etc/rc1.d |
|---|
| 247 | fi |
|---|
| 248 | if [ ! -d $BUILDPLACE/etc/rc6.d ]; then |
|---|
| 249 | mkdir $BUILDPLACE/etc/rc6.d |
|---|
| 250 | fi |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | provide_var_lib_x11 () |
|---|
| 254 | { |
|---|
| 255 | if [ ! -d $BUILDPLACE/var/lib/x11 ]; then |
|---|
| 256 | mkdir -p $BUILDPLACE/var/lib/x11 |
|---|
| 257 | fi |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | basic_group_setup () { |
|---|
| 261 | if [ ! -f $BUILDPLACE/etc/group ]; then |
|---|
| 262 | echo \ |
|---|
| 263 | "root:x:0: |
|---|
| 264 | daemon:x:1: |
|---|
| 265 | bin:x:2: |
|---|
| 266 | sys:x:3: |
|---|
| 267 | adm:x:4: |
|---|
| 268 | tty:x:5: |
|---|
| 269 | disk:x:6: |
|---|
| 270 | lp:x:7: |
|---|
| 271 | mail:x:8: |
|---|
| 272 | news:x:9: |
|---|
| 273 | uucp:x:10: |
|---|
| 274 | man:x:12: |
|---|
| 275 | proxy:x:13: |
|---|
| 276 | kmem:x:15: |
|---|
| 277 | audio:x:29: |
|---|
| 278 | utmp:x:43: |
|---|
| 279 | video:x:44: |
|---|
| 280 | " > $BUILDPLACE/etc/group |
|---|
| 281 | fi |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | basic_passwd_setup () { |
|---|
| 285 | if [ ! -f $BUILDPLACE/etc/passwd ]; then |
|---|
| 286 | echo \ |
|---|
| 287 | "root:x:0:0:root:/root:/bin/sh |
|---|
| 288 | daemon:x:1:1:daemon:/usr/sbin:/bin/sh |
|---|
| 289 | bin:x:2:2:bin:/bin:/bin/sh |
|---|
| 290 | sys:x:3:3:sys:/dev:/bin/sh |
|---|
| 291 | sync:x:4:65534:sync:/bin:/bin/sync |
|---|
| 292 | games:x:5:60:games:/usr/games:/bin/sh |
|---|
| 293 | man:x:6:12:man:/var/cache/man:/bin/sh |
|---|
| 294 | lp:x:7:7:lp:/var/spool/lpd:/bin/sh |
|---|
| 295 | mail:x:8:8:mail:/var/mail:/bin/sh |
|---|
| 296 | news:x:9:9:news:/var/spool/news:/bin/sh |
|---|
| 297 | uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh |
|---|
| 298 | proxy:x:13:13:proxy:/bin:/bin/sh |
|---|
| 299 | www-data:x:33:33:www-data:/var/www:/bin/sh |
|---|
| 300 | backup:x:34:34:backup:/var/backups:/bin/sh |
|---|
| 301 | list:x:38:38:Mailing List Manager:/var/list:/bin/sh |
|---|
| 302 | irc:x:39:39:ircd:/var/run/ircd:/bin/sh |
|---|
| 303 | gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh |
|---|
| 304 | nobody:x:65534:65534:nobody:/nonexistent:/bin/sh |
|---|
| 305 | " > $BUILDPLACE/etc/passwd |
|---|
| 306 | fi |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | # need /etc/shadow too |
|---|
| 310 | basic_shadow_setup () { |
|---|
| 311 | if [ ! -f $BUILDPLACE/etc/shadow ]; then |
|---|
| 312 | echo \ |
|---|
| 313 | "root:$1$Vu4M34LT$0L2BfH9nXbSG1zQWxUH8M1:0:::::: |
|---|
| 314 | daemon:*:13896:0:99999:7::: |
|---|
| 315 | bin:*:0:0:99999:7::: |
|---|
| 316 | sys:*:0:0:99999:7::: |
|---|
| 317 | sync:*:0:0:99999:7::: |
|---|
| 318 | games:*:0:0:99999:7::: |
|---|
| 319 | man:*:0:0:99999:7::: |
|---|
| 320 | lp:*:0:0:99999:7::: |
|---|
| 321 | mail:*:0:0:99999:7::: |
|---|
| 322 | news:*:0:0:99999:7::: |
|---|
| 323 | uucp:*:0:0:99999:7::: |
|---|
| 324 | proxy:*:0:0:99999:7::: |
|---|
| 325 | www-data:*:0:0:99999:7::: |
|---|
| 326 | backup:*:0:0:99999:7::: |
|---|
| 327 | list:*:0:0:99999:7::: |
|---|
| 328 | irc:*:0:0:99999:7::: |
|---|
| 329 | gnats:*:0:0:99999:7::: |
|---|
| 330 | nobody:*:0:0:99999:7:::" > $BUILDPLACE/etc/shadow |
|---|
| 331 | fi |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | provide_empty_install_info () { |
|---|
| 335 | if [ ! -f $BUILDPLACE/usr/sbin/install-info ]; then |
|---|
| 336 | echo \ |
|---|
| 337 | '#!/bin/sh |
|---|
| 338 | exec /etc/init.d/$1 $2 |
|---|
| 339 | ' > $BUILDPLACE/usr/sbin/install-info |
|---|
| 340 | chmod 755 $BUILDPLACE/usr/sbin/install-info |
|---|
| 341 | fi |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | set_approx_time () { |
|---|
| 345 | if [ -d $BUILDPLACE/bin ]; then |
|---|
| 346 | DATE=`date` |
|---|
| 347 | ZERO=`date -d@0` |
|---|
| 348 | # if we have a usable date, store it. |
|---|
| 349 | if [ "$DATE" != "$ZERO" ]; then |
|---|
| 350 | APPROX=`stat -c%Y $BUILDPLACE/bin/` |
|---|
| 351 | STR=`date -d@$APPROX +%m%d%H%M%Y` |
|---|
| 352 | info INSTCORE "Storing approximate time '$STR' in './datestring'" |
|---|
| 353 | echo "$STR" > $BUILDPLACE/datestring |
|---|
| 354 | fi |
|---|
| 355 | fi |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | basic_etc_fstab () { |
|---|
| 359 | if [ ! -f "$BUILDPLACE/etc/fstab" ]; then |
|---|
| 360 | cat > $BUILDPLACE/etc/fstab << 'EOF' |
|---|
| 361 | # /etc/fstab: static file system information. |
|---|
| 362 | # |
|---|
| 363 | # <file system> <mount point> <type> <options> <dump> <pass> |
|---|
| 364 | proc /proc proc defaults 0 0 |
|---|
| 365 | sysfs /sys sysfs defaults 0 0 |
|---|
| 366 | devpts /dev/pts devpts mode=0620,gid=5 0 0 |
|---|
| 367 | EOF |
|---|
| 368 | chown 0.0 "$BUILDPLACE/etc/fstab"; |
|---|
| 369 | chmod 0644 "$BUILDPLACE/etc/fstab" |
|---|
| 370 | fi |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | make_dpkg_dirs () { |
|---|
| 374 | mkdir -p "$BUILDPLACE/var/lib/dpkg" |
|---|
| 375 | : >"$BUILDPLACE/var/lib/dpkg/status" |
|---|
| 376 | echo >"$BUILDPLACE/var/lib/dpkg/available" |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | x_feign_install () { |
|---|
| 380 | local pkg="$1" |
|---|
| 381 | local deb="$(debfor $pkg)" |
|---|
| 382 | local ver="$( |
|---|
| 383 | ar -p "$BUILDPLACE/$deb" control.tar.gz | zcat | |
|---|
| 384 | tar -O -xf - control ./control 2>/dev/null | |
|---|
| 385 | sed -ne 's/^Version: *//Ip' | head -n 1 |
|---|
| 386 | )" |
|---|
| 387 | mkdir -p "$BUILDPLACE/var/lib/dpkg/info" |
|---|
| 388 | echo \ |
|---|
| 389 | "Package: $pkg |
|---|
| 390 | Version: $ver |
|---|
| 391 | Status: install ok installed" >> "$BUILDPLACE/var/lib/dpkg/status" |
|---|
| 392 | touch "$BUILDPLACE/var/lib/dpkg/info/${pkg}.list" |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | prepare_proc () { |
|---|
| 396 | if [ ! -d $BUILDPLACE/proc ]; then |
|---|
| 397 | mkdir -p $BUILDPLACE/proc |
|---|
| 398 | fi |
|---|
| 399 | if [ ! -d $BUILDPLACE/sys ]; then |
|---|
| 400 | mkdir -p $BUILDPLACE/sys |
|---|
| 401 | fi |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | prepare_var () { |
|---|
| 405 | if [ ! -d $BUILDPLACE/var/log ]; then |
|---|
| 406 | mkdir -p $BUILDPLACE/var/log |
|---|
| 407 | fi |
|---|
| 408 | if [ ! -d $BUILDPLACE/var/spool ]; then |
|---|
| 409 | mkdir -p $BUILDPLACE/var/spool |
|---|
| 410 | fi |
|---|
| 411 | } |
|---|
| 412 | |
|---|
| 413 | busybox_inittab () { |
|---|
| 414 | if [ ! -e "$BUILDPLACE/etc/inittab" ]; then |
|---|
| 415 | info INSTCORE "Adding default busybox inittab" |
|---|
| 416 | cat > $BUILDPLACE/etc/inittab << 'EOF' |
|---|
| 417 | # /etc/inittab |
|---|
| 418 | # |
|---|
| 419 | # Copyright (C) 2001 Erik Andersen <andersen@codepoet.org> |
|---|
| 420 | # |
|---|
| 421 | # Note: BusyBox init doesn't support runlevels. |
|---|
| 422 | |
|---|
| 423 | # Startup the system |
|---|
| 424 | null::sysinit:/bin/mount -o remount,rw / |
|---|
| 425 | null::sysinit:/bin/mount -t proc proc /proc |
|---|
| 426 | null::sysinit:/bin/mount -t sysfs sysfs /sys |
|---|
| 427 | null::sysinit:/bin/mount -t devpts devpts /dev/pts |
|---|
| 428 | null::sysinit:/bin/mount -a |
|---|
| 429 | null::sysinit:/bin/hostname -F /etc/hostname |
|---|
| 430 | null::sysinit:/sbin/ifconfig lo 127.0.0.1 up |
|---|
| 431 | null::sysinit:/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo |
|---|
| 432 | # now run any rc scripts and then login |
|---|
| 433 | ::sysinit:/etc/init.d/rcS |
|---|
| 434 | |
|---|
| 435 | # Set up a couple of getty's |
|---|
| 436 | tty1::respawn:/sbin/getty 38400 tty1 |
|---|
| 437 | tty2::respawn:/sbin/getty 38400 tty2 |
|---|
| 438 | |
|---|
| 439 | # Put a getty on the serial port |
|---|
| 440 | #ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100 |
|---|
| 441 | ttyS2::respawn:/sbin/getty -L ttyS2 115200 vt100 |
|---|
| 442 | |
|---|
| 443 | # Logging junk |
|---|
| 444 | null::sysinit:/bin/touch /var/log/messages |
|---|
| 445 | null::respawn:/sbin/syslogd -n -m 0 |
|---|
| 446 | null::respawn:/sbin/klogd -n |
|---|
| 447 | tty3::respawn:/usr/bin/tail -f /var/log/messages |
|---|
| 448 | |
|---|
| 449 | # Stuff to do for the 3-finger salute |
|---|
| 450 | ::ctrlaltdel:/sbin/reboot |
|---|
| 451 | |
|---|
| 452 | # Stuff to do before rebooting |
|---|
| 453 | null::shutdown:/usr/bin/killall klogd |
|---|
| 454 | null::shutdown:/usr/bin/killall syslogd |
|---|
| 455 | null::shutdown:/bin/umount -a -r |
|---|
| 456 | null::shutdown:/sbin/swapoff -a |
|---|
| 457 | |
|---|
| 458 | EOF |
|---|
| 459 | fi |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | busybox_rcS () { |
|---|
| 463 | if [ ! -d "$BUILDPLACE/etc/default" ]; then |
|---|
| 464 | mkdir -p $BUILDPLACE/etc/default |
|---|
| 465 | fi |
|---|
| 466 | if [ ! -d "$BUILDPLACE/etc/rc.d" ]; then |
|---|
| 467 | mkdir -p $BUILDPLACE/etc/rc.d |
|---|
| 468 | fi |
|---|
| 469 | if [ ! -f "$BUILDPLACE/etc/default/rcS" ]; then |
|---|
| 470 | echo "#!/bin/sh" > $BUILDPLACE/etc/default/rcS |
|---|
| 471 | echo >> $BUILDPLACE/etc/default/rcS |
|---|
| 472 | chown 0.0 "$BUILDPLACE/etc/default/rcS" |
|---|
| 473 | chmod 644 "$BUILDPLACE/etc/default/rcS" |
|---|
| 474 | fi |
|---|
| 475 | # derived from the buildroot version. |
|---|
| 476 | if [ ! -e "$BUILDPLACE/etc/init.d/rcS" ]; then |
|---|
| 477 | info INSTCORE "Adding default busybox rcS" |
|---|
| 478 | cat > $BUILDPLACE/etc/init.d/rcS << 'EOF' |
|---|
| 479 | #!/bin/sh |
|---|
| 480 | set -e |
|---|
| 481 | # Start all init scripts in /etc/rc.d/ |
|---|
| 482 | # |
|---|
| 483 | if [ ! -z "$SPAWNED" ]; then |
|---|
| 484 | /bin/login |
|---|
| 485 | fi |
|---|
| 486 | SPAWNED="$SPAWNED ." |
|---|
| 487 | export SPAWNED=\$SPAWNED |
|---|
| 488 | for i in /etc/rc.d/S??* ;do |
|---|
| 489 | # Ignore dangling symlinks (if any). |
|---|
| 490 | [ ! -f "$i" ] && continue |
|---|
| 491 | case "$i" in |
|---|
| 492 | *.sh) |
|---|
| 493 | # Source shell script for speed. |
|---|
| 494 | ( |
|---|
| 495 | trap - INT QUIT TSTP |
|---|
| 496 | set start |
|---|
| 497 | . $i |
|---|
| 498 | ) |
|---|
| 499 | ;; |
|---|
| 500 | *) |
|---|
| 501 | # No sh extension, so fork subprocess. |
|---|
| 502 | $i start |
|---|
| 503 | ;; |
|---|
| 504 | esac |
|---|
| 505 | done |
|---|
| 506 | EOF |
|---|
| 507 | chown 0.0 "$BUILDPLACE/etc/init.d/rcS" |
|---|
| 508 | chmod 0755 "$BUILDPLACE/etc/init.d/rcS" |
|---|
| 509 | fi |
|---|
| 510 | } |
|---|
| 511 | |
|---|
| 512 | # call repeatedly to create init symlinks. |
|---|
| 513 | # arg1 is the file in $BUILDPLACE/etc/init.d/ |
|---|
| 514 | # arg2 is the number for the link in the init sequence |
|---|
| 515 | # where 'foo 20' runs after 'bar 10' etc. |
|---|
| 516 | symlink_rcS () { |
|---|
| 517 | local file="$1" |
|---|
| 518 | local num="$2" |
|---|
| 519 | linkname="S$num$file" |
|---|
| 520 | if [ ! -d "$BUILDPLACE/etc/rc.d/" ]; then |
|---|
| 521 | mkdir $BUILDPLACE/etc/rc.d |
|---|
| 522 | fi |
|---|
| 523 | if [ -f $BUILDPLACE/etc/init.d/$file ]; then |
|---|
| 524 | ln -sf ../init.d/$file $BUILDPLACE/etc/rc.d/$linkname |
|---|
| 525 | fi |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | symlink_rcK () { |
|---|
| 529 | local file="$1" |
|---|
| 530 | local num="$2" |
|---|
| 531 | linkname="K$num$file" |
|---|
| 532 | if [ ! -d "$BUILDPLACE/etc/rc.d/" ]; then |
|---|
| 533 | mkdir $BUILDPLACE/etc/rc.d |
|---|
| 534 | fi |
|---|
| 535 | if [ -f $BUILDPLACE/etc/init.d/$file ]; then |
|---|
| 536 | ln -sf ../init.d/$file $BUILDPLACE/etc/rc.d/$linkname |
|---|
| 537 | fi |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | basic_etc_profile () { |
|---|
| 541 | if [ ! -e "$BUILDPLACE/etc/profile" ]; then |
|---|
| 542 | info INSTCORE "Adding a basic /etc/profile file" |
|---|
| 543 | cat > $BUILDPLACE/etc/profile << 'EOF' |
|---|
| 544 | if [ "`id -u`" -eq 0 ]; then |
|---|
| 545 | PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games/" |
|---|
| 546 | else |
|---|
| 547 | PATH="/usr/local/bin:/usr/bin:/bin:/usr/games" |
|---|
| 548 | fi |
|---|
| 549 | |
|---|
| 550 | if [ "$PS1" ]; then |
|---|
| 551 | if [ "`id -u`" -eq 0 ]; then |
|---|
| 552 | PS1='# ' |
|---|
| 553 | else |
|---|
| 554 | PS1='$ ' |
|---|
| 555 | fi |
|---|
| 556 | fi |
|---|
| 557 | |
|---|
| 558 | export PATH |
|---|
| 559 | export DISPLAY=:0 |
|---|
| 560 | umask 022 |
|---|
| 561 | |
|---|
| 562 | EOF |
|---|
| 563 | fi |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | set_cdebconf_default () { |
|---|
| 567 | info INSTCORE "Setting cdebconf as default." |
|---|
| 568 | echo "export DEBCONF_USE_CDEBCONF=true" >> $BUILDPLACE/etc/profile |
|---|
| 569 | } |
|---|
| 570 | |
|---|
| 571 | set_tslib_pointercal () { |
|---|
| 572 | info INSTCORE "Setting location of tslib calibration file." |
|---|
| 573 | echo "export TSLIB_CALIBFILE=/etc/pointercal" >> $BUILDPLACE/etc/profile |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | # this function is coded to match the sample_xorg_conf |
|---|
| 577 | # some devices might use /dev/input/event1 or event2 |
|---|
| 578 | set_tslib_tsdevice () { |
|---|
| 579 | info INSTCORE "Setting location of tslib touchscreen device." |
|---|
| 580 | echo "export TSLIB_TSDEVICE=/dev/input/event0" >> $BUILDPLACE/etc/profile |
|---|
| 581 | } |
|---|
| 582 | |
|---|
| 583 | sample_xorg_conf () { |
|---|
| 584 | if [ ! -e "$BUILDPLACE/etc/X11/xorg.conf" ]; then |
|---|
| 585 | info INSTCORE "Adding sample xorg.conf" |
|---|
| 586 | cat > $BUILDPLACE/etc/X11/xorg.conf << 'EOF' |
|---|
| 587 | # You probably want to change at least some of these |
|---|
| 588 | # lines and provide it via machine:variant customisations. |
|---|
| 589 | # This one comes from balloon3-config. |
|---|
| 590 | Section "Files" |
|---|
| 591 | FontPath "/usr/share/fonts/truetype/ttf-bitstream-vera/" |
|---|
| 592 | EndSection |
|---|
| 593 | |
|---|
| 594 | Section "InputDevice" |
|---|
| 595 | Identifier "Generic Keyboard" |
|---|
| 596 | Driver "kbd" |
|---|
| 597 | EndSection |
|---|
| 598 | |
|---|
| 599 | # /dev/input/event0 is kernel-module specific. |
|---|
| 600 | # You may need to change this. |
|---|
| 601 | Section "InputDevice" |
|---|
| 602 | Identifier "Touchscreen" |
|---|
| 603 | Driver "tslib" |
|---|
| 604 | Option "ScreenNumber" "0" |
|---|
| 605 | Option "Width" "0" |
|---|
| 606 | Option "Height" "0" |
|---|
| 607 | Option "Rotate" "NONE" |
|---|
| 608 | Option "TslibDevice" "/dev/input/event0" |
|---|
| 609 | EndSection |
|---|
| 610 | |
|---|
| 611 | Section "Device" |
|---|
| 612 | Identifier "Generic Video Card" |
|---|
| 613 | Driver "fbdev" |
|---|
| 614 | Option "UseFBDev" "true" |
|---|
| 615 | EndSection |
|---|
| 616 | |
|---|
| 617 | Section "Monitor" |
|---|
| 618 | Identifier "Configured Monitor" |
|---|
| 619 | EndSection |
|---|
| 620 | |
|---|
| 621 | Section "ServerLayout" |
|---|
| 622 | Identifier "Default Layout" |
|---|
| 623 | Screen "Default Screen" |
|---|
| 624 | InputDevice "Touchscreen" |
|---|
| 625 | EndSection |
|---|
| 626 | |
|---|
| 627 | Section "Screen" |
|---|
| 628 | Identifier "Default Screen" |
|---|
| 629 | Monitor "Configured Monitor" |
|---|
| 630 | EndSection |
|---|
| 631 | |
|---|
| 632 | EOF |
|---|
| 633 | fi |
|---|
| 634 | } |
|---|
| 635 | |
|---|
| 636 | shell_update_rcd () { |
|---|
| 637 | if [ ! -e "$BUILDPLACE/usr/sbin/update-rc.d" ]; then |
|---|
| 638 | info INSTCORE "Adding a /usr/sbin/update-rc.d shell script" |
|---|
| 639 | cp /usr/share/emdebian-tools/update-rc.d $BUILDPLACE/usr/sbin/ |
|---|
| 640 | chmod 0755 $BUILDPLACE/usr/sbin/update-rc.d |
|---|
| 641 | fi |
|---|
| 642 | } |
|---|