Forum Moderators: bakedjake
Basically I do the php dev in windows and I am wanting to automate some of the tedious tasks I have to do when putting out a new release.
I am no shell script guru and what I have working currently is many hours of hunting the net for solutions.
first of I sync the files and set the perms to 664
find . -type f -name "*.*" -exec chmod 664 {} \;
then I make sure all the newlines are set to unix
find . -type f -name "*.*" -exec dos2unix -o {} \;
At that point I make sure all of the files have the correct charset for UTF-8 excluding any image files and one ttf font that gets distributed
find . -type f \( ! -iname "*.ttf" ! -iname "*.gif" ! -iname "*.jpg" ! -iname "*.jpeg" ! -iname "*.png" \) -exec iconv -f ISO-8859-1 -t UTF-8 -o {}.utf8 {} \;
then the last thing at this stage before an automated diff patch
is to rename all of the .utf8 files that have been created by dropping the .utf8 extension and using the previous extension for that file so .php.utf8 becomes .php again
this works but does not recurse into the directory structure so the files in the current directory are moved just fine but anything in a directory doesn't get touched.
for x in *.utf8; do mv $x `basename $x .utf8`; done;
Any help is appreciated.
Best Regards,
Brandon
#!/bin/bashCONVERT_FROM=ISO-8859-1
CONVERT_TO=UTF-8# move into our working directory
cd /var/www/localhost/htdocs/dist/# change the execute permissions from windows on our files
find . -type f -name "*.*" -exec chmod 664 {} \;
echo "Files have been modified to remove the execute bit"# if line endings in our file are windows CR change to unix
find . -type f -name "*.*" -exec dos2unix -q -o {} \;
echo "Dos 2 Unix new line conversion has completed"# delete any previous utf-8 files so we can write new ones
find . -type f \( -iname "*utf8*" \) -exec rm -f {} \;
echo "Old UTF-8 files have been deleted"# get all files in our current working directory and make sure they are UTF-8 charset
find . -type f \( ! -iname "*.ttf" ! -iname "*.gif" ! -iname "*.jpg" ! -iname "*.jpeg" ! -iname "*.png" \) -exec iconv -f $CONVERT_FROM -t $CONVERT_TO -s -o {}$
echo "New UTF-8 files have been created"# delete unconverted files so we can move the new files back later
find . -type f \( ! -iname "*.utf8" ! -iname "*.ttf" ! -iname "*.gif" ! -iname "*.jpg" ! -iname "*.jpeg" ! -iname "*.png" \) -exec rm {} \;
echo "Removal of original unconverted files is complete"# rename all files converted to utf-8 with utf8 extension
mmv -m ";*.utf8" "#1#2"
# deal with .htaccess
mmv -m ";.*.utf8" "#1.#2"
echo "Dist Prep has completed"
I could still use a little help optimizing it if anyone feels like it.
Best Regards,
Brandon
find . -type f \( ! -iname "*.ttf" ! -iname "*.gif" ! -iname "*.jpg" ! -iname "*.jpeg" ! -iname "*.png" \) -exec iconv -f $CONVERT_FROM -t $CONVERT_TO -s -o {}.utf8 {} \;
it is missing the final .utf8 {} \;