#!/bin/bash ## hwdetection, needs >= sys-apps/hwinfo # get_hwinfo $hw_item get_hwinfo() { local item="$1" local all local i all=$(hwinfo --short --"${item}") declare -i i=0 while read device description do # skip the first line (( i++ )) [ ${i} -eq 1 ] && continue echo "${device};${description}" done <<< "${all}" } # get_driver_modules $hw_item get_driver_modules() { local item="$1" local modules # being little tricky here :) # does following: # grep: # -> 'Driver Modules: "via82cxxx", "ide_cd"' # cut: # -> ' "via82cxxx", "ide_cd"' # sed1: # -> ' modules="via82cxxx", "ide_cd"' # sed2: # -> ' modules="via82cxxx ide_cd"' # then evaluate -> eval modules="via82cxxx ide_cd" # and we get a variable $modules with all mods #eval $(hwinfo --"${item}" | grep "Driver Modules:" | cut -d: -f2 | sed -e "s:\":modules=\":" -e "s:\",\ \":\ :") local i for i in $(hwinfo --"${item}" | grep "Driver Modules:" | cut -d: -f2 ) do eval $(echo "${i}" | sed -e "s:\":modules=\"\${modules}\ :" -e "s:\",\ \":\ :") done echo "${modules}" } # remove_duplicates $list remove_duplicates() { local list="$@" local fixed_list=":" local i for i in ${list} do if [[ -z $(echo "${fixed_list}" | fgrep ":${i}:") ]] then fixed_list="${fixed_list}${i}:" fi done # remove all ':' and show the cleaned list # this way fixes double spaces also for i in $(echo ${fixed_list} | sed "s|:| |g") do echo "${i}" done } get_x11_driver_modules() { local modules modules="$(hwinfo --gfxcard | grep "XFree86 v4 Server Module:" | cut -d: -f2)" # remove duplicates from list and show it remove_duplicates "${modules}" } # create_initrd {/path/to/initrd kernelversion } # when nothing given then /boot/initrd-$(uname -r).img $(uname -r) will be used # default config path is /etc/conf.d/mkinitrd create_initrd() { local initrd="$1" local kernel="$2" local config="$3" local modules [[ -z ${initrd} ]] && initrd="/boot/initrd-$(uname -r).img" [[ -z ${kernel} ]] && kernel="$(uname -r)" [[ -z ${config} ]] && config="/etc/conf.d/mkinitrd" # get various modules needed to boot modules="${modules} $(get_driver_modules disk)" modules="${modules} $(get_driver_modules scsi)" modules="${modules} $(get_driver_modules cdrom)" # remove all duplicate modules modules="$(remove_duplicates ${modules})" # create the config and an initrd echo "# autogenerated config file" > ${config} echo "MODULES=\"${modules}\"" >> ${config} echo "IMAGE_TYPE=\"initramfs\"" >> ${config} mkinitrd -f ${initrd} ${kernel} } # special: memory (size), floppy (modprobe floppy), smp (support y/n) # sound (which module? -> eval $(hwinfo --sound | grep "Driver Modules:" | cut -d: -f2 | sed s:\":a=\":) ) # # for i in cdrom cpu disk floppy gfxcard keyboard memory monitor mouse # netcard pppoe scsi smp \ # sound wlan # do # echo -------- ${i} # get_hwinfo ${i} # echo ------------------------------------------------- # echo # done # get_driver_modules sound # get_driver_modules wlan # get_driver_modules cdrom # get_driver_modules disk # get_driver_modules gfxcard # get_x11_driver_modules # # get a modules list # for i in sound wlan cdrom disk gfxcard # do # ALL_MODULES="${ALL_MODULES} $(get_driver_modules ${i})" # done # ALL_MODULES="${ALL_MODULES} $(get_x11_driver_modules)" # # show a clean list # for i in $(remove_duplicates ${ALL_MODULES}) # do # echo ${i} # done #create_initrd /root/TEST/initrd #get_driver_modules cdrom #get_driver_modules disk #get_driver_modules scsi #get_driver_modules all # network #get_hwinfo netcard #get_driver_modules netcard #get_hwinfo disk #get_hwinfo partition | grep /dev/hda