# $Id$ ## hwdetection, needs >= sys-apps/hwinfo # hwinfo wrapper to use hwinfo with sudo if requested hwinfo() { local use_sudo="" case ${SUDO} in yes|y|true|1) use_sudo=sudo ;; esac ${use_sudo} /usr/sbin/hwinfo $@ } # get_hwinfo $hw_item get_hwinfo() { local enable_desc="0" if [[ $1 = --with-description ]] || [[ $1 = -d ]] then enable_desc=1 shift fi local item="$1" local all local i # handle special items case ${item} in memory) get_hwinfo_memory; return ;; smp) get_hwinfo_smp; return ;; esac all=$(hwinfo --short --"${item}") declare -i i=0 while read device description do # skip the first line (( i++ )) [ ${i} -eq 1 ] && continue if [[ ${enable_desc} = 1 ]] then echo "${device};${description}" else echo "${device}" fi done <<< "${all}" } # special memory case get_hwinfo_memory() { local memory=$(hwinfo --memory | grep "Memory Size" | cut -d: -f2 | sed "s:\ ::") echo "${memory}" } # special smp case get_hwinfo_smp() { local smp=$(hwinfo --smp | grep "SMP support:" | cut -d: -f2 | sed "s:\ ::") echo "${smp}" } # 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 remove_duplicates "${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 unset list # remove all ':' and show the cleaned list # this way fixes double spaces also local counter declare -i counter=0 for i in $(echo ${fixed_list} | sed "s|:| |g") do (( counter++ )) if [[ ${counter} -eq 1 ]] then list="${i}" else list+=" ${i}" fi done echo "${list}" } get_x11_driver_modules() { local modules modules="$(hwinfo --gfxcard | grep 'XFree86 v4 Server Module:' | sed 's/.*Module:\ \(.*\)/\1/')" # remove duplicates from list and show it remove_duplicates "${modules}" } # get_netcard_driver_modules device # e.g. get_netcard_driver_modules eth0 get_netcard_driver_modules() { local device="$1" local modules if [[ -z ${device} ]] then echo "Error: get_netcard_driver_module(): no device given" return 1 fi modules=$(hwinfo --netcard | grep -B1 "Device File: ${device}" | sed 's/.*Modules: \"\(.*\)\"/\1/;q') remove_duplicates "${modules}" } get_blkid_information() { local partition="$1" local variable="$2" local method case $1 in --uuid|-u) shift; method="-U"; partition="$1"; variable="$2" ;; --label|-l) shift; method="-L"; partition="$1"; variable="$2" ;; esac if [[ -z ${partition} ]] then echo "Error: get_get_blkid_information()(): no partition given" return 1 fi if [[ -z ${variable} ]] then echo "Error: get_get_blkid_information()(): no variable given" return 1 fi blkid -o value -s "${variable}" "${method}" "${partition}" } get_fstype() { local partition="$1" if [[ -z ${partition} ]] then echo "Error: get_fstype(): no partition given" return 1 fi # does not work with uuids #mount -f --guess-fstype ${partition} get_blkid_information ${partition} TYPE } get_uuid() { local partition="$1" if [[ -z ${partition} ]] then echo "Error: get_uuid(): no partition given" return 1 fi # does not work with uuids #mount -f --guess-fstype ${partition} get_blkid_information ${partition} UUID } # 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 local kernel local config local chroot #local root local modules # enabled framebuffer modules as default local framebuffer=1 # very basic getops for i in $* do case $1 in #--root|-r) shift; root="$1" ;; --initrd|-i) shift; initrd="$1" ;; --config|-c) shift; config="$1" ;; --kernelversion|-v) shift; kernel="$1" ;; --nofb) shift; framebuffer=0 esac shift done [[ -z ${initrd} ]] && initrd="/boot/initrd-$(uname -r).img" [[ -z ${kernel} ]] && kernel="$(uname -r)" [[ -z ${config} ]] && config="/etc/conf.d/mkinitrd" if [[ ! -z ${INSTALL_ROOT} ]] then config="${INSTALL_ROOT}/${config}" chroot="chrooted" fi # get various modules needed to boot modules="$(get_driver_modules disk)" modules+=" $(get_driver_modules scsi)" modules+=" $(get_driver_modules cdrom)" # check for special ide_disk drivers (ata support) if [[ ! -z $(echo ${modules} | grep ide_disk) ]] then modules+=" $(grep ide_disk /proc/modules | cut -d' ' -f4 | sed '/-/d;s:,:\ :g')" fi # add some generic modules modules+=" sg_mod sg loop sr_mod sd_mod ide-cd ide-cd_mod ide-disk" # add generic framebuffer modules [[ ${framebuffer} = 1 ]] && modules+=" uvesafb" # 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} ${chroot} mkinitrd -f ${initrd} ${kernel} } chrooted() { local cmd="$@" mount -t sysfs sysfs ${INSTALL_ROOT}/sys mount -t proc proc ${INSTALL_ROOT}/proc mount -o bind /dev ${INSTALL_ROOT}/dev chroot ${INSTALL_ROOT} ${cmd} umount ${INSTALL_ROOT}/dev umount ${INSTALL_ROOT}/proc umount ${INSTALL_ROOT}/sys }