Notes on using a separate storage domain with a Faircamp site

DISCLAIMER!

I hope these bash scripts are useful, but they are designed for my own particular Faircamp setup. You might need to adapt them to yours.
The scripts are set up for a Faircamp build with no nested albums. They will only work if each album folder is in the root directory of the Faircamp server.
Be careful! The upload and download commands sync the files to the server and separate storage and could potentially delete your stuff!
Tested only with Faircamp version 0.1.0

Scripts!

After generating the Faircamp site we need to search and replace the links to audio and zip files in the html, so that they point to our dedicated storage.
We then need to upload the audio and zip files to our dedicated storage, while uploading everything else to our web server.

To replace all the links I use the following bash script...

ATTENTION!
This will only work if your Faircamp directory is laid out in a flat structure with each album folder in the root directory of your Faircamp server.
It only transfers opus, mp3 and flac audio files, and zips.
When using the sed program to replace text, we need to be sure the delimiter is not present in the text we're replacing. I used '~' (tilde) because I know it's not in any of the text I'll replace. Replace all the ~ with another character if you need to.
Later, we'll upload our music to a folder called 'album' on our dedicated storage. This is reflected in the updated links.
Replace "media.example.com" with your own separate storage address.

cd "PATH/TO/.faircamp_build" for dir in ./*/; do dirname=$(basename "$dir") find . -name *.html -exec sed -i 's~href="../../../'"$dirname"'/opus-128~href="https://media.example.com/album/'"$dirname"'/opus-128~g' {} \; find . -name *.html -exec sed -i 's~href="../../../'"$dirname"'/mp3-v0~href="https://media.example.com/album/'"$dirname"'/mp3-v0~g' {} \; find . -name *.html -exec sed -i 's~href="../../../'"$dirname"'/flac~href="https://media.example.com/album/'"$dirname"'/flac~g' {} \; cd "$dir" find . -name *.html -exec sed -i 's~src="opus-96~src="https://media.example.com/album/'"$dirname"'/opus-96~g' {} \; find . -name *.html -exec sed -i 's~src="mp3-v5~src="https://media.example.com/album/'"$dirname"'/mp3-v5~g' {} \; find . -name *.html -exec sed -i 's~src="../../opus-96~src="https://media.example.com/album/'"$dirname"'/opus-96~g' {} \; find . -name *.html -exec sed -i 's~src="../../mp3-v5~src="https://media.example.com/album/'"$dirname"'/mp3-v5~g' {} \; cd .. done

After replacing the links we can upload the files. We'll upload only the audio files and zips to our dedicated storage, in a folder called 'album', but otherwise keep the same directory structure.
Then we'll sync all the other files to our web server, excluding audio file directories.
Replace user@remote_host:/my/storage/ with your own storage server details.
CAUTION! These sync commands might delete stuff from your storage! Check carefully before use!

rsync command to sync only flac, mp3, opus and zip files

rsync -avz --delete --prune-empty-dirs --include={'*/','*.flac','*.mp3','*.opus','*.zip'} --exclude='*' /PATH/TO/.faircamp_build/ user@remote_host:/my/storage/album/

s3cmd to sync only flac, mp3, opus and zip files

If you're using s3 compatible storage you may be using the s3cmd program to sync instead. Replace MY_BUCKET with your storage bucket name. Note that we also set the files to public access.

s3cmd sync --skip-existing --delete-removed --exclude '*' --include '*.flac' --include '*.mp3' --include '*.opus' --include '*.zip' PATH/TO/.faircamp_build/ s3://MY_BUCKET/album/ --acl-public

rsync command to sync everything else to our webserver, excluding audio file directories

rsync -avz --delete --exclude={'*flac*','*mp3-v0*','*mp3-v5*','*opus-96*','*opus-128*'} PATH/TO/.faircamp_build/ user@remote_host:/my/website/

Putting it all together

We can combine all this into a single bash script, which we can run after building our Faircamp site. It replaces the links then uploads files to the appropriate locations. Mine looks something like this:

cd "PATH/TO/.faircamp_build" for dir in ./*/; do dirname=$(basename "$dir") find . -name *.html -exec sed -i 's~href="../../../'"$dirname"'/opus-128~href="https://media.example.com/album/'"$dirname"'/opus-128~g' {} \; find . -name *.html -exec sed -i 's~href="../../../'"$dirname"'/mp3-v0~href="https://media.example.com/album/'"$dirname"'/mp3-v0~g' {} \; find . -name *.html -exec sed -i 's~href="../../../'"$dirname"'/flac~href="https://media.example.com/album/'"$dirname"'/flac~g' {} \; cd "$dir" find . -name *.html -exec sed -i 's~src="opus-96~src="https://media.example.com/album/'"$dirname"'/opus-96~g' {} \; find . -name *.html -exec sed -i 's~src="mp3-v5~src="https://media.example.com/album/'"$dirname"'/mp3-v5~g' {} \; find . -name *.html -exec sed -i 's~src="../../opus-96~src="https://media.example.com/album/'"$dirname"'/opus-96~g' {} \; find . -name *.html -exec sed -i 's~src="../../mp3-v5~src="https://media.example.com/album/'"$dirname"'/mp3-v5~g' {} \; cd .. done s3cmd sync --skip-existing --delete-removed --exclude '*' --include '*.flac' --include '*.mp3' --include '*.opus' --include '*.zip' ./ s3://MY_BUCKET/album/ --acl-public rsync -avz --delete --exclude={'*flac*','*mp3-v0*','*mp3-v5*','*opus-96*','*opus-128*'} ./ user@remote_host:/my/website/