# fss-0005 fss-000d iki-0000
#
# Example controlfile based on the example files:
#   - miscellaneous/entries/serial.entry.
#   - miscellaneous/exits/serial.exit.
#   - miscellaneous/rules/serial/s_1.rule
#   - miscellaneous/rules/serial/s_2.rule
#   - miscellaneous/rules/serial/s_3.rule
#   - miscellaneous/rules/serial/s_4.rule
#   - miscellaneous/rules/serial/s_5.rule
#   - miscellaneous/rules/serial/s_6.rule
#

entry/main:
  consider serial s_1
  consider serial s_2
  consider serial s_3
  consider serial s_4
  consider serial s_5

  start serial s_6

  ready

exit/main:
  consider serial s_1
  consider serial s_2
  consider serial s_3
  consider serial s_4
  consider serial s_5
  consider serial s_6

  stop serial s_1

  ready

rule/serial/s_1/settings:
  name "Serial 1"
  on stop need serial s_2

rule/serial/s_1/script:
  start {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 1: sleeping $(date -u)"
      sleep 1
      echo "Serial 1: slept    $(date -u)"
    \}

    main ${*}
  }

  stop {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 1: stopping, sleeping $(date -u)"
      sleep 1
      echo "Serial 1: stopping, slept    $(date -u)"
    \}

    main ${*}
  }

rule/serial/s_2/settings:
  name "Serial 2"
  on start need serial s_1
  on stop need serial s_3

rule/serial/s_2/script:
  start {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 2: sleeping $(date -u)"
      sleep 1
      echo "Serial 2: slept    $(date -u)"
    \}

    main ${*}
  }

  stop {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 2: stopping, sleeping $(date -u)"
      sleep 1
      echo "Serial 2: stopping, slept    $(date -u)"
    \}

    main ${*}
  }

rule/serial/s_3/settings:
  name "Serial 3"
  on start need serial s_2
  on stop need serial s_4

rule/serial/s_3/script:
  start {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 3: sleeping $(date -u)"
      sleep 1
      echo "Serial 3: slept    $(date -u)"
    \}

    main ${*}
  }

  stop {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 3: stopping, sleeping $(date -u)"
      sleep 1
      echo "Serial 3: stopping, slept    $(date -u)"
    \}

    main ${*}
  }

rule/serial/s_4/settings:
  name "Serial 4"
  on start need serial s_3
  on stop need serial s_5

rule/serial/s_4/script:
  start {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 4: sleeping $(date -u)"
      sleep 1
      echo "Serial 4: slept    $(date -u)"
    \}

    main ${*}
  }

  stop {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 4: stopping, sleeping $(date -u)"
      sleep 1
      echo "Serial 4: stopping, slept    $(date -u)"
    \}

    main ${*}
  }

rule/serial/s_5/settings:
  name "Serial 5"
  on start need serial s_4
  on stop need serial s_6

rule/serial/s_5/script:
  start {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 5: sleeping $(date -u)"
      sleep 1
      echo "Serial 5: slept    $(date -u)"
    \}

    main ${*}
  }

  stop {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 5: stopping, sleeping $(date -u)"
      sleep 1
      echo "Serial 5: stopping, slept    $(date -u)"
    \}

    main ${*}
  }

rule/serial/s_6/settings:
  name "Serial 6"
  on start need serial s_5

rule/serial/s_6/script:
  start {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 6: sleeping $(date -u)"
      sleep 1
      echo "Serial 6: slept    $(date -u)"
    \}

    main ${*}
  }

  stop {
    main() {
      local IFS=$' \t\n' # Prevent IFS exploits by overriding with a local scope.

      echo "Serial 6: stopping, sleeping $(date -u)"
      sleep 1
      echo "Serial 6: stopping, slept    $(date -u)"
    \}

    main ${*}
  }
