wok-6.x view xz/stuff/lzma @ rev 5086
awstats, openldap: fix postfix (chroot)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Mar 15 12:39:19 2010 +0100 (2010-03-15) |
parents | a2da616d3e4f |
children | 6a8dae495834 |
line source
1 #!/bin/sh
2 #
3 # Wrapper to accept lzma_alone or lzma_utils arguments
4 #
6 usage()
7 {
8 cat 1>&2 <<EOT
9 Usage: LZMA <e|d> inputFile outputFile [<switches>...]
10 e: encode file
11 d: decode file
12 <Switches>
13 -a{N}: set compression mode - [0, 2], default: 1 (max)
14 -d{N}: set dictionary - [12,30], default: 23 (8MB)
15 -fb{N}: set number of fast bytes - [2, 273], default: 64
16 -mc{N}: set number of cycles for match finder
17 -lc{N}: set number of literal context bits - [0, 3], default: 3
18 -lp{N}: set number of literal pos bits - [0, 4], default: 0
19 -pb{N}: set number of pos bits - [0, 4], default: 2
20 -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc3, hc4], default: bt4
21 -eos: write End Of Stream marker
22 -si: read data from stdin
23 -so: write data to stdout
24 EOT
25 exit 1
26 }
28 # Get lzma_alone arg
29 getarg()
30 {
31 case "$1" in
32 -a0) mode="lzma1=mode=fast";;
33 -a1) mode="lzma1=mode=normal";;
34 -a2) mode="lzma2=mode=normal";;
35 -d*) extra="$extra,dict=$((2 ** ${1#-d}))";;
36 -fb*) extra="$extra,fb=${1#-fb}";;
37 -mc*) extra="$extra,depth=${1#-mc}";;
38 -lc*) extra="$extra,lc=${1#-lc}";;
39 -lp*) extra="$extra,lp=${1#-lp}";;
40 -pb*) extra="$extra,pb=${1#-pb}";;
41 -mf*) extra="$extra,mf=${1#-mf}";;
42 -eos|-mt*) ;;
43 -si) output="> ${input#< }"; input="";;
44 -so) output="";;
45 *) return 1;;
46 esac
47 return 0
48 }
50 lzma_utils()
51 {
52 args="--format=lzma"
53 files=""
54 suffix=lzma
55 while [ -n "$1" ]; do
56 case "$1" in
57 -e) args="$args -z";;
58 -d|-k|-[0-9]) args="$args $1";;
59 --fast) args="$args -1";;
60 --best) args="$args -9";;
61 -c|--stdout|--to-stdout) args="$args -c";;
62 -S) suffix=${2#.}; shift;;
63 -*);;
64 *) files="$files $1";;
65 esac
66 shift
67 done
68 for i in $files; do
69 xz $args $i || exit
70 [ "lzma" == "$suffix" ] || mv ${i%.*}.lzma ${i%.*}.$suffix
71 done
72 exit
73 }
75 # lzma_utils or lzma_alone ?
76 [ -n "$3" ] || lzma_utils $@
77 case "$1" in
78 d) args="-d";;
79 e) args="-z";;
80 --help|-h|-\?|'') usage;;
81 *) lzma_utils $@;;
82 esac
84 # it's lzma_alone
85 # get filenames
86 input="< $2"
87 output="> $2"
88 shift
89 if ! getarg "$1"; then
90 output="> $2"
91 getarg "$2"
92 shift
93 fi
95 # get arguments
96 extra=""
97 mode="lzma1=mode=normal"
98 while [ -n "$2" ]; do
99 getarg "$2" || usage
100 shift
101 done
103 # fake lzma_alone (-eos -mt1)
104 eval xz $args --format=lzma --$mode$extra --stdout $input $output
105 status=$?
106 if [ -n "$input" -a -n "$output" ]; then
107 size=$(stat -c "%s" ${input#< })
108 ascii="00000 "
109 for i in 1 2 3 4 5 6 7 8; do
110 ascii="$ascii $(printf "%02x" $((size % 256)) )"
111 size=$(( $size / 256 ))
112 done
113 echo "$ascii | .." | hexdump -R | \
114 dd of=${output#> } seek=5 bs=1 conv=notrunc 2> /dev/null
115 fi
116 exit $status