Supports compression using zip format

This commit is contained in:
Howard Wu 2022-10-22 18:30:46 +08:00
parent 58d2c7de76
commit ac4f52ac49
2 changed files with 26 additions and 13 deletions

View File

@ -152,6 +152,7 @@ ROOT_SOL_MAP=(
COMPRESS_FORMAT_MAP=( COMPRESS_FORMAT_MAP=(
"7z" "7z"
"xz" "xz"
"zip"
) )
ARR_TO_STR() { ARR_TO_STR() {
@ -853,23 +854,34 @@ fi
if [ ! -d "$OUTPUT_DIR" ]; then if [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p "$OUTPUT_DIR" mkdir -p "$OUTPUT_DIR"
fi fi
OUTPUT_NAME="${OUTPUT_DIR:?}/$artifact_name"
if [ "$COMPRESS_OUTPUT" ] || [ -n "$COMPRESS_FORMAT" ]; then if [ "$COMPRESS_OUTPUT" ] || [ -n "$COMPRESS_FORMAT" ]; then
mv "$WORK_DIR/wsa/$ARCH" "$WORK_DIR/wsa/$artifact_name" mv "$WORK_DIR/wsa/$ARCH" "$WORK_DIR/wsa/$artifact_name"
if [ "$COMPRESS_FORMAT" = "7z" ]; then if [ -z "$COMPRESS_FORMAT" ]; then
rm -f "${OUTPUT_DIR:?}"/"$artifact_name.7z" || abort COMPRESS_FORMAT="7z"
echo "Compressing with 7z" fi
7z a "$OUTPUT_DIR"/"$artifact_name.7z" "$WORK_DIR/wsa/$artifact_name" || abort if [ -n "$COMPRESS_FORMAT" ]; then
elif [ "$COMPRESS_FORMAT" = "xz" ]; then FILE_EXT=".$COMPRESS_FORMAT"
rm -f "${OUTPUT_DIR:?}"/"$artifact_name.tar.xz" || abort if [ "$FILE_EXT" = ".xz" ]; then
echo "Compressing with tar xz" FILE_EXT=".tar$FILE_EXT"
if ! (tar -cP -I 'xz -9 -T0' -f "$OUTPUT_DIR"/"$artifact_name.tar.xz" "$WORK_DIR/wsa/$artifact_name"); then
echo "Out of memory? Trying again with single threads..."
tar -cPJvf "$OUTPUT_DIR"/"$artifact_name.tar.xz" "$WORK_DIR/wsa/$artifact_name" || abort
fi fi
fi fi
rm -f "${OUTPUT_NAME:?}$FILE_EXT" || abort
if [ "$COMPRESS_FORMAT" = "7z" ]; then
echo "Compressing with 7z"
7z a "${OUTPUT_NAME:?}$FILE_EXT" "$WORK_DIR/wsa/$artifact_name" || abort
elif [ "$COMPRESS_FORMAT" = "xz" ]; then
echo "Compressing with tar xz"
if ! (tar -cP -I 'xz -9 -T0' -f "${OUTPUT_NAME:?}$FILE_EXT" "$WORK_DIR/wsa/$artifact_name"); then
echo "Out of memory? Trying again with single threads..."
tar -cPJvf "${OUTPUT_NAME:?}$FILE_EXT" "$WORK_DIR/wsa/$artifact_name" || abort
fi
elif [ "$COMPRESS_FORMAT" = "zip" ]; then
7z -tzip a "${OUTPUT_NAME:?}$FILE_EXT" "$WORK_DIR/wsa/$artifact_name" || abort
fi
else else
rm -rf "${OUTPUT_DIR:?}/${artifact_name}" || abort rm -rf "${OUTPUT_NAME:?}" || abort
cp -r "$WORK_DIR"/wsa/"$ARCH" "$OUTPUT_DIR/$artifact_name" || abort cp -r "$WORK_DIR"/wsa/"$ARCH" "$OUTPUT_NAME" || abort
fi fi
echo -e "done\n" echo -e "done\n"

View File

@ -234,7 +234,8 @@ if [ "$COMPRESS_OUTPUT" = "--compress" ]; then
[default]="7z")' \ [default]="7z")' \
\ \
'7z' "7-Zip" 'on' \ '7z' "7-Zip" 'on' \
'xz' "tar.xz" 'off' 'xz' "tar.xz" 'off' \
'zip' "Zip" 'off'
) )
fi fi
# if ! (YesNoBox '([title]="Off line mode" [text]="Do you want to enable off line mode?")'); then # if ! (YesNoBox '([title]="Off line mode" [text]="Do you want to enable off line mode?")'); then