blob: fd49f60df072bc8eb3fd7986ea82219b8f9fdaa3 [file] [log] [blame]
Tomáš Pecka04eb7372022-06-07 08:03:04 +02001#!/bin/bash
2
3set -ex
4
5SCRIPT_ROOT=$(dirname $(realpath -s $0))
6MIGRATIONS=$SCRIPT_ROOT/czechlight-migration-list.sh
7export MIGRATIONS_DIRECTORY=${SCRIPT_ROOT}/migrations
8CFG_VERSION_FILE="${CFG_VERSION_FILE:-/cfg/sysrepo/version}"
9CFG_STARTUP_FILE="${CFG_STARTUP_FILE:-/cfg/sysrepo/startup.json}"
10PROC_CMDLINE="${PROC_CMDLINE:-/proc/cmdline}"
11
12export CLA_YANG="${CLA_YANG:-/usr/share/cla-sysrepo/yang}"
13export 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)
16source $MIGRATIONS
17for 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
30done
31
32for ARG in $(cat "$PROC_CMDLINE"); do
33 case "${ARG}" in
34 czechlight=*)
35 export CZECHLIGHT="${ARG:11}"
36 ;;
37 esac
38done
39
40case "${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 ;;
59esac
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
65if [[ -r "$CFG_VERSION_FILE" && -f "$CFG_STARTUP_FILE" ]]; then
66 CURRENT_VERSION="$(cat ${CFG_VERSION_FILE})"
67else
68 CURRENT_VERSION=0
69fi
70
71if [[ ! "$CURRENT_VERSION" =~ ^[0-9]+$ ]]; then
72 echo "Invalid version '$CURRENT_VERSION'"
73 exit 1
74fi
75
76while [[ $CURRENT_VERSION -lt ${#MIGRATION_FILES[@]} ]]; do
77 /bin/bash ${SCRIPT_ROOT}/migrations/${MIGRATION_FILES[$CURRENT_VERSION]}
78 CURRENT_VERSION=$(($CURRENT_VERSION + 1))
79done
80
81# store current version and save startup.json
82sysrepocfg -d startup -f json -X > "$CFG_STARTUP_FILE"
83echo "$CURRENT_VERSION" > "$CFG_VERSION_FILE"
84
85# If not do not copy here from startup -> running, running might be stale.
86sysrepocfg -C startup