Skip to content

Commit 84c63ed

Browse files
anonymouspagemegastep
authored andcommitted
Feature: Allow extra options to compressor
This feature adds a new command line parameter, --comp-extra, which functions similarly to --tar-extra, in that it allows a user to add extra parameters to whichever compressor they have chosen to use. The basis for this feature was to allow passing --no-name to gzip, as part of a quest to make fully reproducible makeself archives.
1 parent bccc0e4 commit 84c63ed

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ makeself.sh [args] archive_dir file_name label startup_script [script_args]
9292
* **`--compress`** : Use the UNIX `compress` command to compress the data. This should be the default on all platforms that don't have gzip available.
9393
* **`--nocomp`** : Do not use any compression for the archive, which will then be an uncompressed TAR.
9494
* **`--complevel`** : Specify the compression level for gzip, bzip2, pbzip2, zstd, xz, lzo or lz4. (defaults to 9)
95+
* **`--comp-extra`** : Append more options to the compressor's command line.
9596
* **`--threads`** : Specify the number of threads to be used by compressors that support parallelization. Omit to use compressor's default. Most useful (and required) for opting into xz's threading, usually with `--threads=0` for all available cores. pbzip2 and pigz are parallel by default, and setting this value allows limiting the number of threads they use.
9697
* **`--notemp`** : The generated archive will not extract the files to a temporary directory, but in a new directory created in the current directory. This is better to distribute software packages that may extract and compile by themselves (i.e. launch the compilation through the embedded script).
9798
* **`--current`** : Files will be extracted to the current directory, instead of in a subdirectory. This option implies `--notemp` above.

makeself.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ Do not compress the data.
7474
.B --complevel lvl
7575
Specify the compression level for gzip, bzip2, pbzip2, xz, zstd, lzo or lz4. Defaults to 9.
7676
.TP
77+
.B --comp-extra opt
78+
Append more options to the compressor's command line.
79+
.TP
7780
.B --threads num
7881
Specify the number of threads to be used by compressors that support parallelization.
7982
.TP

makeself.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ MS_Usage()
5353
echo " --lz4 : Compress using lz4 instead of gzip"
5454
echo " --compress : Compress using the UNIX 'compress' command"
5555
echo " --complevel lvl : Compression level for gzip pigz zstd xz lzo lz4 bzip2 pbzip2 and bzip3 (default 9)"
56+
echo " --comp-extra : Append extra options to the chosen compressor"
5657
echo " --threads thds : Number of threads to be used by compressors that support parallelization."
5758
echo " Omit to use compressor's default. Most useful (and required) for opting"
5859
echo " into xz's threading, usually with '--threads=0' for all available cores."
@@ -134,6 +135,7 @@ PASSWD=""
134135
PASSWD_SRC=""
135136
OPENSSL_NO_MD=n
136137
COMPRESS_LEVEL=9
138+
COMP_EXTRA=""
137139
DEFAULT_THREADS=123456 # Sentinel value
138140
THREADS=$DEFAULT_THREADS
139141
KEEP=n
@@ -253,6 +255,10 @@ do
253255
COMPRESS_LEVEL="$2"
254256
shift 2 || { MS_Usage; exit 1; }
255257
;;
258+
--comp-extra)
259+
COMP_EXTRA="$2"
260+
shift 2 || { MS_Usage; exit 1; }
261+
;;
256262
--threads)
257263
THREADS="$2"
258264
shift 2 || { MS_Usage; exit 1; }
@@ -548,6 +554,10 @@ none)
548554
;;
549555
esac
550556

557+
if test x"$COMP_EXTRA" != "x"; then
558+
GZIP_CMD="$GZIP_CMD $COMP_EXTRA"
559+
fi
560+
551561
if test x"$ENCRYPT" = x"openssl"; then
552562
if test x"$APPEND" = x"y"; then
553563
echo "Appending to existing archive is not compatible with OpenSSL encryption." >&2

test/compextratest

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -eu
3+
THIS="$(readlink -f "$0")"
4+
THISDIR="$(dirname "${THIS}")"
5+
SUT="$(dirname "${THISDIR}")/makeself.sh"
6+
7+
setupTests() {
8+
temp=$(mktemp -d -t XXXXX)
9+
pushd "${temp}"
10+
mkdir src
11+
echo "echo This is a test" > src/startup.sh
12+
}
13+
14+
tearDown() {
15+
popd
16+
rm -rf "${temp}"
17+
}
18+
19+
testCompExtraOpts() {
20+
setupTests
21+
22+
comp_extra="--no-name"
23+
${SUT} --comp-extra "$comp_extra" src src.sh alabel startup.sh
24+
25+
assertEquals $? 0
26+
27+
tearDown
28+
}
29+
30+
# Negative test: ensure failures are detected when invalid compressor
31+
# extras are specified.
32+
testCompExtraOptsInvalid() {
33+
setupTests
34+
35+
comp_extra="-x" # -x is an invalid gzip option
36+
${SUT} --comp-extra "$comp_extra" src src.sh alabel startup.sh
37+
38+
assertNotEquals $? 0
39+
40+
tearDown
41+
}
42+
43+
44+
# Load and run shUnit2.
45+
source "./shunit2/shunit2"
46+

0 commit comments

Comments
 (0)