Skip to content

Instantly share code, notes, and snippets.

@JamesYeoman
Last active June 15, 2021 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesYeoman/4c58fa8f81738117f3b088c1ae80b533 to your computer and use it in GitHub Desktop.
Save JamesYeoman/4c58fa8f81738117f3b088c1ae80b533 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# An estimated 340M of storage space will be needed for temporary downloads.
# Upon script completion, all temporary downloads will be removed
# This installer will ensure that pulseeffects has all the dependencies installed,
# and prompt you to select an AutoEQ preset using FZF.
#
# This only works because WAV support was added to PulseEffects in version 4.7.2, and
# AutoEQ provides WAV impulse files.
#
# If anyone is able to create a way of detecting the pulseeffects version, then brilliant.
# But for now, the only solution is to just have a disclaimer.
function downloadZip() {
echo "Downloading $2 inside /tmp"
wget --quiet --output-file="/tmp/${1}.zip" "$2"
echo "Unzipping the downloaded archive"
unzip -q "/tmp/${1}.zip"
mv "/tmp/${1}-master" "/tmp/$1"
}
function getFzfCmd() {
local cmd="/tmp/fzf/fzf"
if [[ "${FZF_IN_PATH:-1}" -eq 0 ]]; then
cmd="fzf"
fi
echo "$cmd"
}
function checkFileForWav() {
local filename="$(basename "$1")"
[[ "${filename##*44100Hz.wav}" == "44100Hz.wav" ]] && return 0 || return 1
}
function requestFile() {
while true; do
echo "On the next screen, you'll be greeted by a FZF prompt. You need to select the 44100Hz.wav file for your headset."
read -N 1 -s -p "Press any key to acknowledge the above"
local cmd="$(getFzfCmd)"
local value=$(command $cmd --no-multi)
local statusCode="$?"
if $statusCode ; then
if checkFileForWav "$value" ; then
echo "$value"
return 0
fi
printf "The selected file '${value}' isn't a WAV file.\n\n"
else
echo "FZF was aborted."
return 1
fi
done
}
# First off, if git isn't installed, we should abort (considering the reliance on git here)
if ! command -v "unzip" ; then
echo "The unzip utility is not installed. This installer requires unzip."
exit 1
fi
# Next, we should actually ensure FZF is available, and download it if not available...
FZF_IN_PATH=0
if ! command -v "fzf" ; then
echo "FZF not found in \$PATH. As this script needs FZF, in 10 seconds, it will download FZF to /tmp/fzf."
echo "FZF will be cleaned up at the end of the script. If even this is unsatisfactory, please abort the script"
echo "within the next 10 seconds."
sleep 10
echo "Assuming ok to download FZF"
FZF_IN_PATH=1
echo "Downloading the FZF repo"
downloadZip "fzf" "https://github.com/junegunn/fzf/archive/refs/heads/master.zip"
chmod +x /tmp/fzf/install
echo "Running the FZF 'install' script with --bin as an argument"
echo "(therefore it'll only download the platform-specific binary to /tmp/fzf/bin)"
/tmp/fzf/install --bin
fi
# Now that FZF is handled, let's fetch AutoEQ
downloadZip "AutoEq" "https://github.com/jaakkopasanen/AutoEq/archive/refs/heads/master.zip"
# Time to get the user to pick their headset model
pushd "/tmp/AutoEq/results" &>/dev/null
wavFile="$(requestFile)"
# Now to copy the wav files to the correct locations
if [[ "$?" -eq 0 ]]; then
pathTo44100="/tmp/AutoEq/results/$wavFile"
pathTo48000="$(echo "${pathTo44100}" | sed 's/44100Hz/48000Hz/')"
irsFolder="${XDG_CONFIG_HOME:-$HOME/.config}/PulseEffects/irs"
if [[ ! -d "$irsFolder" ]]; then
mkdir -p "$irsFolder"
fi
cp "$pathTo44100" "${irsFolder}/44100Hz.irs"
cp "$pathTo48000" "${irsFolder}/48000Hz.irs"
echo "The impulse response files for your chosen headset are now located in the following locations"
printf "\t${pathTo44100}\n"
printf "\t${pathTo48000}\n\n"
fi
popd &>/dev/null
echo "Running cleanup routine"
[[ -d "/tmp/fzf" ]] && rm -rf /tmp/fzf
rm -rf /tmp/AutoEq
echo "Use the wavey line button in the Convolver settings to select the impulse response frequency you prefer."
echo "Also, make sure that the gstreamer1.0-convolver-pulseeffects package is installed, in order to use the convolver functionality."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment