2013-06-18 17:13:55 +02:00
|
|
|
#!/bin/sh
|
2013-03-03 11:19:50 +01:00
|
|
|
|
|
|
|
_printhelp()
|
|
|
|
{
|
|
|
|
cat <<EOF
|
|
|
|
Usage: ${1##*/} [-m METHOD] [-v] FILES|FOLDERS
|
|
|
|
|
|
|
|
Create an archive from a single or multiples files/folders.
|
|
|
|
|
|
|
|
-h: Display this help.
|
|
|
|
-m: Choose compression method.
|
|
|
|
* gz: gzip (default).
|
|
|
|
* xz: LZMA.
|
|
|
|
-v: Exclude VCS data. (GNU tar only.)
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
OPTION_VCS=""
|
|
|
|
OPTION_METHOD=""
|
|
|
|
while getopts ":hm:v" opt; do
|
|
|
|
case $opt in
|
|
|
|
h)
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
m)
|
|
|
|
OPTION_METHOD="${OPTARG}"
|
|
|
|
;;
|
|
|
|
v)
|
|
|
|
OPTION_VCS="--exclude-vcs"
|
|
|
|
;;
|
|
|
|
?)
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
:)
|
|
|
|
echo "Missing argument."
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2013-06-18 17:13:55 +02:00
|
|
|
ARCEXT="tar.gz"
|
|
|
|
ARCOPT="z"
|
2013-03-03 11:19:50 +01:00
|
|
|
case $OPTION_METHOD in
|
|
|
|
"gz")
|
|
|
|
ARCEXT="tar.gz"
|
|
|
|
ARCOPT="z"
|
|
|
|
;;
|
|
|
|
"xz")
|
|
|
|
ARCEXT="tar.xz"
|
|
|
|
ARCOPT="J"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
2013-06-18 17:13:55 +02:00
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
FULLPATH="$(realpath "$1")"
|
|
|
|
OUTPUT="${FULLPATH}-$(date +%F-%H%M%S).${ARCEXT}"
|
2013-03-03 11:19:50 +01:00
|
|
|
|
2013-06-18 17:13:55 +02:00
|
|
|
(cd "${FULLPATH}/.." && \
|
|
|
|
tar -${ARCOPT} -cf ${OPTION_VCS} "$OUTPUT" "${FULLPATH##*/}" )
|
|
|
|
;;
|
2013-03-03 11:19:50 +01:00
|
|
|
|
2013-06-18 17:13:55 +02:00
|
|
|
0)
|
|
|
|
FULLPATH="$PWD"
|
|
|
|
OUTPUT="${FULLPATH}-$(date +%F-%H%M%S).${ARCEXT}"
|
|
|
|
(cd "${FULLPATH}/.." && \
|
|
|
|
tar -${ARCOPT} -cf ${OPTION_VCS} "$OUTPUT" "${FULLPATH##*/}" )
|
|
|
|
;;
|
2013-03-03 11:19:50 +01:00
|
|
|
|
2013-06-18 17:13:55 +02:00
|
|
|
*)
|
|
|
|
FULLPATH="$PWD"
|
|
|
|
OUTPUT="${FULLPATH}/${FULLPATH##*/}-$(date +%F-%H%M%S).${ARCEXT}"
|
2013-03-03 11:19:50 +01:00
|
|
|
|
2013-06-18 17:13:55 +02:00
|
|
|
tar -${ARCOPT} -cf ${OPTION_VCS} "$OUTPUT" "$@"
|
|
|
|
;;
|
|
|
|
esac
|