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

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

LINPHONE_ICON_NAME="linphone520"

IMG=abc.svg
cd /usr/local/linphone-desktop/5.2.0/share/icons/hicolor/scalable/apps

echo "Which icon do you prefer for linphone-desktop 5.2.0?"
sleep 3

echo "Select a number in the list that shows up."
sleep 3
echo "Hit Ctrl + C to cancel"
sleep 3

# Show the icon selection:
xdg-open ./

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.
# To change icon for all regular linphone versions, uncomment the line.
#cp "$FILE" "/home/$USER/.local/share/icons/hicolor/scalable/apps/linphone.svg"
cp "$FILE" "/home/$USER/.local/share/icons/hicolor/scalable/apps/linphone520.svg"

echo "You can change the icon manually by exchanging the file:"
echo "/home/$USER/.local/share/icons/hicolor/scalable/apps/linphone520.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/5.2.0/share/applications/linphone520.desktop $HOME/.local/share/applications
chmod +x $HOME/.local/share/applications
sed -i "s|Icon.*|Icon=${HOME}\/\.local\/share\/icons\/hicolor\/scalable\/apps\/linphone520\.svg|g" $HOME/.local/share/applications/linphone520.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
