-
Notifications
You must be signed in to change notification settings - Fork 9
/
installer-for-linux
112 lines (98 loc) · 4.28 KB
/
installer-for-linux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash -eu
set -e
VERSION=4.1.7
VARIANT=thonny
ARCHITECTURE="$(uname -m)"
if [[ "$ARCHITECTURE" == "x86_64" ]]; then
echo
echo "This script will download and install Thonny ($VARIANT-$VERSION) for Linux (32 or 64-bit PC)."
read -p "Press ENTER to continue or Ctrl+C to cancel."
FILENAME=$VARIANT-$VERSION-$ARCHITECTURE.tar.gz
URL="https://github.com/thonny/thonny/releases/download/v$VERSION/$FILENAME"
echo "Downloading $URL"
TMPDIR=$(mktemp -d -p .)
wget -O $TMPDIR/$FILENAME $URL
tar -zxf $TMPDIR/$FILENAME -C $TMPDIR
$TMPDIR/thonny/install
rm -rf $TMPDIR
echo
read -p "Press ENTER to exit the installer."
else
echo "Thonny only provides pre-built bundles for x86_64 (not $ARCHITECTURE)."
TARGET=~/apps/thonny
PYVER="$(python3 -V 2>&1)"
GOODVER="Python 3\.(8|9|10|11|12)\.*"
if [[ "$PYVER" =~ $GOODVER ]]; then
PYLOC="$(which python3 2>&1)"
echo "I could install Thonny into a venv under your existing $PYVER ($PYLOC)."
read -p "Press ENTER to continue or Ctrl+C to cancel."
# Install non-pip dependencies
if [[ -f /etc/debian_version ]]; then
if ! dpkg -s python3-tk > /dev/null ; then
echo "Going to install 'python3-tk' first"
sudo apt-get install python3-tk
fi
if ! dpkg -s python3-venv > /dev/null ; then
echo "Going to install 'python3-venv' first"
sudo apt-get install python3-venv
fi
elif [[ -f /etc/redhat-release ]]; then
if rpm -qa | grep python3-tkinter > /dev/null ; then
echo "Going to install 'python3-tkinter' first"
sudo yum install python3-tkinter
fi
elif [[ -f /etc/SuSE-release ]]; then # TODO: this file is deprecated
if ! rpm -qa | grep python3-tkinter > /dev/null ; then
echo "Going to install 'python3-tkinter' first"
sudo zypper install python3-tkinter
fi
elif [[ -f /etc/arch-release ]]; then
if ! pacman -Qi tk > /dev/null ; then
echo "Going to install 'tk' first"
sudo pacman -S tk
fi
else
echo "Can't determine your package manager, assuming Tkinter and venv are present."
fi
if [[ -d $TARGET ]]; then
echo "Removing existing Thonny installation at $TARGET"
rm -rf $TARGET
fi
echo "Creating virtual environment for Thonny"
python3 -m venv $TARGET
echo "Marking virtual environment as private to Thonny"
echo ";Existence of this file indicates that Python in this directory is private for Thonny" > ${TARGET}/bin/thonny_python.ini
echo "Installing Thonny's dependencies"
$TARGET/bin/pip3 install 'jedi==0.19.*' 'pyserial==3.5' 'pylint==3.2.*' 'docutils==0.21.*' 'mypy==1.11.*' 'asttokens==2.4.*' 'Send2Trash==1.8.*' 'esptool==4.8.*' 'paramiko==3.4.*' 'websockets==13.0.*' 'ptyprocess==0.7.*; sys_platform == "linux" or sys_platform == "darwin"' 'dbus-next==0.2.*; sys_platform == "linux"' 'adafruit_board_toolkit==1.1.*; sys_platform == "win32" or sys_platform == "darwin"'
echo "Installing Thonny and its dependencies"
$TARGET/bin/pip3 install thonny==${VERSION}
echo "Creating the launcher"
LAUNCHER=~/.local/share/applications/Thonny.desktop
SITE_PACKAGES=$($TARGET/bin/python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')
echo "[Desktop Entry]" > $LAUNCHER
echo "Type=Application" >> $LAUNCHER
echo "Name=Thonny" >> $LAUNCHER
echo "GenericName=Python IDE" >> $LAUNCHER
echo "Exec=$TARGET/bin/thonny %F" >> $LAUNCHER
echo "Comment=Python IDE for beginners" >> $LAUNCHER
echo "Icon=$SITE_PACKAGES/thonny/res/thonny.png" >> $LAUNCHER
echo "StartupWMClass=Thonny" >> $LAUNCHER
echo "Terminal=false" >> $LAUNCHER
echo "Categories=Development;IDE" >> $LAUNCHER
echo "Keywords=programming;education" >> $LAUNCHER
echo "MimeType=text/x-python;" >> $LAUNCHER
echo "Actions=Edit;" >> $LAUNCHER
echo "" >> $LAUNCHER
echo "[Desktop Action Edit]" >> $LAUNCHER
echo "Exec=$TARGET/bin/thonny %F" >> $LAUNCHER
echo "Name=Edit with Thonny" >> $LAUNCHER
UNINSTALLER="${TARGET}/bin/uninstall"
echo "Creating the uninstaller ($UNINSTALLER)"
echo "#!/usr/bin/env bash" > $UNINSTALLER
echo "rm -rf $TARGET"
echo "rm $LAUNCHER"
else
echo "Can't offer alternatives as your system doesn't seem to have suitable Python interpreter."
exit 1
fi
fi