#!/usr/bin/bash

# Copyright (c) 2019 Arista Networks, Inc.  All rights reserved.
# Arista Networks, Inc. Confidential and Proprietary.

# Determine and start the wanted mode for EOS.

# The idea is that each AristaDiagnosticsMode is associated with a target. Each
# service that wants to be part of one of the modes simply need to add
# WantedBy=MODE.target. Here is a description of each target:
#   - NoEOS.target: Target that is started in NoEOS mode. That's mostly used by
#     manufacturing. They run their own things and don't want any regular EOS code to
#     tamper with the hardware.
#   - EOS.target: Target that is used by any service that needs to be started for EOS
#     regular mode.
#   - multi-user.target: Target that is used by any service that needs to be started
#     in both EOS mode and NoEOS mode.

# Only consider NoEOS.target if it exists (i.e., not a release image).
systemctl status NoEOS.target > /dev/null 2>&1
if [ $? != 4 ] && grep -qs "AristaDiagnosticsMode=NoEOS" /proc/cmdline; then
   # unmask sshd before starting the target that it's "WantedBy"
   systemctl unmask sshd
   systemctl start NoEOS.target
else
   systemctl start EOS.target
fi
