Skip to content

Commit

Permalink
tweak upgrade system, add maintenance mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kizniche committed Nov 10, 2019
1 parent 9235ad5 commit 46b23e5
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 50 deletions.
7 changes: 2 additions & 5 deletions install/install
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
# curl -L https://raw.githubusercontent.com/kizniche/Mycodo/master/install/install | bash
#

printf "Mycodo installation is currently disabled while the upgrade system is tested"
exit 1

if [ -d ~/Mycodo ]; then
printf "\n## Error: Install aborted. Cause: The ~/Mycodo directory already exists. The install cannot continue because a previous Mycodo install was detected. Please either move or delete the ~/Mycodo directory and rerun this script to initiate the install.\n"
exit 1
printf "\n## Error: Install aborted. Cause: The ~/Mycodo directory already exists. The install cannot continue because a previous Mycodo install was detected. Please either move or delete the ~/Mycodo directory and rerun this script to initiate the install or run ~/Mycodo/install/setup.sh.\n"
exit 1
fi

sudo apt-get install -y jq whiptail
Expand Down
15 changes: 15 additions & 0 deletions install/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ if [ "$EUID" -ne 0 ]; then
exit 1
fi

# Maintenance mode
# This is a temporary state so the developer can test a version release before users can install.
# Creating the file ~/Mycodo/.maintenance will override maintenece mode.
if python "${CURRENT_MYCODO_DIRECTORY}"/mycodo/scripts/upgrade_check.py --maintenance_mode; then
if [[ ! -e $INSTALL_DIRECTORY/.maintenance ]]; then
printf "The Mycodo upgrade system is currently in maintenance mode so the developer can test the latest code.\n"
printf "Please wait and attempt the install later.\n"
printf "Note: You will need to delete the ~/Mycodo directory that was just downloaded and re-run the install command:\n"
printf "cd ~\n"
printf "rm -rf ~/Mycodo\n"
printf "curl -L https://raw.githubusercontent.com/kizniche/Mycodo/master/install/install | bash\n"
exit 1
fi
fi

WHIPTAIL=$(command -v whiptail)
exitstatus=$?
if [ $exitstatus != 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion mycodo/config_devices_units.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# config_units.py - Mycodo unit settings
# config_devices_units.py - Mycodo device unit settings
#

from flask_babel import lazy_gettext
Expand Down
10 changes: 10 additions & 0 deletions mycodo/config_maintenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
#
# config_maintenance.py - Global Mycodo settings
#

# Maintenance Mode
# Prevents users from installing or upgrading Mycodo
# Used by the developers to test the install/upgrade system for stability prior to release

MAINTENANCE_MODE = True
22 changes: 11 additions & 11 deletions mycodo/mycodo_flask/templates/admin/upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@
current_latest_release != '0.0.0' and
upgrade != 1 %}

<div style="padding: 0.5em 0">
<p style="padding-top: 0.5em">
Installed version: <a href="https://github.com/kizniche/Mycodo/releases/tag/v{{current_release}}" target="_blank">{{current_release}}</a>
<br>Latest version: <a href="https://github.com/kizniche/Mycodo/releases/tag/v{{current_latest_release}}" target="_blank">{{current_latest_release}}</a>
</div>
<div style="padding: 0.5em 0">
<br>Refer to the <a href="https://github.com/kizniche/Mycodo/blob/master/CHANGELOG.md" target="_blank">Changelog</a> for a list of all changes.
</div>
<p>Major version upgrade: <a href="https://github.com/kizniche/Mycodo/releases/tag/v{{current_latest_major_version}}.0.0" target="_blank">{{current_latest_major_version}}.0.0</a></p>
<p style="font-weight: bold; color: red">Version incompatibility detected!</p>
<p>Your current version, {{current_release}}, is not compatible with an upgrade to {{current_latest_major_version}}.x. If you choose to upgrade, no settings or configurations will be transferred to v{{current_latest_release}}, so it is advisable to backup these settings by either saving the settings database (~/Mycodo/databases/mycodo.db) or writing down information (GPIO pins, PID settings, etc.).</p>
<p>In come cases, there may be extenuating circumstances preventing an upgrade, even if the settings database is wiped. If this is the case, the upgrade script will inform you of the issue upon attempting to perform the upgrade.</p>
<p>If you would like to attempt to upgrade Mycodo to v{{current_latest_release}}, select the button below.</p>
</p>
<p>
Refer to the <a href="https://github.com/kizniche/Mycodo/blob/master/CHANGELOG.md" target="_blank">Changelog</a> for a full list of changes.
<br>Major version changes: <a href="https://github.com/kizniche/Mycodo/releases/tag/v{{current_latest_major_version}}.0.0" target="_blank">{{current_latest_major_version}}.0.0</a>
</p>
<p style="font-weight: bold; color: red">Major version change detected!</p>
<p>A new major version has been released on GitHub: v{{current_latest_major_version}} (currently at v{{current_latest_release}}). This usually means there are system-breaking changes for some or all users, and if you choose to upgrade, your system settings may not be able to be preserved. It is advisable to backup these settings by either <a href="/export">exporting</a> the settings database (~/Mycodo/databases/mycodo.db) or making note of important information (GPIO pins, PID settings, etc.).</p>
<p>However, there may be cases where the settings database can be preserved during the upgrade. There may be other cases that an upgrade is not possible, even if the settings database is wiped. This will be dependent on both your currently installed version and the current version available for upgrade and won't be known until an upgrade is attempted. The upgrade script will inform you of any of these situations after the upgrade is initiated.</p>
<p>If you would like to attempt to upgrade Mycodo to v{{current_latest_release}}, select the button below.</p>
<div class="form-inline" style="padding-bottom: 1em">
<form method="post" action="/admin/upgrade">
<input type="hidden" name="form-name" value="upgrade">
{{form_upgrade.csrf_token}}
<div>
<div class="form-group">
{{form_upgrade.upgrade_next_major_version(class_='btn btn-primary', **{'onclick':'return confirm("Your settings database will not be transfered if you choose to upgrade. IT WILL BE DELETED. Confirm that you really want to do this.")'})}}
{{form_upgrade.upgrade_next_major_version(class_='btn btn-primary', **{'onclick':'return confirm("Your settings database may not be preserved if you choose to upgrade. Confirm that you really want to do this.")'})}}
</div>
</div>
</form>
Expand Down
28 changes: 0 additions & 28 deletions mycodo/scripts/meets_python_version.py

This file was deleted.

26 changes: 26 additions & 0 deletions mycodo/scripts/upgrade_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Perform checks used during install/upgrade

import os
import sys

sys.path.append(os.path.abspath(os.path.join(__file__, "../../..")))

from mycodo.config_maintenance import MAINTENANCE_MODE

if __name__ == "__main__":
try:
if sys.argv[1] == '--min_python_version':

if not sys.version_info.major >= int(sys.argv[2].split('.')[0]):
sys.exit(1)
if not sys.version_info.minor >= int(sys.argv[2].split('.')[1]):
sys.exit(1)

elif sys.argv[1] == '--maintenance_mode':

if not MAINTENANCE_MODE:
sys.exit(1)

except:
sys.exit(1)
2 changes: 1 addition & 1 deletion mycodo/scripts/upgrade_download.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Downloads the upgrade file
# Downloads the version of Mycodo to upgrade to

exec 2>&1

Expand Down
17 changes: 13 additions & 4 deletions mycodo/scripts/upgrade_install.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash
# Upgrade from a previous release to this current release.
# Check currently-installed version for the ability to upgrade to this release version.
# If not in the list of versions able to upgrade from, present error to the user.
# If in the list of versions able to upgrade from, proceed with upgrade.

exec 2>&1

Expand Down Expand Up @@ -54,18 +52,29 @@ runSelfUpgrade() {

printf "#### Beginning pre-upgrade checks ####\n"

# Maintenance mode
# This is a temporary state so the developer can test a version release before users can upgrade.
# Creating the file ~/Mycodo/.maintenance will override maintenece mode.
if python "${CURRENT_MYCODO_DIRECTORY}"/mycodo/scripts/upgrade_check.py --maintenance_mode; then
if [[ ! -e $CURRENT_MYCODO_DIRECTORY/.maintenance ]]; then
printf "The Mycodo upgrade system is currently in maintenance mode so the developer can test the latest upgrade.\n"
printf "Please wait and attempt the upgrade later.\n"
exit 1
fi
fi

# Upgrade requires Python >= 3.6
printf "Checking Python version...\n"
if hash python3 2>/dev/null; then
if ! python3 "${CURRENT_MYCODO_DIRECTORY}"/mycodo/scripts/meets_python_version.py --version "3.6"; then
if ! python3 "${CURRENT_MYCODO_DIRECTORY}"/mycodo/scripts/upgrade_check.py --min_python_version "3.6"; then
printf "Incorrect Python version found. Mycodo requires Python >= 3.6.\n"
printf "If you're running Raspbian 9 (Stretch, Python 3.5), you will need to upgrade to at least Raspbian 10 (Buster, Python 3.7) to use the latest version of Mycodo\n"
exit 1
else
printf "Python >= 3.6 found."
fi
else
printf "Error: python3 not found. Cannot proceed with upgrade without python3.\n"
printf "Error: python3 not found. Cannot proceed with upgrade without python3 (Python >= 3.6).\n"
exit 1
fi

Expand Down

0 comments on commit 46b23e5

Please sign in to comment.