#!/bin/sh
# -*- mode: python -*-
# virtme-loadmods: load modules for all available devices
# Copyright © 2014 Andy Lutomirski
# Licensed under the GPLv2, which is available in the virtme distribution
# as a file called LICENSE with SHA-256 hash:
# 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643

export PATH=/bin:/sbin:/usr/bin:/usr/sbin
export TERM=linux

log() {
    if [[ -e /dev/kmsg ]]; then
	echo "<6>virtme-loadmods: $*" >/dev/kmsg
    else
	echo "virtme-loadmods: $*"
    fi
}

log 'looking for modaliases'
mods="$(find /sys/devices -type f -name modalias -print0 |xargs -0 cat |sort |uniq)"

log "requesting $(echo "$mods" |wc -w) modules"
modprobe -q -a -- $mods

log 'done'

exit 0
