NOTICE1: it deletes the original files, so you only end up the flac files, a list of the song titles (in case you want to import the song names with EasyTag.sf.net) and the cue file.
NOTICE2: During convertion it needs ~2x of disk space of the big flac file size.
NOTICE3: As far as I know only Debian have a fixed version of bchunk, so if you (like me) doesn't use Debian, you have to download Debian's patch, and compile bchunk yourself. Without the fixed version of bchunk, the all songs will have wrong offsets!
CODE
#!/bin/sh
FLAC="$(echo *flac)"
CUE="$(echo *cue)"
AUD="audio.raw"
flac -d "$FLAC"
rm "$FLAC"
WAV="$(echo *wav)"
sox "$WAV" "$AUD"
rm "$WAV"
/usr/local/bin/bchunk -w "$AUD" "$CUE" track
rm "$AUD"
flac --best track*
rm track*wav
sed -n 's/ TITLE "\(.*\)"/\1/p' "$CUE" > songnames.txt
FLAC="$(echo *flac)"
CUE="$(echo *cue)"
AUD="audio.raw"
flac -d "$FLAC"
rm "$FLAC"
WAV="$(echo *wav)"
sox "$WAV" "$AUD"
rm "$WAV"
/usr/local/bin/bchunk -w "$AUD" "$CUE" track
rm "$AUD"
flac --best track*
rm track*wav
sed -n 's/ TITLE "\(.*\)"/\1/p' "$CUE" > songnames.txt
