@ -62,7 +62,7 @@ get_dso_deps() {
}
}
inst() {
inst() {
if (($# != 2 && $# != 3));then
if (($# != 2 && $# != 3)); then
echo "usage: inst <file> <root> [<destination file>]"
echo "usage: inst <file> <root> [<destination file>]"
return 1
return 1
fi
fi
@ -70,12 +70,10 @@ inst() {
local root="${1%%/}" ; shift
local root="${1%%/}" ; shift
local dest="${1##/}"
local dest="${1##/}"
[[ $dest ]] || dest="${file##/}"
[[ $dest ]] || dest="${file##/}"
mkdir -p "$root/${dest%/*}"
mkdir -p "$root/${dest%/*}"
local RET=0
local RET=0
local target=""
local target=""
[ -L "$file" ] && target=$(readlink "$file")
[[ -L $file ]] && target=$(readlink "$file")
if [[ $target && $dest != $target ]]; then
if [[ $target && $dest != $target ]]; then
if [[ -e $root/$dest ]]; then
if [[ -e $root/$dest ]]; then
RET=0
RET=0
@ -83,25 +81,22 @@ inst() {
ln -sf "$target" "$root/$dest"
ln -sf "$target" "$root/$dest"
#inst "$target" "$root"
#inst "$target" "$root"
local BASE=${target##*/}
local BASE=${target##*/}
local LIBDIR=`echo "$file" | sed -e 's,\(\(.*\)/\)[^/]\+$,\1,'`
local LIBDIR=$(echo "$file" | sed -e 's,\(\(.*\)/\)[^/]\+$,\1,')
if [[ $LIBDIR = $BASE ]]; then
if [[ $LIBDIR = $BASE ]]; then
local LIBDIR=`echo "/$dest" | sed -e 's,\(\(.*\)/\)[^/]\+$,\1,'`
local LIBDIR=$(echo "/$dest" | sed -e 's,\(\(.*\)/\)[^/]\+$,\1,')
fi
fi
local TLIBDIR=$(echo "$target" | sed -e 's,\(^/lib[^/]*\)/.*$,\1/,' \
local TLIBDIR=`echo "$target" | sed -e 's,\(^/lib[^/]*\)/.*$,\1/,' \
-e 's,\(\(.*\)/\)[^/]\+$,\1,')
-e 's,\(\(.*\)/\)[^/]\+$,\1,'`
if [[ $TLIBDIR = $BASE ]]; then
if [[ $TLIBDIR = $BASE ]]; then
local TLIBDIR=`echo "/$dest" | sed \
local TLIBDIR=$(echo "/$dest" | sed \
-e 's,\(^/lib[^/]*\)/.*$,\1/,' \
-e 's,\(^/lib[^/]*\)/.*$,\1/,' \
-e 's,\(\(.*\)/\)[^/]\+$,\1,'`
-e 's,\(\(.*\)/\)[^/]\+$,\1,')
fi
fi
inst "$LIBDIR/$BASE" "$root" "$TLIBDIR/$BASE"
inst "$LIBDIR/$BASE" "$root" "$TLIBDIR/$BASE"
RET=$?
RET=$?
return $RET
return $RET
fi
fi
fi
fi
local SHEBANG=$(dd if="$file" bs=2 count=1 2>/dev/null)
local SHEBANG=$(dd if="$file" bs=2 count=1 2>/dev/null)
if [[ $SHEBANG = '#!' ]]; then
if [[ $SHEBANG = '#!' ]]; then
# We're intentionally not playing the "what did this moron run
# We're intentionally not playing the "what did this moron run
@ -111,7 +106,6 @@ inst() {
RET=$?
RET=$?
return $RET
return $RET
fi
fi
if [[ -e $root/$dest ]]; then
if [[ -e $root/$dest ]]; then
RET=0
RET=0
else
else
@ -120,162 +114,61 @@ inst() {
RET=$?
RET=$?
else
else
cp -aL "$file" "$root/$dest"
cp -aL "$file" "$root/$dest"
local DEPS=$(get_dso_deps "$file")
local DEPS=$(get_dso_deps "$file")
if [[ $DEPS ]]; then
if [[ $DEPS ]]; then
IF_dynamic="yes"
for x in $DEPS; do
local TLIBDIR=$(echo "$x" | sed 's,\(/lib[^/]*\)/.*$,\1,')
local BASE=$(basename "$x")
inst "$x" "$root" "$TLIBDIR/$BASE"
done
RET=$?
fi
fi
for x in $DEPS ; do
fi
local TLIBDIR=`echo "$x" | sed 's,\(/lib[^/]*\)/.*$,\1,'`
local BASE=`basename "$x"`
inst "$x" "$root" "$TLIBDIR/$BASE"
done
RET=$?
fi
fi
fi
return $RET
return $RET
}
}
# module dep finding and installation functions
modcat="/lib/modules/$kernel/modules"
moduledep() {
instmods() {
MPARGS=""
local mod mpargs modpath modname cmd
if [ "$1" == "--ignore-install" ]; then
while (($# > 0)); do
MPARGS="$MPARGS --ignore-install"
mod=${1%.ko}
shift
case $mod in
fi
=ata) instmods $mpargs $(cat "${modcat}.block" |egrep 'ata|ahci');;
deps=""
=*) instmods $mpargs $(cat "${modcat}.${mod#=}");;
deps=$(modprobe $MPARGS --set-version $kernel --show-depends $1 2>/dev/null| awk '/^insmod / { print gensub(".*/","","g",$2) }' | while read foo ; do [ "${foo%%.ko}" != "$1" ] && echo -n "${foo%%.ko} " ; done)
--*) mpargs+=" $mod";;
}
*) modprobe $mpargs --set-version $kernel --show-depends $mod \
2>/dev/null |while read cmd modpath; do
locatemodule() {
[[ $cmd = insmod ]] || continue
MPARGS=""
modname=${modpath##*/}
if [ "$1" == "--ignore-install" ]; then
modname=${modname%.ko}
MPARGS="$MPARGS --ignore-install"
[[ ${mod/-/_} != ${modname/-/_} ]] && {
shift
instmods $mpargs $modname
fi
continue
fmPath=$(modprobe $MPARGS --set-version $kernel --show-depends $1 2>/dev/null | awk '/^insmod / { print $2; }' | tail -1)
}
if [ -n "$fmPath" -a -f "$fmPath" ]; then
inst "$modpath" "$initdir" "/lib/modules/$kernel/$modname.ko"
return 0
done
fi
;;
for modExt in o.gz o ko ; do
esac
for modDir in /lib/modules/$kernel/updates /lib/modules/$kernel ; do
shift
if [ -d $modDir ]; then
fmPath=$(find $modDir -name $1.ko |awk {'print $1; exit;'})
if [ -n "$fmPath" -a -f "$fmPath" ]; then
return 0
fi
fi
done
done
done
return 1
for fw in $(/sbin/modinfo -F firmware $mod 2>/dev/null); do
}
resolveAndExpandModules() {
items=$*
mods=$(expandModules $items)
resdeps mods
echo $resolved
}
expandModules() {
items=$*
for m in $items ; do
char=$(echo $m | cut -c1)
if [ $char = '=' ]; then
NAME=$(echo $m | cut -c2-)
if [ "$NAME" = "ata" ]; then
MODS="$MODS $(cat /lib/modules/$kernel/modules.block |egrep '(ata|ahci)' |sed -e 's/.ko//')"
else
# Ignore if group list does not exist
if [ -e /lib/modules/$kernel/modules.$NAME ]; then
MODS="$MODS $(cat /lib/modules/$kernel/modules.$NAME |sed -e 's/.ko//')"
fi
fi
else
MODS="$MODS $m"
fi
done
echo $MODS
}
installmodule()
{
MPARGS=""
if [ "$1" == "--ignore-install" ]; then
MPARGS="$MPARGS --ignore-install"
shift
fi
MODULE=$1
MNTIMAGE=$2
fmPath=""
locatemodule $MPARGS $MODULE
MODULE=$fmPath
if [ -z "$MODULE" ]; then
return
fi
if [ -x /usr/bin/strip ]; then
/usr/bin/strip -g $MODULE -o $MNTIMAGE/lib/modules/$kernel/$(basename $MODULE)
else
inst "$MODULE" "$MNTIMAGE" "/lib/modules/$kernel/$(basename $MODULE)"
fi
for fw in $(/sbin/modinfo -F firmware $MODULE 2>/dev/null); do
if [ -f /lib/firmware/$fw ]; then
if [ -f /lib/firmware/$fw ]; then
inst "/lib/firmware/$fw" "$MNTIMAGE" "/lib/firmware/$fw"
inst_simple "/lib/firmware/$fw"
fi
fi
done
done
}
}
# This loops to make sure it resolves dependencies of dependencies of...
resdeps () {
modlist="$1"
before=1
after=2
items=$(eval echo \${$modlist})
while [ $before != $after ]; do
before=$(echo $items | wc -c)
list=""
for i in $items ; do
deps=""
moduledep $i
list="$list $deps"
done
items=$(for n in $items $list; do echo $n; done | sort -u)
after=`echo $items | wc -c`
done
resolved="$items"
}
findkeymap () {
findkeymap () {
local MAP=$1
local MAP=$1
[[ ! -f $MAP ]] && \
if [ ! -f "$MAP" ]; then
MAP=$(find /lib/kbd/keymaps -type f -name $MAP -o -name $MAP.\* | head -n1)
MAP=$(find /lib/kbd/keymaps -type f -name $MAP -o -name $MAP.\* | head -n1)
[[ " $KEYMAPS " = *" $MAP "* ]] && return
fi
case " $KEYMAPS " in
*" $MAP "*)
return
;;
esac
KEYMAPS="$KEYMAPS $MAP"
KEYMAPS="$KEYMAPS $MAP"
case $MAP in
case $MAP in
*.gz)
*.gz) cmd=zgrep;;
cmd=zgrep
*.bz2) cmd=bzgrep;;
;;
*) cmd=grep ;;
*.bz2)
cmd=bzgrep
;;
*)
cmd=grep
;;
esac
esac
for INCL in $($cmd "^include " $MAP | cut -d' ' -f2 | tr -d '"'); do
for INCL in $($cmd "^include " $MAP | cut -d' ' -f2 | tr -d '"'); do