]>
Commit | Line | Data |
---|---|---|
3b403b32 | 1 | #!/bin/bash |
cc02093d HH |
2 | # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- |
3 | # ex: ts=8 sw=4 sts=4 et filetype=sh | |
4 | # | |
5 | # Copyright 2005-2010 Harald Hoyer <harald@redhat.com> | |
6 | # Copyright 2005-2010 Red Hat, Inc. All rights reserved. | |
7 | # | |
8 | # This program is free software; you can redistribute it and/or modify | |
9 | # it under the terms of the GNU General Public License as published by | |
10 | # the Free Software Foundation; either version 2 of the License, or | |
11 | # (at your option) any later version. | |
12 | # | |
13 | # This program is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | # | |
074d12c1 | 21 | |
f7bccf37 HH |
22 | usage() |
23 | { | |
dde2db3d | 24 | { |
7d9bb76a HH |
25 | echo "Usage: ${0##*/} [options] [<initramfs file> [<filename> [<filename> [...] ]]]" |
26 | echo "Usage: ${0##*/} [options] -k <kernel version>" | |
dde2db3d | 27 | echo |
7d9bb76a HH |
28 | echo "-h, --help print a help message and exit." |
29 | echo "-s, --size sort the contents of the initramfs by size." | |
30 | echo "-f, --file <filename> print the contents of <filename>." | |
31 | echo "-k, --kver <kernel version> inspect the initramfs of <kernel version>." | |
dde2db3d HH |
32 | echo |
33 | } >&2 | |
f7bccf37 HH |
34 | } |
35 | ||
3ea5d2e2 | 36 | sorted=0 |
7d9bb76a HH |
37 | declare -A filenames |
38 | ||
39 | unset POSIXLY_CORRECT | |
40 | TEMP=$(getopt \ | |
41 | -o "shf:k:" \ | |
42 | --long kver: \ | |
43 | --long file: \ | |
44 | --long help \ | |
45 | --long size \ | |
46 | -- "$@") | |
47 | ||
48 | if (( $? != 0 )); then | |
49 | usage | |
50 | exit 1 | |
51 | fi | |
52 | ||
53 | eval set -- "$TEMP" | |
54 | ||
55 | while (($# > 0)); do | |
56 | case $1 in | |
57 | -k|--kver) KERNEL_VERSION="$2"; shift;; | |
58 | -f|--file) filenames[${2#/}]=1; shift;; | |
59 | -s|--size) sorted=1;; | |
60 | -h|--help) usage; exit 0;; | |
61 | --) shift;break;; | |
62 | *) usage; exit 1;; | |
3ea5d2e2 | 63 | esac |
7d9bb76a | 64 | shift |
3ea5d2e2 | 65 | done |
3ea5d2e2 | 66 | |
7d9bb76a | 67 | [[ $KERNEL_VERSION ]] || KERNEL_VERSION="$(uname -r)" |
dde2db3d | 68 | |
7d9bb76a | 69 | if [[ $1 ]]; then |
dde2db3d HH |
70 | image="$1" |
71 | if ! [[ -f "$image" ]]; then | |
72 | { | |
73 | echo "$image does not exist" | |
74 | echo | |
75 | } >&2 | |
76 | usage | |
77 | exit 1 | |
78 | fi | |
dde2db3d | 79 | else |
727e68d0 HH |
80 | [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id |
81 | ||
7d9bb76a HH |
82 | if [[ -d /boot/loader/entries || -L /boot/loader/entries ]] \ |
83 | && [[ $MACHINE_ID ]] \ | |
84 | && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then | |
727e68d0 HH |
85 | image="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd" |
86 | else | |
d928724c | 87 | image="/boot/initramfs-${KERNEL_VERSION}.img" |
727e68d0 | 88 | fi |
dde2db3d HH |
89 | fi |
90 | ||
7d9bb76a HH |
91 | shift |
92 | while (($# > 0)); do | |
93 | filenames[${1#/}]=1; | |
94 | shift | |
95 | done | |
727e68d0 | 96 | |
dde2db3d HH |
97 | if ! [[ -f "$image" ]]; then |
98 | { | |
99 | echo "No <initramfs file> specified and the default image '$image' cannot be accessed!" | |
100 | echo | |
101 | } >&2 | |
102 | usage | |
103 | exit 1 | |
104 | fi | |
074d12c1 | 105 | |
884e1cda HH |
106 | read -N 6 bin < "$image" |
107 | case $bin in | |
108 | $'\x1f\x8b'*) | |
109 | CAT="zcat";; | |
110 | BZh*) | |
111 | CAT="bzcat";; | |
d93fe0fa | 112 | $'\x71\xc7'*|070701) |
884e1cda HH |
113 | CAT="cat";; |
114 | *) | |
115 | CAT="xzcat"; | |
116 | if echo "test"|xz|xzcat --single-stream >/dev/null 2>&1; then | |
117 | CAT="xzcat --single-stream" | |
118 | fi | |
119 | ;; | |
120 | esac | |
66fe35eb | 121 | |
884e1cda HH |
122 | ret=0 |
123 | ||
4460416a HH |
124 | if (( ${#filenames[@]} > 0 )); then |
125 | (( ${#filenames[@]} == 1 )) && nofileinfo=1 | |
126 | for f in ${!filenames[@]}; do | |
127 | [[ $nofileinfo ]] || echo "initramfs:/$f" | |
128 | [[ $nofileinfo ]] || echo "========================================================================" | |
b093aa2d | 129 | $CAT -- $image | cpio --extract --verbose --quiet --to-stdout $f 2>/dev/null |
4460416a HH |
130 | ((ret+=$?)) |
131 | [[ $nofileinfo ]] || echo "========================================================================" | |
132 | [[ $nofileinfo ]] || echo | |
133 | done | |
3ea5d2e2 | 134 | else |
4460416a HH |
135 | echo "Image: $image: $(du -h $image | while read a b; do echo $a;done)" |
136 | echo "========================================================================" | |
b093aa2d | 137 | version=$($CAT -- "$image" | cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/dracut-*' 2>/dev/null) |
4460416a HH |
138 | ((ret+=$?)) |
139 | echo "$version with dracut modules:" | |
861d9430 | 140 | $CAT -- "$image" | cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/modules.txt' 2>/dev/null |
4460416a HH |
141 | ((ret+=$?)) |
142 | echo "========================================================================" | |
143 | if [ "$sorted" -eq 1 ]; then | |
b093aa2d | 144 | $CAT -- "$image" | cpio --extract --verbose --quiet --list | sort -n -k5 |
4460416a | 145 | else |
b093aa2d | 146 | $CAT -- "$image" | cpio --extract --verbose --quiet --list | sort -k9 |
4460416a HH |
147 | fi |
148 | ((ret+=$?)) | |
149 | echo "========================================================================" | |
3ea5d2e2 | 150 | fi |
4460416a | 151 | |
884e1cda | 152 | exit $ret |