1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#!/bin/bash
# gzip-like CLI wrapper for p7zip
set -e
compress=true
file=
usage ()
{
echo "Usage: $0 [-d] [-h|--help] [file]"
echo ""
echo " -h print this help"
echo " -d decompress file"
echo ""
exit 1
}
while [ "$#" != "0" ] ; do
case "$1" in
-d) compress=false ;; # decompressing
-c) echo "$0: ignoring $1 option (not yet implemented)" ;;
-h|--help|-*) usage ;;
*)
if [ "${file}" = "" ] ; then
file="$1"
else
usage
fi
;;
esac
shift
done
# make sure they're present, before we screw up
for i in mktemp 7zr rm cat tty ; do
if ! which $i > /dev/null ; then
echo "$0: $i: command not found"
exit 1
fi
done
if [ "${file}" != "" ] ; then
if ${compress} ; then
7zr a "${file}.7z" "${file}"
exec rm "${file}"
else
case "${file}" in
*.7z)
7zr x "${file}"
exec rm "${file}"
;;
*)
echo "$0: ${file}: unknown suffix -- ignored"
exit 0
;;
esac
fi
fi
tmp=`mktemp`
trap "rm -f ${tmp}" 0
if ${compress} ; then
if tty -s <&1 >/dev/null ; then
echo "$0: compressed data not written to a terminal."
echo "For help, type: $0 -h"
exit 1
fi
rm -f ${tmp}
7zr a ${tmp} -si >/dev/null
cat ${tmp}
else
cat > ${tmp}
7zr x ${tmp} -so 2>/dev/null | cat
fi
exec rm -f ${tmp}
|