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