#!/usr/bin/env bash
# Change linphone icon

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd $SCRIPT_DIR
echo

LINPHONE_ICON_NAME="linphone446beta0"

echo "Which icon do you prefer for linphone-desktop 4.4.6-beta.0?"
sleep 3
echo "Select a number in the list that shows up."
sleep 3
echo "Hit Ctrl + C to cancel"
sleep 3

cd ../linphone-desktop/4.4.6-beta.0/share/icons/hicolor/scalable/apps
# Show the icon selection:
xdg-open ./

IMG=abc.svg


FILE=a
select file in $(ls *.svg); do 
   echo $REPLY $file
   FILE=$file
   break
done

mkdir -p "/home/$USER/.local/share/icons/hicolor/scalable/apps"
if [ ! -f "/home/$USER/.local/share/icons/hicolor/index.theme" ]; then
    cp "/usr/share/icons/hicolor/index.theme" "/home/$USER/.local/share/icons/hicolor/index.theme"    
fi

# We only want to change the icon on this version.
cp "$FILE" "/home/$USER/.local/share/icons/hicolor/scalable/apps/linphone446beta0.svg"

echo "You can change the icon by exchanging the file:"
echo "/home/$USER/.local/share/icons/hicolor/scalable/apps/linphone446beta0.svg"
sleep 5
echo "The folder will be opened for you now."
sleep 3
xdg-open "/home/$USER/.local/share/icons/hicolor/scalable/apps/" &

cp /usr/local/linphone-desktop/4.4.6-beta.0/share/applications/linphone446-beta0.desktop $HOME/.local/share/applications
chmod +x $HOME/.local/share/applications
sed -i "s|Icon.*|Icon=${HOME}\/\.local\/share\/icons\/hicolor\/scalable\/apps\/linphone446beta0\.svg|g" $HOME/.local/share/applications/linphone446-beta0.desktop
touch $HOME/.local/share/icons/hicolor
gtk-update-icon-cache $HOME/.local/share/icons/hicolor

touch "/home/$USER/.local/share/icons/hicolor"
gtk-update-icon-cache "/home/$USER/.local/share/icons/hicolor"

exit 0
