#!/bin/sh
#210314 sfs
m="fuse isofs usbhid zram aufs overlay squashfs fat ext"
m1="Arch Linux Kernel module ($m) info"
[ ! "$1" ] && echo "$m1 
    Use: 
		$0 linux*.pkg*
		$0 linux-dir" && exit 1 
k="$1"
echo "$m1:"
if [ -f "$k" ] ;then
    b="`tar -tf "$k" |egrep 'modules.builtin$'`"
    t="/tmp/`basename "$k"`/"
    mkdir -p "$t"
    tar -xf "$k" -C "$t"  "$b" 
#tar -tvf "$k" |egrep '/fs/aufs/$|/fs/overlayfs/$'
echo "=== Modules =====" &&
tar -tf "$k" |awk '/\/fs\/aufs\/$/ || /\/fs\/overlayfs\/$/ || /\/fs\/fat\/$/ \
    || /\/fs\/ext[1-9]\/$/ \
    || /\/fs\/squashfs\/$/ \
    || /\/fs\/fuse\/$/ \
    || /\/block\/zram\/$/ \
    || /\/hid\/usbhid\/$/ \
    || /\/fs\/isofs\/$/ \
    {system("basename " $0)}' |sort
#    {print $0}' 

elif [ -d "$k" ] ;then
    b="`find "$k" |egrep 'modules.builtin$'`"
echo "=== Modules =====" &&
find "$k" |awk '/\/fs\/aufs$/ || /\/fs\/overlayfs$/ || /\/fs\/fat$/ \
    || /\/fs\/ext[1-9]$/ \
    || /\/fs\/squashfs$/ \
    || /\/fs\/fuse$/ \
    || /\/block\/zram$/ \
    || /\/hid\/usbhid$/ \
    || /\/fs\/isofs$/ \
    {system("basename " $0)}' |sort
#    {print $0}' 


else echo "$1 not found" && exit 1
fi
    echo "=== BuiltIn =====" 
    awk '/aufs/ || /overlay/ || /usbhid/ || /zram/ || /fuse/ || /isofs/ || /squashfs/ || /fat/ || /ext[1-9]/ {system("basename " $0 " .ko")}' "$t$b"
#    awk '/aufs/ || /overlay/ || /squashfs/ || /fat/ || /ext[1-9]/ {print $0}' "$t/$b"
#    egrep 'aufs|overlay|squashfd|fat|ext[1-9]' "$t/$b"
[ -d "$t" ] && rm -R "$t"

