Created
April 5, 2013 01:30
-
-
Save kou1okada/5315910 to your computer and use it in GitHub Desktop.
LHa self-extracting archive to .lzh archive converter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Copyright (c) 2013 Koichi OKADA. All rights reserved. | |
# This script is distributed under the MIT license. | |
# http://www.opensource.org/licenses/mit-license.php | |
if [ "$1" = "" ]; then | |
echo "LHa self-extracting archive to .lzh archive converter." | |
echo "Usage: ${0##*/} file ..." | |
echo | |
exit 1 | |
fi | |
while [ "$1" != "" ]; do | |
file "$1" | grep -q "LHa self-extracting archive" | |
if [ "$?" = "0" ]; then | |
ARCHIVE="${1%.*}.lzh" | |
if [ -e "$ARCHIVE" ]; then | |
echo "$ARCHIVE: already exists." | |
else | |
echo "deSFX: $ARCHIVE" | |
SKIP=$(od -A n -t u4 -j 512 -N 4 "$1" | awk '{print $1}') | |
unset OFFSET | |
if dd if="$1" bs=1 skip=$(( $SKIP + 2 )) count=5 2> /dev/null | grep -qe '^-lh[56d]-' ; then OFFSET=0; fi | |
if dd if="$1" bs=1 skip=$(( $SKIP + 4 )) count=5 2> /dev/null | grep -qe '^-lh[56d]-' ; then OFFSET=2; fi | |
if [ "$OFFSET" = "" ]; then | |
echo "$1: unknown SFX." | |
else | |
dd if="$1" of="$ARCHIVE" skip=1 bs=$(( $SKIP + $OFFSET )) 2> /dev/null | |
fi | |
fi | |
fi | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment