This repository has been archived by the owner on Oct 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
New upgrade script for Python. #131
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
944b77a
Added upgrade script for python
ludeeus d7b86f2
typo
ludeeus b1ea75f
typo
ludeeus 4ee7323
Fix for stickler-ci
ludeeus 3e73de0
typo
ludeeus e9402a2
Futureproofing
ludeeus e09fdba
More futureproofing
ludeeus db8d08f
move "backup"
ludeeus 56430f0
Premission issues
ludeeus 5f28483
Fix for validation
ludeeus bc1c035
Revert steps
ludeeus bdb74a9
minor change
ludeeus 6e39e5e
Corrections from review, and multiple warnings
ludeeus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Description | ||
This script will upgrade Python to the latest stable version. | ||
It will also create a new virtual environment to be used for Home Assistant. | ||
|
||
## Upgrade | ||
``` | ||
$ sudo hassbian-config upgrade python | ||
``` | ||
|
||
## Additional info | ||
If you have installed additional components directly to `/srv/homeassistant/` like `libcec` thoese will need to be reinstalled. | ||
|
||
*** | ||
This script was originally contributed by [@Ludeeus](https://github.com/ludeeus). | ||
With inspiration from: [blog.ceard.tech](https://blog.ceard.tech/2017/12/upgrading-python-virtual-environment.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/bin/bash | ||
|
||
function python-show-short-info { | ||
echo "Upgrades python3 and virtual environment to the newest version." | ||
} | ||
|
||
function python-show-long-info { | ||
echo "Upgrades python3 and virtual environment to the newest version." | ||
} | ||
|
||
function python-show-copyright-info { | ||
echo "This script was originally contributed by Ludeeus <https://github.com/ludeeus>." | ||
} | ||
|
||
function python-upgrade-package { | ||
python-show-short-info | ||
python-show-copyright-info | ||
PYTHONVERSION=$(curl -s https://www.python.org/downloads/source/ | grep "Latest Python 3 Release" | cut -d "<" -f 3 | awk -F ' ' '{print $NF}') | ||
|
||
echo "Installing Python $PYTHONVERSION" | ||
apt-get -y update | ||
apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev | ||
apt-get install libtcmalloc-minimal4 | ||
export LD_PRELOAD="/usr/lib/libtcmalloc_minimal.so.4" | ||
cd /tmp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 'cd ... || exit' or 'cd ... || return' in case cd fails. |
||
wget https://www.python.org/ftp/python/"$PYTHONVERSION"/Python-"$PYTHONVERSION".tar.xz | ||
tar xf Python-"$PYTHONVERSION".tar.xz | ||
cd Python-"$PYTHONVERSION" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 'cd ... || exit' or 'cd ... || return' in case cd fails. |
||
./configure --enable-optimizations | ||
make | ||
apt -y autoremove | ||
rm -r /tmp/Python-"$PYTHONVERSION" | ||
rm /tmp/Python-"$PYTHONVERSION".tar.xz | ||
echo "Done" | ||
|
||
echo "Stopping Home Assistant." | ||
systemctl stop home-assistant@homeassistant.service | ||
|
||
echo "Backing up previous virutal enviorment." | ||
mv /srv/homeassistant /srv/homeassistant_old | ||
sudo -u homeassistant -H /bin/bash << EOF | ||
source /srv/homeassistant/bin/activate | ||
pip3 freeze —local > /tmp/requirements.txt | ||
deactivate | ||
EOF | ||
|
||
echo "Creating new virutal enviorment using Python $PYTHONVERSION" | ||
python3.6 -m venv /srv/homeassistant | ||
sudo chown homeassistant:homeassistant /srv/homeassistant | ||
sudo mv /srv/homeassistant_old/hassbian /srv/homeassistant/hassbian | ||
sudo apt-get install python3-pip python3-dev | ||
sudo pip3 install --upgrade virtualenv | ||
sudo -u homeassistant -H /bin/bash << EOF | ||
source /srv/homeassistant/bin/activate | ||
pip3 install -r /tmp/requirements.txt | ||
pip3 install --upgrade homeassistant | ||
deactivate | ||
EOF | ||
mv /home/homeassistant/.homeassistant/deps /home/homeassistant/.homeassistant/deps_old | ||
|
||
echo "Starting Home Assistant." | ||
sudo curl -o /etc/systemd/system/home-assistant@homeassistant.service https://raw.githubusercontent.com/home-assistant/hassbian-scripts/dev/package/etc/systemd/system/home-assistant%40homeassistant.service | ||
sudo systemctl enable home-assistant@homeassistant.service | ||
sudo systemctl daemon-reload | ||
sudo systemctl start home-assistant@homeassistant.service | ||
|
||
echo "Checking the installation..." | ||
validation=$(sudo -u homeassistant -H /bin/bash << EOF | grep Version | awk '{print $2}' | ||
source /srv/homeassistant/bin/activate | ||
python -V | ||
EOF | ||
) | ||
if [ "$validation" == "Python $PYTHONVERSION" ]; then | ||
echo | ||
echo -e "\\e[3231mUpgrade done..\\e[0m" | ||
echo | ||
else | ||
echo | ||
echo -e "\\e[31mUpgrade failed..." | ||
echo -e "\\e[31mReverting..." | ||
echo -e "\\e[0mIf you have issues with this script, please say something in the #devs_hassbian channel on Discord." | ||
echo | ||
return 1 | ||
fi | ||
return 0 | ||
} | ||
|
||
[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add information that this is not recommended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better now? :)