mirror of
https://github.com/megastep/makeself.git
synced 2026-04-22 23:17:04 +08:00
Support both encryption and compression modes at the same time.
This commit is contained in:
+32
-25
@@ -149,6 +149,9 @@ else
|
||||
MS_Usage
|
||||
fi
|
||||
ENCRYPT=n
|
||||
ENCRYPT_MODE=n
|
||||
ENCRYPT_CMD=""
|
||||
DECRYPT_CMD=""
|
||||
PASSWD=""
|
||||
PASSWD_SRC=""
|
||||
OPENSSL_NO_MD=n
|
||||
@@ -238,21 +241,21 @@ do
|
||||
shift
|
||||
;;
|
||||
--gpg-encrypt)
|
||||
COMPRESS=gpg
|
||||
shift
|
||||
;;
|
||||
ENCRYPT_MODE=gpg
|
||||
shift
|
||||
;;
|
||||
--gpg-asymmetric-encrypt-sign)
|
||||
COMPRESS=gpg-asymmetric
|
||||
shift
|
||||
;;
|
||||
ENCRYPT_MODE=gpg-asymmetric
|
||||
shift
|
||||
;;
|
||||
--gpg-extra)
|
||||
GPG_EXTRA="$2"
|
||||
shift 2 || { MS_Usage; exit 1; }
|
||||
;;
|
||||
--ssl-encrypt)
|
||||
ENCRYPT=openssl
|
||||
shift
|
||||
;;
|
||||
ENCRYPT_MODE=openssl
|
||||
shift
|
||||
;;
|
||||
--ssl-passwd)
|
||||
PASSWD=$2
|
||||
shift 2 || { MS_Usage; exit 1; }
|
||||
@@ -552,16 +555,6 @@ base64)
|
||||
GZIP_CMD="base64"
|
||||
GUNZIP_CMD="base64 --decode -i -"
|
||||
;;
|
||||
gpg)
|
||||
GZIP_CMD="gpg $GPG_EXTRA -ac -z$COMPRESS_LEVEL"
|
||||
GUNZIP_CMD="gpg -d"
|
||||
ENCRYPT="gpg"
|
||||
;;
|
||||
gpg-asymmetric)
|
||||
GZIP_CMD="gpg $GPG_EXTRA -z$COMPRESS_LEVEL -es"
|
||||
GUNZIP_CMD="gpg --yes -d"
|
||||
ENCRYPT="gpg"
|
||||
;;
|
||||
compress)
|
||||
GZIP_CMD="compress -fc"
|
||||
GUNZIP_CMD="(type compress >/dev/null 2>&1 && compress -fcd || gzip -cd)"
|
||||
@@ -576,14 +569,15 @@ if test x"$COMP_EXTRA" != "x"; then
|
||||
GZIP_CMD="$GZIP_CMD $COMP_EXTRA"
|
||||
fi
|
||||
|
||||
if test x"$ENCRYPT" = x"openssl"; then
|
||||
case "$ENCRYPT_MODE" in
|
||||
openssl)
|
||||
if test x"$APPEND" = x"y"; then
|
||||
echo "Appending to existing archive is not compatible with OpenSSL encryption." >&2
|
||||
fi
|
||||
|
||||
|
||||
ENCRYPT_CMD="openssl enc -aes-256-cbc -salt -pbkdf2"
|
||||
DECRYPT_CMD="openssl enc -aes-256-cbc -d -salt -pbkdf2"
|
||||
|
||||
|
||||
if test x"$OPENSSL_NO_MD" != x"y"; then
|
||||
ENCRYPT_CMD="$ENCRYPT_CMD -md sha256"
|
||||
DECRYPT_CMD="$DECRYPT_CMD -md sha256"
|
||||
@@ -594,7 +588,20 @@ if test x"$ENCRYPT" = x"openssl"; then
|
||||
elif test -n "$PASSWD"; then
|
||||
ENCRYPT_CMD="$ENCRYPT_CMD -pass pass:$PASSWD"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
gpg)
|
||||
ENCRYPT_CMD="gpg $GPG_EXTRA -ac -z$COMPRESS_LEVEL -o -"
|
||||
DECRYPT_CMD="gpg $GPG_EXTRA -d"
|
||||
;;
|
||||
gpg-asymmetric)
|
||||
ENCRYPT_CMD="gpg $GPG_EXTRA -z$COMPRESS_LEVEL -es -o -"
|
||||
DECRYPT_CMD="gpg $GPG_EXTRA --yes -d"
|
||||
;;
|
||||
n)
|
||||
;;
|
||||
esac
|
||||
|
||||
ENCRYPT="$ENCRYPT_MODE"
|
||||
|
||||
tmpfile="${TMPDIR:-/tmp}/mkself$$"
|
||||
|
||||
@@ -687,9 +694,9 @@ eval "$GZIP_CMD" <"$tmparch" >"$tmpfile" || {
|
||||
}
|
||||
rm -f "$tmparch"
|
||||
|
||||
if test x"$ENCRYPT" = x"openssl"; then
|
||||
if test x"$ENCRYPT_MODE" != xn; then
|
||||
echo "About to encrypt archive \"$archname\"..."
|
||||
{ eval "$ENCRYPT_CMD -in $tmpfile -out ${tmpfile}.enc" && mv -f ${tmpfile}.enc $tmpfile; } || \
|
||||
{ eval "$ENCRYPT_CMD" < "$tmpfile" > "${tmpfile}.enc" && mv -f "${tmpfile}.enc" "$tmpfile"; } || \
|
||||
{ echo Aborting: could not encrypt temporary file: "$tmpfile".; rm -f "$tmpfile"; exit 1; }
|
||||
fi
|
||||
|
||||
|
||||
+128
@@ -39,6 +39,20 @@ diffInfo() {
|
||||
return "${rc}"
|
||||
}
|
||||
|
||||
gpgDiffInfo() {
|
||||
if ! command -v gpg >/dev/null 2>&1; then
|
||||
# Skip gracefully if gpg is not available
|
||||
return 0
|
||||
fi
|
||||
local rc=""
|
||||
local gnupg=""
|
||||
gnupg="$(mktemp -d)"
|
||||
GNUPGHOME="${gnupg}" diffInfo "$@"
|
||||
rc="$?"
|
||||
rm -rf "${gnupg}"
|
||||
return "${rc}"
|
||||
}
|
||||
|
||||
testDefault() (
|
||||
cd "$(mktemp -d)" || return 1
|
||||
diffInfo --packaging-date "@0" <<EOF
|
||||
@@ -143,6 +157,120 @@ EOF
|
||||
assertEquals "$?" 0
|
||||
)
|
||||
|
||||
testSslEncryptWithCompression() (
|
||||
cd "$(mktemp -d)" || return 1
|
||||
diffInfo --packaging-date "@0" --ssl-encrypt --ssl-passwd "secret" <<EOF
|
||||
Identification: infotest
|
||||
Target directory: infotest
|
||||
Uncompressed size: ${UNCOMPRESSED_PLACEHOLDER}
|
||||
Compression: gzip
|
||||
Encryption: openssl
|
||||
Date of packaging: @0
|
||||
Built with Makeself version ${VERSION}
|
||||
Build command was: ./makeself.sh \\
|
||||
"--packaging-date" \\
|
||||
"@0" \\
|
||||
"--ssl-encrypt" \\
|
||||
"--ssl-passwd" \\
|
||||
"secret" \\
|
||||
"./infotest" \\
|
||||
"./infotest.run" \\
|
||||
"infotest" \\
|
||||
"ls" \\
|
||||
"-lah"
|
||||
Script run after extraction:
|
||||
ls -lah
|
||||
infotest will be removed after extraction
|
||||
EOF
|
||||
assertEquals "$?" 0
|
||||
)
|
||||
|
||||
testSslEncryptWithZstdCompression() (
|
||||
cd "$(mktemp -d)" || return 1
|
||||
diffInfo --packaging-date "@0" --ssl-encrypt --ssl-passwd "secret" --zstd <<EOF
|
||||
Identification: infotest
|
||||
Target directory: infotest
|
||||
Uncompressed size: ${UNCOMPRESSED_PLACEHOLDER}
|
||||
Compression: zstd
|
||||
Encryption: openssl
|
||||
Date of packaging: @0
|
||||
Built with Makeself version ${VERSION}
|
||||
Build command was: ./makeself.sh \\
|
||||
"--packaging-date" \\
|
||||
"@0" \\
|
||||
"--ssl-encrypt" \\
|
||||
"--ssl-passwd" \\
|
||||
"secret" \\
|
||||
"--zstd" \\
|
||||
"./infotest" \\
|
||||
"./infotest.run" \\
|
||||
"infotest" \\
|
||||
"ls" \\
|
||||
"-lah"
|
||||
Script run after extraction:
|
||||
ls -lah
|
||||
infotest will be removed after extraction
|
||||
EOF
|
||||
assertEquals "$?" 0
|
||||
)
|
||||
|
||||
testGpgEncryptWithGzipCompression() (
|
||||
cd "$(mktemp -d)" || return 1
|
||||
gpgDiffInfo --packaging-date "@0" --gpg-encrypt --gpg-extra "--batch --yes --pinentry-mode=loopback --passphrase=secret" <<EOF
|
||||
Identification: infotest
|
||||
Target directory: infotest
|
||||
Uncompressed size: ${UNCOMPRESSED_PLACEHOLDER}
|
||||
Compression: gzip
|
||||
Encryption: gpg
|
||||
Date of packaging: @0
|
||||
Built with Makeself version ${VERSION}
|
||||
Build command was: ./makeself.sh \\
|
||||
"--packaging-date" \\
|
||||
"@0" \\
|
||||
"--gpg-encrypt" \\
|
||||
"--gpg-extra" \\
|
||||
"--batch --yes --pinentry-mode=loopback --passphrase=secret" \\
|
||||
"./infotest" \\
|
||||
"./infotest.run" \\
|
||||
"infotest" \\
|
||||
"ls" \\
|
||||
"-lah"
|
||||
Script run after extraction:
|
||||
ls -lah
|
||||
infotest will be removed after extraction
|
||||
EOF
|
||||
assertEquals "$?" 0
|
||||
)
|
||||
|
||||
testGpgEncryptWithZstdCompression() (
|
||||
cd "$(mktemp -d)" || return 1
|
||||
gpgDiffInfo --packaging-date "@0" --gpg-encrypt --gpg-extra "--batch --yes --pinentry-mode=loopback --passphrase=secret" --zstd <<EOF
|
||||
Identification: infotest
|
||||
Target directory: infotest
|
||||
Uncompressed size: ${UNCOMPRESSED_PLACEHOLDER}
|
||||
Compression: zstd
|
||||
Encryption: gpg
|
||||
Date of packaging: @0
|
||||
Built with Makeself version ${VERSION}
|
||||
Build command was: ./makeself.sh \\
|
||||
"--packaging-date" \\
|
||||
"@0" \\
|
||||
"--gpg-encrypt" \\
|
||||
"--gpg-extra" \\
|
||||
"--batch --yes --pinentry-mode=loopback --passphrase=secret" \\
|
||||
"--zstd" \\
|
||||
"./infotest" \\
|
||||
"./infotest.run" \\
|
||||
"infotest" \\
|
||||
"ls" \\
|
||||
"-lah"
|
||||
Script run after extraction:
|
||||
ls -lah
|
||||
infotest will be removed after extraction
|
||||
EOF
|
||||
assertEquals "$?" 0
|
||||
)
|
||||
|
||||
################################################################################
|
||||
|
||||
# Load and run shUnit2.
|
||||
|
||||
Reference in New Issue
Block a user