#!/bin/bash #SH #!/usr/bin/env bash #SH This is portable, but has a different set of issues. #SH An attacker could alter $PATH and place a bash before #SH the real location. It's unlikely, but some feel better #SH with the absolute path here. So... okay. # # .spls to .wav+.mp3 batch processing and conversion # ================================================== # # This file can be executed as wrapper for SOMPYLER_DIRECTORY/scripts/sompyle # that also autodetects and reuses any cache directory for the given spls # file, so tones for notes that have not been changed or added are not # re-rendered. # # This is only a script for convenience; scripts/sompyle is usable without. # # PREREQUISITES: # -------------- # # Make sure you have installed following tools: # # - GNU find or any other find supporting -samefile operator # - lame: LAME Encoder # # # INSTALLATION: # ------------- # # Symlink this file from a /bin-directory in your $PATH, or copy and adjust # it according to your needs. # # # USAGE: # ------ # # $name_of_link [OPTIONS --] FILE [FILE2 FILE3 ... FILEn] # # The OPTIONS are simply passed to the wrapped script. Execute # scripts/sompyle without parameters to get a list and usage help. # # Do not forget the final "--" that means that following parameters are the # files to process. Files indicated without .spls suffix are regarded as # having one and they must be contained in $SOMPYLER_DIRECTORY/scores/. # # # CAUTION: # -------- # # This script is not quite portable, yet. # Replace if you have copied and customized scripts/sompyle-wrapper.sh: homedir=$(cd "$(dirname $(readlink $0))"/..; pwd) #SH Why readlink here (doesn't work the same way on BSD)? You want #SH the parent directory of the script? As you're in bash anyway, you #SH can: homedir="${PWD%/*}" or even pushd ../ and change the working #SH directory. # Use temporary directory as is stored in ${TMPDIR} environment variable # If not set, assume /tmp. export tempdir=${TMPDIR:-/tmp} #SH I'm not sure if it is strictly necessary to quote subshells, but I #SH feel better with it. # Supported by shells with array support declare -a FILES ARGS for i in "$@"; do if [ $i == "--" ]; then ARGS_ONLY=0 elif [ "$ARGS_ONLY" == 1 ] || [[ "$i" == -* ]]; then ARGS+=("$i") ARGS_ONLY=1 else FILES+=("$i") fi done #SH Bash has getopts. It also supports the "--" case. #SH Tutorial here: http://wiki.bash-hackers.org/howto/getopts_tutorial #SH or man bash /getopts (a bit cryptic, though) for score in "${FILES[@]}"; do if [ "${score}" != "*.spls" ]; then #SH $score must be "*.spls" to make this false. Is this intended? #SH Or do you rather mean somthing like [[ "$score" =~ .*\.spls ]], #SH Which is true for all .spls files? score="${homedir}/scores/${score}.spls" fi out="${tempdir}/$(basename "${score%.spls}").wav" tmp="$(find -L ${tempdir} -wholename "${tempdir}/sompyler*/score" -samefile "${score}" 2> /dev/null | head -1)" if [ -n "$tmp" ]; then # First argument to scripts/sompyle can be a directory instead of a # .spls file. This directory is expected to contain a "./score" file # or symlink to a real .spls file. So just let us overwrite it: score="$(dirname $tmp)" echo "Let's reuse cache directory ${score} with 'score' linking to requested file ..." fi "${homedir}/scripts/sompyle" "${score}" "${out}" "${ARGS[@]}" \ && lame "${out}" && rm "${out}" done