Tomáš Pecka | 04eb737 | 2022-06-07 08:03:04 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -ex |
| 4 | |
| 5 | SCRIPT_ROOT=$(dirname $(realpath -s $0)) |
| 6 | MIGRATIONS=$SCRIPT_ROOT/czechlight-migration-list.sh |
| 7 | export MIGRATIONS_DIRECTORY=${SCRIPT_ROOT}/migrations |
| 8 | CFG_VERSION_FILE="${CFG_VERSION_FILE:-/cfg/sysrepo/version}" |
| 9 | CFG_STARTUP_FILE="${CFG_STARTUP_FILE:-/cfg/sysrepo/startup.json}" |
| 10 | PROC_CMDLINE="${PROC_CMDLINE:-/proc/cmdline}" |
| 11 | |
| 12 | export CLA_YANG="${CLA_YANG:-/usr/share/cla-sysrepo/yang}" |
| 13 | export VELIA_YANG="${VELIA_YANG:-/usr/share/velia/yang}" |
| 14 | |
| 15 | # load migrations and perform a sanity check (filename's numerical prefix corresponds to the order in the MIGRATIONS array) |
| 16 | source $MIGRATIONS |
| 17 | for i in $(seq ${#MIGRATION_FILES[@]}); do |
| 18 | FILENAME=${MIGRATION_FILES[$(($i - 1))]} |
| 19 | |
| 20 | if ! [[ "$FILENAME" =~ ^[0-9]{4}_.*.sh$ ]]; then |
| 21 | echo "Migration file '$FILENAME' has unexpected name" |
| 22 | exit 1 |
| 23 | fi |
| 24 | |
| 25 | FILE_REV=$(echo "$FILENAME" | grep -Eo "^[0-9]{4}") |
| 26 | if [[ $((FILE_REV + 0)) != $i ]]; then |
| 27 | echo "Migration filename '$FILENAME' hints revision $(($FILE_REV + 0)) but it is at position $i of the migration array" |
| 28 | exit 1 |
| 29 | fi |
| 30 | done |
| 31 | |
| 32 | for ARG in $(cat "$PROC_CMDLINE"); do |
| 33 | case "${ARG}" in |
| 34 | czechlight=*) |
| 35 | export CZECHLIGHT="${ARG:11}" |
| 36 | ;; |
| 37 | esac |
| 38 | done |
| 39 | |
| 40 | case "${CZECHLIGHT}" in |
| 41 | sdn-roadm-line*) |
| 42 | export YANG_ROADM=1 |
| 43 | ;; |
| 44 | sdn-roadm-add-drop*) |
| 45 | export YANG_ROADM=1 |
| 46 | ;; |
| 47 | sdn-roadm-hires-add-drop*) |
| 48 | export YANG_ROADM=1 |
| 49 | ;; |
| 50 | sdn-roadm-coherent-a-d*) |
| 51 | export YANG_COHERENT=1 |
| 52 | ;; |
| 53 | sdn-inline*) |
| 54 | export YANG_INLINE=1 |
| 55 | ;; |
| 56 | calibration-box) |
| 57 | export YANG_CALIBRATION=1 |
| 58 | ;; |
| 59 | esac |
| 60 | |
| 61 | |
| 62 | # we might end up on the system |
| 63 | # * that was created before the migrations were introduced; such system does not have ${CFG_VERSION_FILE} |
| 64 | # * that was just created and freshly initialized with firmware; it has ${CFG_VERSION_FILE} but startup.json does not exist |
| 65 | if [[ -r "$CFG_VERSION_FILE" && -f "$CFG_STARTUP_FILE" ]]; then |
| 66 | CURRENT_VERSION="$(cat ${CFG_VERSION_FILE})" |
| 67 | else |
| 68 | CURRENT_VERSION=0 |
| 69 | fi |
| 70 | |
| 71 | if [[ ! "$CURRENT_VERSION" =~ ^[0-9]+$ ]]; then |
| 72 | echo "Invalid version '$CURRENT_VERSION'" |
| 73 | exit 1 |
| 74 | fi |
| 75 | |
| 76 | while [[ $CURRENT_VERSION -lt ${#MIGRATION_FILES[@]} ]]; do |
| 77 | /bin/bash ${SCRIPT_ROOT}/migrations/${MIGRATION_FILES[$CURRENT_VERSION]} |
| 78 | CURRENT_VERSION=$(($CURRENT_VERSION + 1)) |
| 79 | done |
| 80 | |
| 81 | # store current version and save startup.json |
| 82 | sysrepocfg -d startup -f json -X > "$CFG_STARTUP_FILE" |
| 83 | echo "$CURRENT_VERSION" > "$CFG_VERSION_FILE" |
| 84 | |
| 85 | # If not do not copy here from startup -> running, running might be stale. |
| 86 | sysrepocfg -C startup |