#!/bin/bash
# Make symbolic link
sudo ln -sf `ls /Applications/YAMAHA/StudioManager/lib/libsm2-dm1k_o1v96_resources.1.*.dylib| tail -n 1`  /usr/lib/libsm2-dm1k_o1v96_resources.1.dylib

# install manual
# get Finder language
myuid=$(ps alxwww|grep Installer.app|head -n 1|cut -c 3-5)
toplang=$(sudo -u \#${myuid} defaults read NSGlobalDomain AppleLanguages|tr -d ' \n()'|cut -c 1-2)
if [ ${toplang}  = "ja" -o ${toplang}  = "Ja" ]
then
    # this is Japanese
    cp -p "/Library/Application Support/Yamaha/SM2/Plugins/JapaneseManual/SM_01V96.pdf" "/Library/Application Support/Yamaha/SM2/Plugins/01V96.plugin/Contents/Resources"
    cp -p "/Library/Application Support/Yamaha/SM2/Plugins/JapaneseManual/SM_01V96.pdf" "/Applications/YAMAHA/StudioManager/SM2.app/Contents/Resources/"
elif [ ${toplang}  = "de" -o ${toplang}  = "Ge" ]
then 
    # this is German
    cp -p "/Library/Application Support/Yamaha/SM2/Plugins/GermanManual/SM_01V96.pdf" "/Library/Application Support/Yamaha/SM2/Plugins/01V96.plugin/Contents/Resources"
    cp -p "/Library/Application Support/Yamaha/SM2/Plugins/GermanManual/SM_01V96.pdf" "/Applications/YAMAHA/StudioManager/SM2.app/Contents/Resources/"
elif [ ${toplang}  = "fr" -o ${toplang}  = "Fr" ]
then 
    # this is French
    cp -p "/Library/Application Support/Yamaha/SM2/Plugins/FrenchManual/SM_01V96.pdf" "/Library/Application Support/Yamaha/SM2/Plugins/01V96.plugin/Contents/Resources"
    cp -p "/Library/Application Support/Yamaha/SM2/Plugins/FrenchManual/SM_01V96.pdf" "/Applications/YAMAHA/StudioManager/SM2.app/Contents/Resources/"
elif [ ${toplang}  = "es" -o ${toplang}  = "Sp" ]
then 
    # this is Spanish
    cp -p "/Library/Application Support/Yamaha/SM2/Plugins/SpanishManual/SM_01V96.pdf" "/Library/Application Support/Yamaha/SM2/Plugins/01V96.plugin/Contents/Resources"
    cp -p "/Library/Application Support/Yamaha/SM2/Plugins/SpanishManual/SM_01V96.pdf" "/Applications/YAMAHA/StudioManager/SM2.app/Contents/Resources/"
else
    # this is other language(use English)
    cp -p "/Library/Application Support/Yamaha/SM2/Plugins/EnglishManual/SM_01V96.pdf" "/Library/Application Support/Yamaha/SM2/Plugins/01V96.plugin/Contents/Resources"
    cp -p "/Library/Application Support/Yamaha/SM2/Plugins/EnglishManual/SM_01V96.pdf" "/Applications/YAMAHA/StudioManager/SM2.app/Contents/Resources/"
fi
# delete work files
rm -rf "/Library/Application Support/Yamaha/SM2/Plugins/JapaneseManual/"
rm -rf "/Library/Application Support/Yamaha/SM2/Plugins/GermanManual/"
rm -rf "/Library/Application Support/Yamaha/SM2/Plugins/FrenchManual/"
rm -rf "/Library/Application Support/Yamaha/SM2/Plugins/EnglishManual/"
rm -rf "/Library/Application Support/Yamaha/SM2/Plugins/SpanishManual/"
exit
