#!/bin/bash

version=2026.2.0.1

install_packages python3-pip python3-dev || exit 1

wget https://download.jetbrains.com/python/pycharm-$version-aarch64.tar.gz -O pycharm.tar.gz || error "Failed to download pycharm.tar.gz"
status "Extracting pycharm.tar.gz to /opt"
sudo rm -rf /opt/pycharm && sudo mkdir -p /opt/pycharm
sudo tar xzf pycharm.tar.gz -C /opt/pycharm || error "Failed to extract pycharm.tar.gz"
sudo mv /opt/pycharm/*/* /opt/pycharm/
sudo chmod +x /opt/pycharm/bin/pycharm.sh

status "Creating desktop shortcut ..."
echo "[Desktop Entry]
Type=Application
Name=PyCharm
Icon=$(dirname "$0")/icon-64.png
Exec=/opt/pycharm/bin/pycharm.sh
Comment=Python IDE
Categories=Development;IDE;Programming;
Terminal=false
StartupWMClass=jetbrains-pycharm
StartupNotify=true" | sudo tee /usr/local/share/applications/jetbrains-pycharm.desktop

#cleanup
sudo rm -rf $HOME/pycharm.tar.gz $HOME/fsnotifier-pycharm-rpi  $HOME/fsnotifier-pycharm-rpi.zip /usr/local/share/applications/jetbrains-pycharm-ce.desktop
