3 # Copyright 1997, 1998 Patrick Volkerding, Moorhead, Minnesota USA
6 # Redistribution and use of this script, with or without modification, is
7 # permitted provided that the following conditions are met:
9 # 1. Redistributions of this script must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
15 # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
18 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
20 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
21 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 # This is a preprocessor for 'less'. It is used when this environment
24 # variable is set: LESSOPEN="|lesspipe.sh %s"
26 # attempt to reveal info about initrd image
28 local ft=$(file "$1") dec tmp ft2
31 *LZMA?compressed?data*)
34 *gzip?compressed?data*)
43 tmp=$(mktemp -d) || return 1
44 $dec "$1" > $tmp/initrd.img || {
49 ft2=$(file $tmp/initrd.img)
50 echo "$ft:${ft2#$tmp/initrd.img:}"
53 install -d $tmp/initrd
54 (cd $tmp/initrd && cpio -dimu --quiet < $tmp/initrd.img)
57 install -d $tmp/initrd
58 mount -ro loop $tmp/initrd.img $tmp/initrd
66 (cd $tmp/initrd; ls -lR)
68 # also display linuxrc
69 if [ -f $tmp/initrd/linuxrc ]; then
71 echo "/linuxrc program:"
72 cat $tmp/initrd/linuxrc
75 mountpoint -q $tmp/initrd && umount $tmp/initrd
81 # display library info
82 # DT_NEEDED, SONAME etc
91 # possible initrd images
93 initrd "$1" && return 0
99 *.tar.bz|*.tbz) bzip -d < "$1" | tar tvvf - ;;
100 *.bz) bzip -d < "$1" ;;
101 *.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf - ;;
102 *.bz2) bzip2 -dc -- "$1" ;;
103 *.cab|*.CAB) cabextract -l -- "$1" ;;
104 *.cpi|*.cpio) cpio -itv < "$1" ;;
105 *.cpio.gz) gzip -dc -- "$1" | cpio -itv ;;
106 *.deb) dpkg -c "$1" ;;
107 *.tar.gz|*.tar.[Zz]|*.tgz) tar tzvvf "$1" ;;
108 *.gz|*.[Zz]) gzip -dc -- "$1" ;;
109 *.tar.lzma|*.tar.xz) tar tJvvf "$1" ;;
110 *.lzma|*.xz) xz -dc -- "$1" || lzma -dc -- "$1" ;;
111 *.phar) phar info -f "$1"; phar list -f "$1" ;;
112 *.rar) unrar -p- vb -- "$1" ;;
113 *.rpm) rpm -qpivl --changelog -- "$1" ;;
114 *.tar|*.ova|*.gem) tar tvvf "$1" ;;
115 *.sqf) unsquashfs -d . -ll "$1" ;;
116 *.zip|*.jar|*.xpi|*.[hj]pi|*.pk3|*.skz|*.gg|*.ipa|*.whl|*.crx) 7z l "$1" || unzip -l "$1" ;;
117 # .war could be Zip (limewire) or tar.gz file (konqueror web archives)
118 *.war) 7z l "$1" || unzip -l "$1" || tar tzvvf "$1" ;;
119 # other file types not handled via mailcap (no mimetype)
120 *.rrd) rrdtool info "$1" ;;
122 *.csr) openssl req -noout -text -in "$1" ;;
123 *.crl) openssl crl -noout -text -in "$1" ;;
124 *.crt) openssl x509 -noout -text -in "$1" ;;
125 *.p7s) openssl pkcs7 -noout -text -in "$1" -print_certs -inform DER;;
126 # gnupg armored files
127 *.asc) command -v gpg >/dev/null && { gpg -nv --homedir=/dev/null "$1" || : ; } || gpg2 -nv --homedir=/dev/null "$1" ;;
128 *.gpg) gpg -d "$1" ;;
129 *.so) library_info "$1" ;;
130 # Possible manual pages
131 *.1|*.2|*.3|*.4|*.5|*.6|*.7|*.8|*.9|*.l|*.n|*.man)
132 FILE=$(file -L "$1") # groff src
133 FILE=$(echo $FILE | cut -d ' ' -f 2)
134 if [ "$FILE" = "troff" ]; then
135 groff -s -p -t -e -Tlatin1 -mandoc "$1"
140 FILE=$(file -bL "$1")
141 FILE=$(echo $FILE | cut -d , -f 1)
142 [ "$FILE" = "SQLite 3.x database" ] && sqlite3 "$1" .dump
146 xterm|xterm-color|xterm*88color|xterm*256color)
151 run-mailcap "$1" || {
152 echo "$LESS" | grep -qi r || ps -p $PPID,$(ps -p $PPID -oppid=) -oargs= | grep -qiw -- -r && highlight --$output --style=darkblue "$1";
154 # Check to see if binary, if so -- view with 'strings'
155 # FILE=$(file -L "$1")
159 if [ -d "$1" ] ; then
162 lesspipe "$1" 2> /dev/null