forked from mit-ll/em-processing-opensky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzipOrganized_2.sh
32 lines (28 loc) · 1.31 KB
/
zipOrganized_2.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
#!/bin/bash
#
# $1 : Directory to be archived
#
# This script can be called directly or by a run script
# zip man
# -j --junk-paths Store just the name of a saved file (junk the path), and do not store directory names. By default, zip will store the full path (relative to the current directory).
# -g --grow Grow (append to) the specified zip archive, instead of creating a new one. If this operation fails, zip attempts to restore the archive to its original state. If the restoration fails, the archive might become corrupted. This option is ignored when there's no existing archive or when at least one archive member must be updated or deleted.
# -u --update Update existing entries if newer on the file system and add new files. If the archive does not exist issue warning then create a new archive.
# Directory to be archived
inDir=$1
# Archive to create
outFile=$(echo "$inDir" | sed "s/1_organize/2_archive/")
outFile=$outFile.zip
# Only do something if there are files
# https://unix.stackexchange.com/a/202352/1408
if [ ! -z "$(ls -A -- "$inDir")" ]; then
# Archive
if [ -f "$outFile" ]; then
echo "Updating: $outFile"
zip -j -r -u $outFile $inDir
else
echo "Archive does not exist, creating: $outFile"
zip -j -r $outFile $inDir
fi
else
echo "Directory empty: $inDir"
fi