LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File gen-initrd.sh of Package petitboot (Project DISCONTINUED:openSUSE:11.1)

#!/bin/bash
#set -x

# need parameter for temp initrd directory
if test -z "$1"
then
	exit 1
fi

INITRD=`pwd`/ramdisk.image.gz
myLIB=$1
DIR=`pwd`/$2

# copy files which shall be included in initrd
rm -rf $DIR
mkdir $DIR
cd $DIR
mkdir -p sbin bin lib lib64 usr etc var/tmp var/log lib/udev
mkdir -p usr/share/petitboot/artwork/ usr/bin usr/sbin mnt
mkdir -p usr/share/udhcpc

cp -aL /sbin/kexec usr/sbin/kexec.bin
cp -aL /usr/sbin/setctsid sbin/setctsid
cp -aL ../artwork usr/share/petitboot/
cp -aL ../src/.libs/petitboot-udev usr/sbin
cp -aL ../src/.libs/petitboot-gui usr/bin
#cp -aL ../src/.libs/petitboot-cui usr/bin
cp -aL /etc/udev etc 
cp -aL /usr/sbin/ps3-flash-util usr/sbin
cp -aL /usr/sbin/ps3-boot-game-os usr/sbin
cp -aL /usr/bin/ps3-video-mode usr/bin
cp -aL /usr/$myLIB/libps3-utils.so.* $myLIB
cp -aL ../lib/.libs/libpetitboot.so.0 $myLIB
cp -aL /lib/libgcc_s.so.* lib

# udev stuff
cp -avL /sbin/udevd /sbin/udevadm sbin
cp -avL /etc/udev/udev.conf etc/udev
cp -avL /usr/bin/udevinfo usr/bin
cp -avL /lib/udev/* lib/udev
cp -avL /lib/udev/rules.d/*persistent-storage.rules etc/udev/rules.d/
cp -avL /lib/udev/rules.d/*persistent-net* etc/udev/rules.d/
cp -avL ../scripts/99-petitboot.rules etc/udev/rules.d/

mv ../extract_from_elf sbin/

#FIXME: created udev rules to compensate scsi_id not exposing variables
cat > etc/udev/rules.d/95-udev-cdrom-fix.rules <<EOF
ENV{ID_CDROM}=="?*", ENV{ID_TYPE}="cd", ENV{ID_BUS}="scsi"
EOF

# create busybox symlinks
cd /usr/bin
busybox.install $DIR --symlinks
cd $DIR

# copy libraries
for i in $(for i in bin/* sbin/* usr/bin/* lib/udev/*_id ; do ldd "$i" ; done | sed -ne 's:\t\(.* => \)\?\(/.*\) (0x[0-9a-f]*):\2:p' | sort -u)
do
	mylibdir=
	case "$i" in
		*/lib/*)
		mylibdir=lib
		;;
		*/lib64/*)
		mylibdir=lib64
		;;
	esac
        cp -vL $i $mylibdir
done

# copy libraries for dns resolving
cp /$myLIB/libnss_dns.so.2 $myLIB
cp /$myLIB/libresolv.so.2 $myLIB

# flash otheros.bld
cat > sbin/flash_otheros.sh <<EOF 
#!/bin/ash
# netcat listen on port 12345 for flash image
echo listening on port 12345 for otheros.bld
nc -l -p 12345 > /otheros.bld
ps3-flash-util -w /otheros.bld
EOF

# fix reboot
rm sbin/reboot
cat > sbin/reboot <<EOF 
#!/bin/ash
echo b > /proc/sysrq-trigger
EOF

# make proper kexec call
cat > usr/sbin/kexec <<'EOF'
#!/bin/ash
set -x

INITRD=
CMD_LINE=
# last argument
INST64=
echo "$@"
for i in "$@"
do
    case "$i" in
        --command-line*)
        CMD_LINE=$i ;;
        *) INST64=$i ;;
    esac
done

extract_from_elf -i "$INST64" -e .kernel:vmlinux.strip -o /vmlinuz-$$
if [ -e /vmlinuz-$$ ]; then
        extract_from_elf -i "$INST64" -e .kernel:initrd -o /initrd-$$
        if [ -e /initrd-$$ ]; then
            INITRD="--initrd=/initrd-$$"
        fi
        kexec.bin -f /vmlinuz-$$ "$INITRD" "$CMD_LINE" 
fi
kexec.bin "$@"
EOF

# init script
cat > init <<'EOF'
#!/bin/ash
#set -x

# create device nodes and mount filesystems
mknod /dev/null c 1 3
mkdir -p /lib/udev/rules.d
mkdir -p /var/tmp/mnt
mkdir /proc
mkdir /sys
mkdir /dev/pts
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devpts devpts /dev/pts

# disable uevent helper, udevd listens to netlink
echo "" > /sys/kernel/uevent_helper

# start syslogd
syslogd -O /var/log/messages
/sbin/udevd --daemon < /dev/null > /dev/null 2>&1
# udevsettle, udevtrigger got replaced by udevadm
/sbin/udevadm trigger
/sbin/udevadm settle --timeout=5
# create some more terminals
openvt -c 2 /bin/ash
openvt -c 3 /bin/ash
openvt -c 4 /bin/ash
openvt -c 5 /bin/ash
openvt -c 6 /bin/ash
openvt -c 8 /usr/bin/tail -f /var/log/messages
# openvt -c 9 /sbin/flash_otheros.sh

# check for dhcp
udhcpc -i eth0 -n -q

# enable telnetd for debugging (possible security risk)
# telnetd -l /bin/ash

# switch videomode to 720p
# ps3-video-mode -v 3

while true; do
	petitboot-gui
	if [ $? -eq 1 ]; then
		petitboot-gui
	else
		/bin/ash
	fi
done
EOF

cat > usr/share/udhcpc/default.script <<'EOF'
#!/bin/ash
#set -x

[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1

if [ "$1" = deconfig ] ; then
	ifconfig $interface 0.0.0.0
fi

if [ "$1" = bound ] ; then
	ip link set eth0 up
	ifconfig $interface $ip netmask $subnet
	route add default gw $router dev $interface
	echo $hostname > /etc/hosts
	echo "domain $domain" > /etc/resolv.conf
	echo "nameserver $dns" >> /etc/resolv.conf
	
	exit 0
fi
EOF
chmod 755 usr/share/udhcpc/default.script

chmod 755 init sbin/* bin/* usr/sbin/*
du -s .
find . -type f -print0 | xargs -0 strip --strip-debug -R .comment
du -s .

# create initrd
find . ! -name "*~" | cpio -H newc --create | gzip -9 > $INITRD