]> git.draconx.ca Git - scripts.git/blob - modules.zsh
Add script to convert "JWK"-format RSA keys to normal.
[scripts.git] / modules.zsh
1 #!/usr/bin/env zsh
2 #
3 # Copyright © 2009 Nick Bowler
4 #
5 # Generate module listings for an initramfs by searching a subset of the
6 # installed modules for a particular kernel version.  Currently, all
7 # filesystem and MD drivers, plus all their (recursive) dependencies,
8 # are included.
9 #
10 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
11 # This is free software: you are free to do what the fuck you want to.
12 # There is NO WARRANTY, to the extent permitted by law.
13
14 usage() {
15         echo "usage: modules.zsh kernel-version" 1>&2
16         exit 1
17 }
18
19 out_mkdir_p() {
20         local i base path
21         base=$1
22         path=(${(s./.)2})
23
24         for i in {1..$#path}; do
25                 echo "dir  $base/${(j./.)path[1,i]} 0755 0 0"
26         done
27 }
28
29 if [ -z "$1" ]; then
30         usage
31 fi
32
33 kver=$1
34
35 moduledir=/lib/modules/$kver
36
37 if ! [ -d "$moduledir" ]; then
38         echo "module directory for kernel \`\`$kver'' does not exist." 1>&2
39         usage
40 fi
41
42 kmods=(`find $moduledir/kernel/fs $moduledir/kernel/drivers/md \
43         -type f -name '*.ko' -exec basename {} .ko \;`)
44
45 paths=()
46
47 while [ $#kmods -gt 0 ]; do
48         i=${kmods[1]}
49         kmods=(${kmods[2,-1]})
50
51         info=`modinfo -k $kver $i`
52         paths+=`echo $info | sed -n 's/^filename:[[:space:]]*//p'`
53         
54         kmods+=(${(s.,.)$(echo $info | sed -n 's/^depends:[[:space:]]*//p')})
55 done
56
57 echo "dir  $moduledir 0755 0 0"
58 echo "file $moduledir/modules.dep   $moduledir/modules.dep   0644 0 0"
59 echo "file $moduledir/modules.alias $moduledir/modules.alias 0644 0 0"
60 for i in $paths; do
61         i=${i#$moduledir/}
62         out_mkdir_p $moduledir $(dirname $i)
63         echo "file $moduledir/$i $moduledir/$i 0644 0 0"
64 done | sort -u