#!/usr/bin/env bash
## pycharm python ide

# https://en.wikipedia.org/wiki/PyCharm
# https://www.jetbrains.com/pycharm/download/#section=linux
# https://www.jetbrains.com/pycharm/download/download-thanks.html?platform=linux&code=PCC
UPDATE_URL="https://www.jetbrains.com/help/pycharm/update.html"

PYCHARM_VERSION=2023.3.3

cd /var/tmp || exit && wget -c https://download.jetbrains.com/python/pycharm-community-${PYCHARM_VERSION}.tar.gz && tar xzvf /var/tmp/pycharm-community-${PYCHARM_VERSION}.tar.gz 

# cd /var/tmp || exit && wget -c https://download.jetbrains.com/python/pycharm-professional-${PYCHARM_VERSION}.tar.gz && tar xzvf /var/tmp/pycharm-professional-${PYCHARM_VERSION}.tar.gz


cd /var/tmp/pycharm-community-"${PYCHARM_VERSION}" || exit

cat << EF > ./install_pycharm.sh
PYCHARM_VERSION=${PYCHARM_VERSION}
cd /var/tmp || exit
#wget -c http://download.jetbrains.com/python/pycharm-community-${PYCHARM_VERSION}.tar.gz
tar xzvf /var/tmp/pycharm-community-${PYCHARM_VERSION}.tar.gz -C /opt
ln -sf /opt/pycharm-community-${PYCHARM_VERSION} /opt/pycharm
ln -sf /opt/pycharm/bin/pycharm.sh /usr/local/bin/pycharm
ln -sf /opt/pycharm/bin/inspect.sh /usr/local/bin/inspect

cat << EOF > /opt/pycharm/pycharm.desktop
[Desktop Entry]
Type=Application
Name=pyCharm IDE
GenericName=Integrated Development Environment
Comment=An IDE for the python programming language
Exec=/opt/pycharm/bin/pycharm.sh
Icon=/opt/pycharm/bin/pycharm.png
Terminal=false
Categories=Development;IDE;Electronics;
MimeType=text/x-python
Keywords=python;programming;ide;
EOF
EF

cat << EOF > ./description-pak
PyCharm is an integrated development environment (IDE) used for the Python language.

Coding assistance and analysis, with code completion, syntax and error highlighting, linter integration.
Python refactoring: extract method, introduce variable, introduce constant, pull up and push down.
Support for web frameworks: Django, web2py and Flask
Integrated Python debugger.
Integrated unit testing, with line-by-line code coverage.
Google App Engine Python development.
Version control integration: unified user interface for git.
EOF

echo 'checkinstall -y --fstrans=no --install=no bash ./install_pycharm.sh 2>&1 | tee err' > checkinstall_pycharm.sh && bash ./checkinstall_pycharm.sh
dpkg -i /var/tmp/pycharm-community-"${PYCHARM_VERSION}"/pycharm-community_"${PYCHARM_VERSION}"-1_amd64.deb

