Skip to content

Error if unsupported version in toltecctl #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
201e3b5
Error if unsupported version in toltecctl
Eeems Mar 24, 2022
d14efda
Update package
Eeems Mar 24, 2022
9faea13
Fix formatting
Eeems Mar 27, 2022
efb9543
Fix formatting
Eeems Mar 27, 2022
a90c291
Fix formatting
Eeems Mar 27, 2022
cb87ba3
Missed one
Eeems Mar 27, 2022
79f4e87
Fix force logic
Eeems Mar 27, 2022
ebe337e
Merge branch 'testing' into Eeems-patch-3
Eeems Mar 28, 2022
b302cdd
Merge branch 'testing' into Eeems-patch-3
matteodelabre Apr 2, 2022
309b202
Merge branch 'testing' into Eeems-patch-3
matteodelabre Apr 24, 2022
ae28d23
Add compatibility file and check version against this file
matteodelabre Apr 24, 2022
2a860cc
Merge branch 'testing' into Eeems-patch-3
Eeems Jul 6, 2022
7ff73f2
Merge branch 'testing' into Eeems-patch-3
Eeems Oct 1, 2022
f0da5c1
Merge branch 'testing' into Eeems-patch-3
Eeems Jan 29, 2023
2de419c
Update Compatibility
Eeems Jan 29, 2023
0d7c9f6
Merge branch 'testing' into Eeems-patch-3
Eeems Feb 12, 2023
67780ba
Merge branch 'testing' into Eeems-patch-3
Eeems May 8, 2023
53588f1
Merge branch 'testing' into Eeems-patch-3
Eeems Sep 2, 2023
c54216c
Merge branch 'testing' into Eeems-patch-3
Eeems Nov 27, 2023
9851899
Update toltec-bootstrap version number
Eeems Nov 27, 2023
9b3be3d
Remove timestamp logic
Eeems Nov 27, 2023
94d5150
Switch to using opkg compare-versions
Eeems Nov 27, 2023
dde2ccb
Fix formatting
Eeems Nov 27, 2023
cdbac7c
Fix formatting
Eeems Nov 27, 2023
96872ad
Check for minimum and maximum versions
Eeems Nov 27, 2023
be299de
Fix formatting
Eeems Nov 27, 2023
b7b42c5
Update bootstrap to check version range
Eeems Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package/Compatibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rm1-min-os-version: 2.6.1.71
rm1-max-os-version: 2.15.1.1189
rm2-min-os-version: 2.6.1.71
rm2-max-os-version: 2.15.1.1189
4 changes: 2 additions & 2 deletions package/toltec-bootstrap/package
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
pkgnames=(toltec-bootstrap)
pkgdesc="Manage your Toltec install"
url=https://toltec-dev.org/
pkgver=0.2.3-1
timestamp=2023-09-17T17:35Z
pkgver=0.3.0-1
timestamp=2023-11-27T00:34Z
section="utils"
maintainer="Eeems <[email protected]>"
license=MIT
Expand Down
118 changes: 114 additions & 4 deletions package/toltec-bootstrap/toltecctl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,72 @@ identify-model() {
esac
}

# Find the current OS release version
#
# Output: Current version in the X.Y.Z.P format
get-release-version() {
awk -F= '/RELEASE_VERSION/{print $2}' /usr/share/remarkable/update.conf
}

# Check to see if the version is supported and error if it isn't supported
#
# Arguments:
#
# $1 - Branch for which to check support
#
# Exit code:
#
# 0 - if the current version is supported
# 1 - if unsupported
# 2 - if version compatibility information could not be retrieved
check-version() {
local check_branch
local current_model
local current_version
check_branch="$1"
current_model="$(identify-model)"
current_version="$(get-release-version)"

local supported_version_min
local supported_version_max
local compat

if ! compat="$(
wget --no-verbose --output-document \
"$toltec_srv_root"/"$check_branch"/Compatibility \
2> /dev/null
)"; then
echo "Unable to fetch version compatibility information, make sure you have a stable Wi-Fi connection"
return 2
fi

supported_version_min="$(
echo "$compat" | awk "/$current_model-min-os-version/{ print \$2 }"
)"
supported_version_max="$(
echo "$compat" | awk "/$current_model-max-os-version/{ print \$2 }"
)"
local opkg_path=/home/root/.local/bin/opkg
local failed=false
if ! type -P opkg > /dev/null && ! install-standalone-opkg "$opkg_path"; then
return 1
fi
if opkg compare-versions "$current_version" '>>' "$supported_version_max" > /dev/null; then
failed=true
elif opkg compare-versions "$current_version" '<<' "$supported_version_min" > /dev/null; then
failed=true
fi
rm -f "$opkg_path"
if $failed; then
echo "You’re running an unsupported OS version: $current_version"
echo "Toltec currently supports versions between $supported_version_min and $supported_version_max"
echo "Please monitor Toltec releases for upcoming support"
return 1
fi

return 0
}

# Get the password used to login to the SSH prompt
#
# Output: SSH password
Expand Down Expand Up @@ -267,6 +333,24 @@ src/gz entware https://bin.entware.net/armv7sf-k3.2
CONF
}

# Get the current Toltec branch of this installation
#
# Output: Current branch name
get-branch() {
local srv_prefix_len=${#toltec_srv_root}
local srv_prefix="${toltec_srv_root//\//\\/}"
local awk_get_branch="
match(\$0, /$srv_prefix\/(.+)\/rmall/) {
print substr( \
\$0, \
RSTART+$srv_prefix_len+1, \
RLENGTH-$srv_prefix_len-1-6 \
)
}
"
awk "$awk_get_branch" "$opkg_conf_dir/15-toltec.conf"
}

# Set the Toltec branch for this installation
# (generate-opkg-conf must be run afterwards to rebuild the main config file)
#
Expand Down Expand Up @@ -323,10 +407,9 @@ list-installed-ordered() {
# tsort reports errors if there are dependency cycles, we ignore them
}

# Remove Toltec completely
uninstall() {
# Fetch standalone opkg used to uninstall packages
local opkg_path=/home/root/.local/bin/opkg
# Install standalone opkg binary
install-standalone-opkg() {
local opkg_path="{$1-/home/root/.local/bin/opkg}"
local opkg_remote=https://bin.entware.net/armv7sf-k3.2/installer/opkg

if ! wget --no-verbose "$opkg_remote" --output-document "$opkg_path"; then
Expand All @@ -335,6 +418,19 @@ uninstall() {
fi

chmod u+x "$opkg_path"
if [[ $(command -v opkg) != "$opkg_path" ]]; then
export PATH
PATH="$(dirname "$opkg_path"):$PATH)"
fi
}

# Remove Toltec completely
uninstall() {
local opkg_path=/home/root/.local/bin/opkg
# Fetch standalone opkg used to uninstall packages
if ! install-standalone-opkg "$opkg_path"; then
return 1
fi

# Remove installed packages in reverse dependency order
list-installed-ordered | while read -r pkgname; do
Expand Down Expand Up @@ -421,6 +517,12 @@ MSG
fi
fi

if ! check-version "$target_branch"; then
if [[ -z $force ]]; then
exit 1
fi
fi

if [[ -z $force ]] && [[ $target_branch = "testing" ]]; then
cat << MSG
Using packages from the testing branch may cause breakage or data loss.
Expand Down Expand Up @@ -456,6 +558,14 @@ MSG
;;

reenable)
force=$({ (($# > 0)) && [[ $1 = "--force" || $1 = "-f" ]] && echo 1; } || true)

if ! check-version "$(get-branch)"; then
if [[ -z $force ]]; then
exit 1
fi
fi

reenable
;;

Expand Down
6 changes: 6 additions & 0 deletions scripts/bootstrap/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ main() {
# Clean up the partial install if an uncaught error happens
trap error-cleanup ERR

if ! check-version "$toltec_branch"; then
if [[ "$1" != "--force" ]]; then
exit 1
fi
fi

log "Installing Toltec and Entware"

# Create bind mount from user directory to /opt
Expand Down
1 change: 1 addition & 0 deletions scripts/repo_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@

repo.make_index()
repo.make_listing()
repo.make_compatibility()
16 changes: 12 additions & 4 deletions scripts/toltec/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from enum import Enum, auto
import logging
import os
import shutil
import textwrap
from typing import Dict, Iterable, List, Optional, Set
import requests
Expand Down Expand Up @@ -55,10 +56,10 @@ def __init__(self, recipe_dir: str, repo_dir: str) -> None:
self.repo_dir = repo_dir
self.generic_recipes = {}

for name in os.listdir(self.recipe_dir):
if name[0] != ".":
self.generic_recipes[name] = GenericRecipe.from_file(
os.path.join(self.recipe_dir, name)
for entry in os.scandir(self.recipe_dir):
if entry.is_dir():
self.generic_recipes[entry.name] = GenericRecipe.from_file(
entry.path
)

def fetch_packages(self, remote: Optional[str]) -> GroupedPackages:
Expand Down Expand Up @@ -266,3 +267,10 @@ def make_listing(self) -> None:
# pylint: disable-next=unspecified-encoding
with open(listing_path, "w") as listing_file:
listing_file.write(template.render(sections=sections))

def make_compatibility(self) -> None:
"""Generate the OS compatibility information file."""
logger.info("Generating compatibility info")
compat_source = os.path.join(self.recipe_dir, "Compatibility")
compat_dest = self.repo_dir
shutil.copy2(compat_source, compat_dest)