#!/usr/bin/env bash

# Enable unofficial strict mode
set -e # Exit immediately if any command exits with non-zero status;
       # use `cmd || cmd2` if `cmd` must fail, `cmd || true` if it may fail
set -u # Reading a variable not previously defined raises an error
set -o pipefail # if a cmd in the pipeline fails, its return status is the whole pipeline return status
IFS=$'\n\t' # internal field separator
# remember to use `trap (cleanup_function) EXIT` for cleanup. To remove trap, use `-` as cleanup_function
# use `local` for local variables
# use `readonly` for constants, `local -r` for scoped constants

n_cps="$(edit_config cat | grep -oP '^id.+=.*\K\d+' | sort -n| tail -1)"

level=10
while true;
do
    sleep 4
    for i in $(seq 1 ${n_cps}); do
        echo "# CP $i, level $level"
        set_level $i $level
        sleep 6
    done
done
