Skip to content

Instantly share code, notes, and snippets.

@skinofstars
Created June 21, 2012 13:01
Show Gist options
  • Save skinofstars/2965626 to your computer and use it in GitHub Desktop.
Save skinofstars/2965626 to your computer and use it in GitHub Desktop.
Update all MySQL ENGINE TYPE .sql within a collection of Zips. For updating legacy update files.
#!/usr/bin/env bash
# for each zip in the folder
# unpack to temp loc
# for each sql
# find "TYPE=" and replace with "ENGINE="
# repack and replace original
# remove temp loc
FILES=$1
find $FILES -name "*.zip" | while read ZIP;
do
echo $ZIP
# extract
unzip -oq $ZIP -d $ZIP-tmp
# for each file ending in .sql
find $ZIP-tmp -name "*.sql" | while read SQLFILE;
do
# recursive sed search and replace
sed -i 's/TYPE=/ENGINE=/g' $SQLFILE
done
# repack
# zip will replace/update a file with new contents, however...
# wat - gotta go in to folder or it just adds to zip as sub dir
cd $ZIP-tmp
for wat in `ls`;do
zip -rq ../$ZIP $wat
done
cd ../
# tidy
rm -rf $ZIP-tmp
done
@skinofstars
Copy link
Author

This is brittle, aggressive and destructive. Don't just go running it unless you know what you're doing!!!

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