-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathREADME.txt
More file actions
68 lines (49 loc) · 3.13 KB
/
Copy pathREADME.txt
File metadata and controls
68 lines (49 loc) · 3.13 KB
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
RecompressSelectively.sh version 1.02
Selectively recompress archive files (like zip files) across subdirectories.
Rationale:
Say you have a bunch of archive files (like zip files) spread over many subdirectories,
and you want to recompress them all.
You would like to use another compression tool, like "advzip --shrink-insane",
which uses the zopfli algorithm to very slowly compress as much as possible.
Warning: advzip version 2.1-2.1build1 that comes with Ubuntu MATE 20.04
does not support international characters in filenames.
But you want to skip some archives based on some filename criteria. In fact, it would
be nice use the full power of the 'find' tool.
And you also want to skip some archives based on their contents. For example, only process
those archives with a particular filename inside.
You also want to swap out some shared files in all recompressed archives, because those
common files have been updated in the meantime.
At this point, you need so much flexibility, that you realise you will need to write
a custom script for this purpose. But there are more features to consider.
Any temporary files should always land on the same subdirectory. This way, if something
fails, you can inspect them manually.
Should you run two instances of the script at the same time by mistake, the second instance
should of course realise and stop, so as not to disturb the first one.
The first time around, you want to test the recompression results locally, and not modify
the original archives, in case you have made a mistake somewhere.
Writing such a script from scratch is time consuming, especially if you want it to be robust.
That is why I have written a complete, robust example Bash script with all the features
described above. Every time I need such flexibility in a batch file operation, I can save
a lot of time by copying and modifying this example script.
Syntax:
RecompressSelectively.sh [options...] <start directory>
Options:
--help displays this help text
--version displays the tool's version number (currently 1.02)
--license prints license information
--find-only Run only the 'find' command and list any files found.
--output-dir <dir> Instead of replacing the original archives,
place the recompressed ones somewhere else.
If the output directory already exists, it will not be emptied beforehand.
How to test this script:
./CreateTestFiles.sh "TestData"
./RecompressSelectively.sh --output-dir="TestData/Output" "TestData/FilesToProcess"
Caveats:
- File permissions are not respected. The recompressed archives will have default permissions,
unless you modify this script yourself.
- This script should use a temporary filesystem like /tmp, for performance reasons,
but that is not implemented yet. The main issue is making sure that any temporary files
are deleted if the script gets killed. There is not really a reliable way to achieve that.
Exit status: 0 means success, anything else is an error.
Feedback: Please send feedback to rdiezmail-tools at yahoo.de
Copyright (c) 2020 R. Diez - Licensed under the GNU AGPLv3