Skip to content

Instantly share code, notes, and snippets.

@AndrewBelt
Created January 2, 2018 22:10
Show Gist options
  • Save AndrewBelt/2c8fbe4ca24231a147e348391fa747d6 to your computer and use it in GitHub Desktop.
Save AndrewBelt/2c8fbe4ca24231a147e348391fa747d6 to your computer and use it in GitHub Desktop.

Revisions

  1. AndrewBelt created this gist Jan 2, 2018.
    23 changes: 23 additions & 0 deletions zipmerge.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/bin/bash

    OUT_NAME="$1"
    shift
    IN_NAMES="$@"
    TMP_DIR=$(mktemp -d)

    # Unzip each input ZIP
    for IN_NAME in $IN_NAMES; do
    unzip -n "$IN_NAME" -d "$TMP_DIR"
    done

    # ZIP all contents of uncompressed output into the temporary directory
    (cd "$TMP_DIR"; zip -r "$OUT_NAME" *)

    # Move output ZIP to final location
    mv "$TMP_DIR"/"$OUT_NAME" "$OUT_NAME"

    # Check contents of output ZIP
    unzip -l "$OUT_NAME"

    # Clean up all temporary files
    rm -r "$TMP_DIR"