NBash

Форк
0
138 строк · 3.1 Кб
1
#!/bin/bash
2
#
3
# Copyright (C) 2013, 2020  Etersoft
4
# Copyright (C) 2013, 2020  Vitaly Lipatov <lav@etersoft.ru>
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
15
#
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#
19

20
PROGDIR=$(dirname $0)
21
[ "$PROGDIR" = "." ] && PROGDIR=$(pwd)
22

23
# will replaced to /usr/share/erc during install
24
SHAREDIR=$(dirname $0)
25

26
load_helper()
27
{
28
    local CMD="$SHAREDIR/$1"
29
    [ -r "$CMD" ] || fatal "Have no $CMD helper file"
30
    . $CMD
31
}
32

33
load_helper erc-sh-functions
34
load_helper erc-sh-archive
35

36
check_tty
37

38
phelp()
39
{
40
	echo "$Descr
41
$Usage
42
 Commands:
43
$(get_help HELPCMD)
44

45
 Options:
46
$(get_help HELPOPT)
47
"
48
}
49

50
print_version()
51
{
52
        echo "Etersoft uncompressor version @VERSION@"
53
        echo "Copyright (c) Etersoft 2013, 2020, 2023"
54
        echo "This program may be freely redistributed under the terms of the GNU AGPLv3."
55
}
56

57
regular_unpack()
58
{
59
    local file="$1"
60
    local prg="$2"
61
    local pkg="$3"
62
    local opt="$4"
63

64
    # instead of epm assure
65
    if ! is_command "$prg" ; then
66
        epm assure $prg $pkg || fatal "Try install $pkg package for $prg unpack command."
67
    fi
68

69
    docmd $prg $opt $file || fatal
70
}
71

72

73
progname="${0##*/}"
74

75
Usage="Usage: $progname [options] file(s)..."
76
Descr="ercat - universal file uncompressor"
77

78
quiet=
79
cmd=$1
80

81
# Just printout help if run without args
82
if [ -z "$cmd" ] ; then
83
    print_version
84
    echo
85
    fatal "Run $ $progname --help for get help"
86
fi
87

88
case $cmd in
89
    -h|--help|help)       # HELPOPT: this help
90
        phelp
91
        exit
92
        ;;
93
    -q|--quiet)           # HELPOPT: be silent
94
        quiet=--quiet
95
        shift
96
        cmd=$1
97
        ;;
98
    -v|--version)         # HELPOPT: print version
99
        print_version
100
        exit
101
        ;;
102
esac
103

104
# TODO: check ext
105
# TODO: check file existence
106
# TODO: check by content
107
for f in $@ ; do
108
    TYPE=$(get_archive_ext $f) || TYPE=$(is_plain_text $f) || { warning "Skipping unrecognized $f" ; continue ; }
109
    case $TYPE in
110
        gz)
111
            regular_unpack "$f" gunzip gzip -c
112
            ;;
113
        bz2)
114
            regular_unpack "$f" bzcat bzip2
115
            ;;
116
        xz)
117
            regular_unpack "$f" xzcat xz
118
            ;;
119
        Z|compress)
120
            regular_unpack "$f" zcat gzip
121
            ;;
122
        lzma)
123
            regular_unpack "$f" lzcat xz
124
            ;;
125
        zst|zstd)
126
            regular_unpack "$f" zstdcat zstd
127
            ;;
128
        lz4)
129
            regular_unpack "$f" lz4cat lz4
130
            ;;
131
        plain)
132
            docmd cat "$f" || fatal
133
            ;;
134
        *)
135
            fatal "Unsupported compression format $TYPE"
136
            ;;
137
    esac
138
done
139

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.