-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_tub_archive.sh
executable file
·72 lines (62 loc) · 1.55 KB
/
make_tub_archive.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
#!/bin/bash
Help()
{
# Display Help
echo "Make archive of tub directory, including current config files."
echo
echo "Syntax: $0 [-t <tub directory>] [-a <archive basename>] [-h]"
echo "options:"
echo "t specify tub directory to archive (default to 'data')."
echo "a specify target archive basename (without extension, default to 'wip')."
echo "h Print this Help."
echo
}
tub=""
archive=""
while getopts ":ht:a:" option; do
case $option in
h) # display Help
Help
exit;;
t) # Enter a name
tub=$OPTARG;;
a) # Enter a name
archive=${OPTARG%.*};;
\?) # Invalid option
echo "Error: Invalid option"
Help
exit;;
esac
done
if [[ -z "$tub" ]]; then
tub="data"
echo "Using default tub directory '$tub'"
fi
if [[ ! -d "$tub" ]]; then
echo "tub directory '$tub' not found"
exit
fi
if [[ -z "$archive" ]]; then
archive="wip"
echo "using default archive basename $archive"
fi
if [ ! -f ./config.py ]
then
echo "Could not find ./config.py !"
echo "You must call this script from a 'mycar' directory"
exit
fi
if [ ! -f ./myconfig.py ]
then
echo "Could not find ./myconfig.py !"
echo "You must call this script from a 'mycar' directory"
exit
fi
echo "Archiving ${tub} to $archive.tgz"
tar -chf $archive.tar -C ./${tub} .
echo "Adding ./config.py and ./myconfig.py"
touch myconfig.py config.py
tar -uhf $archive.tar myconfig.py config.py
gzip $archive.tar
mv $archive.tar.gz $archive.tgz
echo "File ${archive}.tgz created"