]> git.draconx.ca Git - scripts.git/blob - libs.sh
Add script to convert "JWK"-format RSA keys to normal.
[scripts.git] / libs.sh
1 #!/bin/zsh
2 #
3 # Copyright (C) 2009 Nick Bowler
4 # Copying and distribution of this file, with or without modification,
5 # are permitted in any medium without royalty provided the copyright
6 # notice and this notice are preserved.  This file is offered as-is,
7 # without any warranty.
8 #
9 # Determine library dependencies for dynamically linked binaries and output
10 # directives suitable for gen_init_cpio to include all required libraries
11 # in an initramfs archive.  Users of this script will probably need to adjust
12 # the BASE, LDD and LOADER variables appropriately.
13
14 # Directory in which the libraries are located.
15 BASE=/usr/x86_64-pc-linux-uclibc
16
17 # How to run ldd.  The uClibc dynamic loader explodes wonderfully if
18 # LD_LIBRARY_PATH is not set correctly.
19 LDD="LD_LIBRARY_PATH=$BASE/lib:$BASE/usr/lib x86_64-pc-linux-uclibc-ldd"
20
21 # Where the dynamic loader is located.  Always included in the output.
22 LOADER="/lib/ld64-uClibc.so.0"
23
24 getlibs() {
25         local file=$1
26
27         if test -u "$1" -o -g "$1"; then
28                 file=`mktemp`
29                 cp -f "$1" "$file"
30         fi
31
32         eval "$LDD '$file'" | sed -n 's/.*=> \(.*\) (0x[[:xdigit:]]*)/\1/p'
33
34         if [ "$file" != "$1" ]; then
35                 rm -f "$file"
36         fi
37 }
38
39 libs=(`for i in "$@"; do getlibs "$i"; done | sort -u`)
40
41 output="file  $LOADER $BASE$LOADER 0755 0 0"
42
43 while [ $#libs -gt 0 ]; do
44         i=${libs[1]}
45         libs=(${libs[2,-1]})
46
47         if ! [[ "$i" =~ "^$BASE" ]]; then continue; fi
48
49         dest=${i#$BASE}
50
51         if test -L "$i"; then
52                 output="$output\nslink $dest $(readlink "$i") 0644 0 0"
53                 next=`readlink "$i"`
54                 if [ "$next[0]" != "/" ]; then
55                         next="$(dirname "$i")/$next"
56                 fi
57                 libs+=$next
58         elif test -f "$i"; then
59                 output="$output\nfile  $dest $i 0644 0 0"
60         fi
61 done
62
63 echo "$output" | sort -u