-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpactar.sh
90 lines (75 loc) · 3.12 KB
/
pactar.sh
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
#!/bin/bash
###################################################################################
#
# This Script packs a directory/file in .tar.gz or tar.bz2 format and adds
# a current date to filename
# Dependencies: tar, gzip and bzip2 packages
# Creation date - 12-12-2016
# Author: mariojsantos
###################################################################################
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
###################################################################################
#Funcion to print the mode use help
function PrintUsage()
{
echo "Use: `basename $0` [-b] [-vh] <file,directory>"
exit 1
}
function PrintHelp()
{
echo "Options: "
echo "-b: compress using bzip2 format"
echo "-v: shows the script version"
echo "-h: shows this help"
exit 1
}
#test if user supplied directory name
if [ -z $1 ]; then
echo -e "Need to supply the file or directory name after the script name!"
PrintUsage
exit
fi
#hour=$(date +%H-%M-%S)
today=$(date +%F)
type="z"
extension=".tar.gz"
target="${1%/}"
while getopts "hvblz" OPTION
do
case $OPTION in
h) PrintHelp
;;
v) echo "`basename $0` version 1.0"
exit
;;
b) type="j"
extension=".tar.bz2"
;;
?) PrintUsage
;;
esac
done
shift $((OPTIND-1))
##############################################################################
# To add the hour to the final filename, uncomment the line started #
# with the "hour" var e add the suffix -"$hour" as in the example below. #
# ex: tar -c"$type"vf "$target"_"$today"-"$hour""$extension" #
# #
##############################################################################
tar -c"$type"vf "$target"_"$today""$extension" $target
exit