-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_tarball
executable file
·102 lines (88 loc) · 1.92 KB
/
create_tarball
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
#
# Create an optionally compressed tar archive.
#
# Dependencies: coreutils, tar, util-linux
# Optional dependencies: bzip2, gzip, lzip, lzop, ncompress, xz, zstd
set -o nounset -o pipefail
readonly L_OPTS="help,version"
readonly OPTS="hVv"
readonly CMD="${0##*/}"
readonly USAGE="${CMD} [OPTION]... ARCHIVE FILE..."
readonly USAGE_ERR_MSG=$(
cat <<END
Usage: ${USAGE}
Try '${CMD} --help' for more information.
END
)
readonly VERSION_INFO=$(
cat <<END
${CMD} (scripts) 1.0.0
This is free and unencumbered software released into the public domain.
For more information, please refer to <https://unlicense.org/>.
END
)
readonly HELP=$(
cat <<END
SYNOPSIS
${USAGE}
DESCRIPTION
Create a tarball named ARCHIVE from FILEs.
Also compress the archive if it has one of the following extensions:
.bz .bz2 .tbz .tbz2 - bzip2
.gz .taz .tgz - gzip
.lz - lzip
.lzo - lzop
.Z - ncompress
.lzma .tlz .txz .xz - xz
.zst - zstd
The corresponding optional dependencies must be satisfied.
OPTIONS
-h, --help
display this help and exit
-V, -v, --version
display version and exit
END
)
opts=$(getopt --options=${OPTS} --longoptions=${L_OPTS} --name "${CMD}" -- "$@")
if (($? != 0)); then
echo "${USAGE_ERR_MSG}"
exit 2
fi
eval set -- "${opts}"
need_help=false
need_version=false
while true; do
case "$1" in
-h | --help)
need_help=true
shift
break
;;
-V | -v | --version)
need_version=true
shift
break
;;
--)
shift
break
;;
esac
done
if [[ $need_help == true ]]; then
echo "${HELP}"
exit 0
fi
if [[ $need_version == true ]]; then
echo "${VERSION_INFO}"
exit 0
fi
if (($# < 2)); then
echo "${CMD}: expected at least 2 arguments; got $#"
echo "${USAGE_ERR_MSG}"
exit 2
fi
tar --create --file "$1" \
--auto-compress --verbose \
"${@:2}"