#!/usr/bin/env bash

# Setup logging to both console and log file
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
LOG_FILE="$SCRIPT_DIR/urmagic-fix-urup-ranges.log"
exec > >(tee -a "$LOG_FILE")
exec 2> >(tee -a "$LOG_FILE" >&2)

set -ex

# - if urup_versions[1] < 26:
# + if system_versions[1] >= 26 and urup_versions[1] < 26:
PYTHON_FILE="/usr/lib/python2.7/dist-packages/urup/main.py"
PYTHONC_FILE="${PYTHON_FILE}c"
ERRONEOUS_STRING="if urup_versions\[1\] < 26\:"
CORRECT_STRING="if system_versions[1] >= 26 and urup_versions[1] < 26:"

sed -i "s|$ERRONEOUS_STRING|$CORRECT_STRING|g" "$PYTHON_FILE"
rm -f "$PYTHONC_FILE"