initial commit

This commit is contained in:
josch 2014-06-26 09:38:43 +02:00
commit cd615ef0c7
4 changed files with 478 additions and 0 deletions

201
ldd.pl Executable file
View file

@ -0,0 +1,201 @@
#!/usr/bin/perl
# fakeldd
#
# Replacement for ldd with usage of objdump
#
# (c) 2003-2010 Piotr Roszatycki <dexter@debian.org>, LGPL
use strict;
my @Libs = ();
my %Libs = ();
my $Status = 0;
my $Dynamic = 0;
my $Format = '';
my $Ldsodir = "/lib";
my @Ld_Library_Path = qw(/usr/lib /lib /usr/lib32 /lib32 /usr/lib64 /lib64);
sub ldso {
my ($lib) = @_;
return if $Libs{$lib};
my $path;
if ($lib =~ /^\//) {
$path = $lib;
}
else {
foreach my $dir (@Ld_Library_Path) {
next unless -f "$dir/$lib";
my $badformat = 0;
local *PIPE;
open PIPE, "objdump -p '$dir/$lib' 2>/dev/null |";
while (my $line = <PIPE>) {
if ($line =~ /file format (\S*)$/) {
$badformat = 1 unless $1 eq $Format;
last;
}
}
close PIPE;
next if $badformat;
$path = "$dir/$lib";
last;
}
}
push @Libs, $lib;
if (-f $path) {
$Libs{$lib} = $path;
objdump($path);
}
}
sub objdump {
my (@files) = @_;
foreach my $file (@files) {
local *PIPE;
open PIPE, "objdump -p '$file' 2>/dev/null |";
while (my $line = <PIPE>) {
$line =~ s/^\s+//;
if ($line =~ /file format (\S*)$/) {
if (not $Format) {
$Format = $1;
if ($^O eq 'linux') {
if ($Format =~ /^elf64-/) {
push @Libs, 'linux-vdso.so.1';
$Libs{'linux-vdso.so.1'} = '';
}
else {
push @Libs, 'linux-gate.so.1';
$Libs{'linux-gate.so.1'} = '';
}
}
foreach my $lib (split /:/, $ENV{LD_PRELOAD}||'') {
ldso($lib);
}
}
else {
next unless $Format eq $1;
}
}
if (not $Dynamic and $line =~ /^Dynamic Section:/) {
$Dynamic = 1;
}
next unless $line =~ /^ \s* NEEDED \s+ (.*) \s* $/x;
my $needed = $1;
if ($needed =~ /^ld(-linux)?(\.|-)/) {
$needed = "$Ldsodir/$needed";
}
ldso($needed);
}
close PIPE;
}
}
sub load_ldsoconf {
my ($file) = @_;
local *FH;
open FH, $file;
while (my $line = <FH>) {
chomp $line;
$line =~ s/#.*//;
next if $line =~ /^\s*$/;
if ($line =~ /^include\s+(.*)\s*/) {
my $include = $1;
foreach my $incfile (glob $include) {
load_ldsoconf($incfile);
}
next;
}
unshift @Ld_Library_Path, $line;
}
close FH;
}
MAIN: {
my @args = @ARGV;
if (not @args) {
print STDERR "fakeldd: missing file arguments\n";
exit 1;
}
if (not `which objdump`) {
print STDERR "fakeldd: objdump: command not found: install binutils package\n";
exit 1;
}
load_ldsoconf('/etc/ld.so.conf');
unshift @Ld_Library_Path, split(/:/, $ENV{LD_LIBRARY_PATH}||'');
while ($args[0] =~ /^-/) {
my $arg = $args[0];
shift @ARGV;
last if $arg eq "--";
}
foreach my $file (@args) {
%Libs = ();
$Dynamic = 0;
if (@args > 1) {
print "$file:\n";
}
if (not -f $file) {
print STDERR "ldd: $file: No such file or directory\n";
$Status = 1;
next;
}
objdump($file);
if ($Dynamic == 0) {
print "\tnot a dynamic executable\n";
$Status = 1;
}
elsif (scalar %Libs eq "0") {
print "\tstatically linked\n";
}
my $address = '0x' . '0' x ($Format =~ /^elf64-/ ? 16 : 8);
foreach my $lib (@Libs) {
if ($lib =~ /^\//) {
printf "\t%s (%s)\n", $lib, $address;
}
elsif (defined $Libs{$lib}) {
printf "\t%s => %s (%s)\n", $lib, $Libs{$lib}, $address;
}
else {
printf "\t%s => not found\n", $lib;
}
}
}
}
END {
$? = $Status;
}

84
ldd.sh Executable file
View file

@ -0,0 +1,84 @@
#!/bin/sh -xe
ld_lib_path="/usr/lib /lib /usr/lib32 /lib32 /usr/lib64 /lib64"
lib_put () { eval lib_"$1"="$2"; }
lib_get () { eval echo \$lib_"$1"; }
dump()
{
objdump -p "$1" 2>/dev/null | while read line; do
case $line in
*file\ format*)
;;
Dynamic\ Section:)
;;
*NEEDED*)
lib=${line#*NEEDED}
lib_put $lib none
echo $lib
;;
esac
done
}
load_ldsoconf()
{
while read line; do
line=${line%%#*}
if [ "$line" = "" ]; then
continue
fi
case $line in include*)
line=${line#include}
for incl in $line; do
load_ldsoconf $incl
done
continue
;;
esac
ld_lib_path=$ld_lib_path" $line"
done < "$1"
}
if [ "$#" -eq 0 ]; then
echo $0: missing argument
exit 1
fi
OBJDUMP=`which objdump`
if [ "$?" -ne 0 ]; then
echo $0: objdump: command not found - install binutils packages
exit 1
fi
load_ldsoconf /etc/ld.so.conf
ld_lib_path=$LD_LIBRARY_PATH" $ld_lib_path"
for path in $ld_lib_path; do
if [ -d $path ]; then
ld_tmp=$ld_tmp" $path"
fi
done
ld_lib_path=$ld_tmp
for file in "$@"; do
if [ "$#" -gt 1 ]; then
echo "$file:"
fi
if [ ! -f "$file" ]; then
echo "ldd: $file: No such file or directory" >&2
continue
fi
for lib in `dump "$file"`; do
echo lib_get $lib
done
done

30
multistrap.conf Normal file
View file

@ -0,0 +1,30 @@
[General]
#arch=armhf
arch=armel
directory=debian-sid-multistrap
cleanup=true
unpack=true
noauth=true
#bootstrap=Debian_bootstrap Debian_unreleased
bootstrap=Debian_bootstrap
aptsources=Debian
allowrecommends=false
addimportant=false
[Debian_bootstrap]
packages=linux-image-kirkwood openssh-server apt locales less vim wget module-init-tools procps man-db iputils-ping dhcp3-client iproute curl vpnc rsync ifupdown net-tools binutils
source=http://127.0.0.1:3142/ftp.de.debian.org/debian
suite=sid
omitdebsrc=true
#[Debian_unreleased]
#packages=linux-image-kirkwood openssh-server apt locales less vim wget module-init-tools procps man-db iputils-ping dhcp3-client iproute curl vpnc rsync ifupdown net-tools binutils
#source=http://127.0.0.1:3142/ftp.de.debian.org/debian
#suite=unreleased
#omitdebsrc=true
[Debian]
source=http://ftp.de.debian.org/debian
keyring=debian-archive-keyring
suite=sid
omitdebsrc=true

163
rootstock.sh Executable file
View file

@ -0,0 +1,163 @@
#!/bin/sh -ex
if [ "$LOGNAME" = "root" ] \
|| [ "$USER" = "root" ] \
|| [ "$USERNAME" = "root" ] \
|| [ "$SUDO_COMMAND" != "" ] \
|| [ "$SUDO_USER" != "" ] \
|| [ "$SUDO_UID" != "" ] \
|| [ "$SUDO_GID" != "" ]; then
echo "don't run this script as root - there is no need to"
exit
fi
if [ "$FAKEROOTKEY" = "" ]; then
echo "re-executing script inside fakeroot"
fakeroot $0;
exit
fi
DIST="sid"
ROOTDIR="debian-$DIST-multistrap"
MIRROR="http://127.0.0.1:3142/ftp.de.debian.org/debian"
MIRROR_REAL="http://ftp.de.debian.org/debian"
#MIRROR="http://127.0.0.1:3142/ftp.debian-ports.org/debian"
#MIRROR_REAL="http://ftp.debian-ports.org/debian"
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C
rm -rf $ROOTDIR $ROOTDIR.tar
PACKAGES="linux-image-kirkwood openssh-server apt locales less vim wget"
PACKAGES=$PACKAGES" module-init-tools procps man-db iputils-ping dhcp3-client"
PACKAGES=$PACKAGES" iproute curl vpnc rsync ifupdown net-tools binutils"
cat > multistrap.conf << __END__
[General]
#arch=armhf
arch=armel
directory=$ROOTDIR
cleanup=true
unpack=true
noauth=true
#bootstrap=Debian_bootstrap Debian_unreleased
bootstrap=Debian_bootstrap
aptsources=Debian
allowrecommends=false
addimportant=false
[Debian_bootstrap]
packages=$PACKAGES
source=$MIRROR
suite=$DIST
omitdebsrc=true
#[Debian_unreleased]
#packages=$PACKAGES
#source=$MIRROR
#suite=unreleased
#omitdebsrc=true
[Debian]
source=$MIRROR_REAL
keyring=debian-archive-keyring
suite=$DIST
omitdebsrc=true
__END__
multistrap -f multistrap.conf
cp /usr/bin/qemu-arm-static $ROOTDIR/usr/bin
# stop invoke-rc.d from starting services
cat > $ROOTDIR/usr/sbin/policy-rc.d << __END__
#!/bin/sh
echo "sysvinit: All runlevel operations denied by policy" >&2
exit 101
__END__
chmod +x $ROOTDIR/usr/sbin/policy-rc.d
# fix for ldconfig inside fakechroot
mv $ROOTDIR/sbin/ldconfig $ROOTDIR/sbin/ldconfig.REAL
mv $ROOTDIR/usr/bin/ldd $ROOTDIR/usr/bin/ldd.REAL
ln -s ../bin/true $ROOTDIR/sbin/ldconfig
# get fake ldd (needs objdump from binutils) for mkinitramfs
# https://github.com/fakechroot/fakechroot/raw/master/scripts/ldd.pl
curl http://mister-muffin.de/p/a3Dt > $ROOTDIR/usr/bin/ldd
chmod +x $ROOTDIR/usr/bin/ldd
# supply ld.so.conf for fake ldd (running libc6 postinst script will fail)
echo "include /etc/ld.so.conf.d/*.conf" > $ROOTDIR/etc/ld.so.conf
# set ROOT for mkinitramfs
echo "ROOT=UUID=9eada77a-5f84-49a4-838e-06abe95c8513" > $ROOTDIR/etc/initramfs-tools/conf.d/root
# do not generate ssh host keys
mkdir -p $ROOTDIR/etc/ssh/
touch "$ROOTDIR/etc/ssh/ssh_host_rsa_key"
touch "$ROOTDIR/etc/ssh/ssh_host_dsa_key"
touch "$ROOTDIR/etc/ssh/ssh_host_ecdsa_key"
cat > $ROOTDIR/tmp/debconfseed.txt << __END__
# put debconf options here
__END__
fakechroot chroot $ROOTDIR debconf-set-selections /tmp/debconfseed.txt
rm $ROOTDIR/tmp/debconfseed.txt
# run preinst scripts
for script in $ROOTDIR/var/lib/dpkg/info/*.preinst; do
[ "$script" = "$ROOTDIR/var/lib/dpkg/info/bash.preinst" ] && continue
fakechroot chroot $ROOTDIR ${script##$ROOTDIR} install
done
# run dpkg --configure -a twice because of errors during the first run
fakechroot chroot $ROOTDIR /usr/bin/dpkg --configure -a || fakechroot chroot $ROOTDIR /usr/bin/dpkg --configure -a
fakechroot chroot $ROOTDIR update-locale LANG=en_US.UTF-8 LANGUAGE=en_US:en
echo en_US.UTF-8 UTF-8 > $ROOTDIR/etc/locale.gen
fakechroot chroot $ROOTDIR locale-gen
cat > $ROOTDIR/etc/fstab << __END__
# <file system> <mount point> <type> <options> <dump> <pass>
rootfs / auto defaults,errors=remount-ro,noatime 0 1
proc /proc proc defaults 0 0
tmpfs /tmp tmpfs defaults,noatime 0 0
tmpfs /var/lock tmpfs defaults,noatime 0 0
tmpfs /var/run tmpfs defaults,noatime 0 0
tmpfs /var/log tmpfs defaults,noatime 0 0
tmpfs /etc/network/run tmpfs defaults,noatime 0 0
__END__
echo kirkwood > $ROOTDIR/etc/hostname
cat > $ROOTDIR/etc/hosts << __END__
127.0.0.1 localhost
127.0.0.1 kirkwood
__END__
# activate a tty on serial
echo "T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100" >> $ROOTDIR/etc/inittab
sed -i 's/\(root:\)[^:]*\(:\)/\1'`openssl passwd -crypt -salt // "" | sed 's/\(\/\|\\\|&\)/\\&/g'`'\2/' $ROOTDIR/etc/shadow
sed -i 's/\(PermitEmptyPasswords\) no/\1 yes/' $ROOTDIR/etc/ssh/sshd_config
echo 'APT::Install-Recommends "0";' > $ROOTDIR/etc/apt/apt.conf.d/99no-install-recommends
echo 'Acquire::PDiffs "0";' > $ROOTDIR/etc/apt/apt.conf.d/99no-pdiffs
mkimage -A arm -O linux -T kernel -C none -n uImage -a 0x00008000 -e 0x00008000 -d $ROOTDIR/boot/vmlinuz-*-kirkwood $ROOTDIR/boot/uImage
mkimage -A arm -O linux -T ramdisk -C none -n uInitrd -d $ROOTDIR/boot/initrd.img-*-kirkwood $ROOTDIR/boot/uInitrd
#cleanup
rm $ROOTDIR/sbin/ldconfig $ROOTDIR/usr/bin/ldd
mv $ROOTDIR/sbin/ldconfig.REAL $ROOTDIR/sbin/ldconfig
mv $ROOTDIR/usr/bin/ldd.REAL $ROOTDIR/usr/bin/ldd
rm $ROOTDIR/usr/sbin/policy-rc.d
rm $ROOTDIR/etc/ssh/ssh_host_*
cp /etc/resolv.conf $ROOTDIR/etc/resolv.conf
# need to generate tar inside fakechroot so that absolute symlinks are correct
fakechroot chroot $ROOTDIR tar -cf $ROOTDIR.tar -C / .
mv $ROOTDIR/$ROOTDIR.tar .
tar --delete -f $ROOTDIR.tar ./usr/bin/qemu-arm-static
rm $ROOTDIR/usr/bin/qemu-arm-static