Skip to content

Instantly share code, notes, and snippets.

@jamespo
Created May 3, 2020 07:50
Show Gist options
  • Save jamespo/8507608997fd3cd13ba0d86dd8c054d2 to your computer and use it in GitHub Desktop.
Save jamespo/8507608997fd3cd13ba0d86dd8c054d2 to your computer and use it in GitHub Desktop.
zip2lha.sh - convert zip files (for WHDLOAD) into lha for retropie / amiberry
#!/bin/bash
# zip2lha.sh - convert zip files (for WHDLOAD) into lha for retropie / amiberry
# USAGE: zip2lha.sh zipfilename.zip
# or to do whole directory: find . -name '*.zip -exec zip2lha.sh {} \;
# set TMPDIR & DESTDIR in script
# REQUIREMENTS: unzip & jlha-utils (NOT lha package) on raspbian
# BE CAREFUL! This script removes contents of TMPDIR after each conversion
FN=$1
LHAFN=$(echo $FN |sed -e 's/.zip/.lha/')
TMPDIR=/data/tmp
DESTDIR=/data/roms/amiga/Amiga1
echo "Extracting $FN to $LHAFN"
unzip -d $TMPDIR "$FN" > /dev/null
cd $TMPDIR
jlha -ao5 "$LHAFN" * > /dev/null
mv "$LHAFN" $DESTDIR
rm -rf *
@Taranchul
Copy link

Taranchul commented Mar 24, 2023

Hi! Thanks for the script. HOWEVER, the rm command at the end is very dangerous. If the TMPDIR doesn't exist, the cd command will fail, and rm will delete everything in the directory the script is invoked from! (Imagine running it from $HOME …) Besides, /data/tmp is no standard directory in any Linux system that I know of, including Retropie. So, in a standard Linux system or Retropie, your script will delete everything in the dir that is run from.

Thus, you should catch a missing TMPDIR and stop the script with an error message, or at least run the rm explicitly on the TMPDIR from outside of it (e.g. end the script with cd -; rm -rf * $TMPDIR/*). Cheers.

edit: Here's a quick dirty rewrite that creates the TMPDIR (here "lhatmp" in the current dir) and deletes it afterwards. (Hint for onlookers: Make DESTDIR=.. to place the lha in the dir the script is invoked from.)

FN=$1
LHAFN=$(echo $FN |sed -e 's/.zip/.lha/')
TMPDIR=lhatmp                         # changed
DESTDIR=/data/roms/amiga/Amiga1

echo "Extracting $FN to $LHAFN"

mkdir -p $TMPDIR                      # new
unzip -d $TMPDIR "$FN" > /dev/null

cd $TMPDIR
jlha -ao5 "$LHAFN" * > /dev/null
mv "$LHAFN" $DESTDIR
cd -                                  # new
rm -rf $TMPDIR                        # changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment