blob: 20460102308b3cff804f64a77ac965b451612c1a [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}"
Tomáš Pecka742c7ec2022-10-03 13:49:57 +020014export ALARMS_YANG="${ALARMS_YANG:-/usr/share/sysrepo-ietf-alarms/yang}"
Tomáš Pecka04eb7372022-06-07 08:03:04 +020015
16# load migrations and perform a sanity check (filename's numerical prefix corresponds to the order in the MIGRATIONS array)
17source $MIGRATIONS
18for 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
31done
32
33for ARG in $(cat "$PROC_CMDLINE"); do
34 case "${ARG}" in
35 czechlight=*)
36 export CZECHLIGHT="${ARG:11}"
37 ;;
38 esac
39done
40
41case "${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 ;;
60esac
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
66if [[ -r "$CFG_VERSION_FILE" && -f "$CFG_STARTUP_FILE" ]]; then
67 CURRENT_VERSION="$(cat ${CFG_VERSION_FILE})"
68else
69 CURRENT_VERSION=0
70fi
71
72if [[ ! "$CURRENT_VERSION" =~ ^[0-9]+$ ]]; then
73 echo "Invalid version '$CURRENT_VERSION'"
74 exit 1
75fi
76
77while [[ $CURRENT_VERSION -lt ${#MIGRATION_FILES[@]} ]]; do
78 /bin/bash ${SCRIPT_ROOT}/migrations/${MIGRATION_FILES[$CURRENT_VERSION]}
79 CURRENT_VERSION=$(($CURRENT_VERSION + 1))
80done
81
82# store current version and save startup.json
Jan Kundrát92a20e22023-02-24 18:13:01 +010083mkdir -p $(dirname ${CFG_STARTUP_FILE}) $(dirname ${CFG_VERSION_FILE})
Tomáš Pecka04eb7372022-06-07 08:03:04 +020084sysrepocfg -d startup -f json -X > "$CFG_STARTUP_FILE"
85echo "$CURRENT_VERSION" > "$CFG_VERSION_FILE"
86
87# If not do not copy here from startup -> running, running might be stale.
88sysrepocfg -C startup