#!/bin/bash ## fix genkernel initrd ## adding PNP ## (c) Denis Kaganovich ## under Anarchy license #FILES="/bin/busybox" FILES="/bin/busybox /sbin/blkid" DATA="/usr/share/genpnprd" #UROOT="$ROOT" UROOT="" home="`pwd`" PNPONLY=false GENKERNEL=true STATIC=false LIBLOOP=true MAKEOPTS="-j2 -s" PNPMODE= PKGFILES= PACKAGES= OVERLAY= IMAGE= CLEAN= CRAMFS= LZMA= COMPRESS= susp_sig= SQUASH=false THIN="/drivers/net/\|/cifs/\|/nfs/\|/unix\|/packet/af_packet" THIN_INFO="/fs/\|^alias:.*:\|/unix\|/packet/af_packet" preserve="/bin/busybox /bin/mount /bin/sh /bin/uname /sbin/mdev /bin/zcat" : ${TMPDIR:="$ROOT/var/tmp"} tmp="$TMPDIR/genpnprd.$$" #tmp=`mktemp -d` die(){ echo "Error $*" caller # rm "$tmp" -Rf exit 1 } genpkg(){ "$1" "$2" "$3" "$4" "$5" } _modlst(){ for m in $* ; do if $PNPONLY; then modalias "${m//-/_}" && echo "$ALIAS" else m="${m//[_-]/[_-]}" grep "/$m\..*:" "${mm}/modules.dep" || find "${mm}" -name "$m.ko" fi done|sort -u } preserve_start(){ echo "Preserving unpacked /lib" local m mm="$rcdir/lib/modules/${KV}" d $PNPONLY && { source "$mm/modules.alias.sh" || die "Broken modules.alias.sh, check mod2sh.pl!" } _modlst "${@}" >>"$tmp/modules.lst" for m in `cat $rcdir/etc/modflags/*`; do [[ -z "`_modlst "$m"`" ]] && sed -i -e "/^$m\$/d" $rcdir/etc/modflags/* done for m in $rcdir/etc/modflags/*; do [[ -s "$m" ]] || rm "$m" done if [[ -n "${THIN#-}" ]]; then _modlst $(find "$mm" -name "*.ko*"|grep "$THIN"|while read m; do modinfo --basedir=/dev/null "$m"|grep -q "$THIN_INFO" && echo "$m" done|sed -e 's:^.*/::g' -e 's:\..*$::g') >>"$tmp/modules2.lst" fi cd "$rcdir" || die mkdir "$tmp/preserve" || die cd "lib/modules/$KV" if grep -qx CONFIG_FW_LOADER_COMPRESS=y "$S/.config" && mv "$rcdir/lib/firmware" "$tmp/preserve/"; then ln -s ../firmware "$rcdir"/lib/firmware elif grep -qx CONFIG_CFG80211=y "$S"/.config; then grep -qx CONFIG_CFG80211_CERTIFICATION_ONUS=y "$S"/.config && preserve+=' /lib/firmware/regulatory.db' && ! grep -qx '# CONFIG_CFG80211_REQUIRE_SIGNED_REGDB is not set' "$S"/.config && preserve+=' /lib/firmware/regulatory.db.p7s' fi echo "$preserve" >"$tmp/preserve.lst" for m in `cat $tmp/modules.lst` ; do m="${m%:}" echo "/lib/modules/$KV/${m#*/lib/modules/$KV/}" >>"$tmp/preserve.lst" $PNPONLY || ( [[ -e "$mm/modules.dep" ]] && grep "^$m:" "$mm/modules.dep" >>"$tmp/_modules.dep" ) done local i # think more... for i in "$rcdir" "$UROOT"; do ROOT="$i" bash "$UROOT/usr/share/genpnprd/genpkgrd" "$tmp/preserve" "$(cat "$tmp/preserve.lst")" >/dev/null done mv "$tmp/_modules.dep" "$tmp/preserve/lib/modules/${KV}/modules.dep" 2>/dev/null $PNPONLY || /usr/bin/perl "$UROOT/usr/share/genpnprd/mod2sh.pl" "$tmp/preserve/lib/modules/${KV}" cd "$rcdir" if ! $LIBLOOP; then mv "$rcdir"/{etc,sys,proc,dev} "$tmp/preserve/" || die mv "$rcdir"/kernel "$tmp/preserve/" find .|sort|while read m; do [[ "$m" == ./* ]] || continue m="${m#./}" if ! [[ -e "$tmp/preserve/$m" ]]; then # [[ -f "$m" ]] || continue [[ -L "$m" ]] && cp "$m" "$tmp/preserve" --parents -a fi ### UNSURE about possibility async direct fw loa [[ "$m" == lib/firmware/* ]] && continue [[ -e "$tmp/preserve/$m" ]] && rm "$m" 2>/dev/null done fi } preserve_end(){ local i d # gentoo no-multilib: /lib + /lib64; my: /lib + symlink. respect all cp -a "$tmp"/preserve/lib* "$rcdir/" || for i in "$tmp"/preserve/lib*; do d="$rcdir/${i##*/}" [ -L "$d" ] && rm "$d" mv "$i" "$rcdir/" -f || mv "$i"/* "$d/" -f || cp -a "$i" "$rcdir/" || die "error append $i to $rcdir" done rm "$tmp/preserve" -Rf } squashfs_enabled(){ [[ "$CRAMFS" != 1 ]] && ( [[ -e "$rcdir/lib/modules/$KV/kernel/fs/squashfs" ]] || ( [[ -d "$S" ]] && grep -sq "^CONFIG_SQUASHFS" "$S/.config" ) ) return $? } kmake(){ make -C "$S" $* $MAKEOPTS || die } clean(){ for i in $CLEAN; do case "$i" in "@"*) while read j; do j=`readlink -f "$rcdir/$j"` || continue [[ "${j#$rcdir/}" == "$j" ]] && continue rm "$j" done <"${i#?}" continue ;; esac i=`readlink -f "$rcdir/$i"` || continue [[ "${i#$rcdir/}" == "$i" ]] && continue rm "$i" -Rf done } IMAGE="" PNPMODE="" OVERLAY="" S="" KV="" echo "Run: $0 $*" i=0 while [[ -n "$*" ]]; do case "$1" in --*) x="${1#--}" shift export $x="$1" ;; *) let i=i+1 case $i in 1)IMAGE="$1";; 2)PNPMODE="$1";; 3)OVERLAY="$1";; 4)S="$1";; esac ;; esac shift done [[ -z "$IMAGE" ]] && { echo "Usage: $0 [nopnp|pnponly|pnp [ [sources]]] or $0 {--