Skip to content

Instantly share code, notes, and snippets.

@chris-rock
Created March 6, 2017 12:36
Show Gist options
  • Save chris-rock/c15ffc94979bf6cc311ff0be893dc962 to your computer and use it in GitHub Desktop.
Save chris-rock/c15ffc94979bf6cc311ff0be893dc962 to your computer and use it in GitHub Desktop.
Convert .cab to .zip
#!/bin/bash
# this tool converts a .cab file to a zip file
# check that we have an input parameter
test -z "${1:-}" &&\
echo "[ERROR] You need to pass a .cab file" &&\
exit 1
CURRENT_DIR=$(pwd)
TMP=$(mktemp -d -t cab)
FILENAME=$(echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")")
echo "[INFO] Extract $FILENAME to $TMP"
cabextract "$FILENAME" -d "$TMP"
# TODO: use CURRENT_DIR/$(basename "$FILENAME").zip
TARGET_ARCHIVE="${FILENAME%.*}".zip
echo "[INFO] Generate $TARGET_ARCHIVE"
pushd $TMP
zip -r "$TARGET_ARCHIVE" *
popd
echo "[INFO] Remove $TMP"
rm -r "$TMP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment