Skip to content

Instantly share code, notes, and snippets.

@shanebrowncs
Last active September 16, 2016 02:13
Show Gist options
  • Save shanebrowncs/15e45c4b630d4e2080b23b6f35939b88 to your computer and use it in GitHub Desktop.
Save shanebrowncs/15e45c4b630d4e2080b23b6f35939b88 to your computer and use it in GitHub Desktop.
Adds downloaded osu beatmaps(.osz) to opsu
#!/bin/bash
#|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Author: Shane "SajeOne" Brown
# Date: 15/09/2016
# Description: Adds downloaded osu beatmaps(.osz) to opsu
# Revision: 2 - Fixed messy output
#|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FILES="./*"
function handleExit(){
if [ -z "$1" ]; then
return 1
fi
if [ $1 -ne 0 ]; then
echo "command failed, stopping execution"
exit 1
fi
}
function installMap(){
# Guards
if [ -z "$1" ]; then
return 1
fi
if [ ! -d "$XDG_DATA_HOME/opsu" ]; then
echo "Opsu directory does not exist, is XDG_DATA_HOME defined?"
exit 1
fi
NAME=$(basename "$1" .osz)
echo -e "\n================\nInstalling $NAME\n================"
mkdir "$NAME" >/dev/null
handleExit $?
echo "created song directory"
mv "$1" "$NAME/" >/dev/null
handleExit $?
echo "moved osz to new directory"
cd "$NAME" >/dev/null
handleExit $?
echo "changed to new dir"
unzip "$1" >/dev/null
handleExit $?
echo "unzipped archive"
mv "$1" "./../completed" >/dev/null
handleExit $?
echo "moved archive to completed"
cd .. >/dev/null
handleExit $?
echo "exited temp dir"
mv "$NAME" "$XDG_DATA_HOME/opsu/Songs" >/dev/null
handleExit $?
echo "moved temp dir to opsu songs"
}
if [ ! -z $1 ] && [ -d "$1" ]; then
FILES="$1"
fi
for f in $FILES; do
if [ ${f: -4} == ".osz" ]; then
installMap "$f"
echo -e "\n### Completed Successfully ###"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment