##
## Copyright 2013 Cumulus Networks Inc.
## All rights reserved
##
## Useful functions and variables for boot time.
##
## This assumes the shell is ash/dash.
##

export INIT_CONF=$(pwd)/cumulus/init

bail_out() {
    exit 1
}

. $script_dir/common/logging_functions
. $script_dir/common/utility

require_superuser()
{
    [ "$(id -u)" = "0" ] || {
        log_failure_msg "You need superuser privileges for this operation."
        exit 1
    }
}

# no-op operation pre/post handlers.  These are intended to be
# overridden by user supplied scripts.
image_provision_pre()
{
    return 0
}

image_provision_post()
{
    return 0
}

image_install_pre()
{
    return 0
}

image_install_post()
{
    return 0
}

image_env_pre()
{
    return 0
}

image_env_post()
{
    return 0
}

image_extract_pre()
{
    return 0
}

image_extract_post()
{
    return 0
}

image_verify_pre()
{
    return 0
}

image_verify_post()
{
    return 0
}

image_info_pre()
{
    return 0
}

image_info_post()
{
    [ -d /etc/cumulus ] || return 0

    img_os_rel=$(grep OS-Release: control 2>/dev/null | awk '{print $2}')
    img_os_relmajor=$(echo $img_os_rel | cut -d "." -f1)
    running_os_relmajor=$(cat /etc/os-release 2>/dev/null | \
                            grep ^VERSION_ID= | \
                            cut -d "=" -f 2  | \
                            cut -d "." -f1,2 2>/dev/null)

    if [ x"$running_os_relmajor" = x"1.5" -a x"$img_os_relmajor" = x"2" ]; then
        echo -e "\n\n\033[38;5;196mAfter this upgrade root user will stop working!!!.\nPlease use cumulus account with sudo.\033[m\n"
    fi

    return 0
}

image_update_pre()
{
    return 0
}

image_update_post()
{
    return 0
}

# Local Variables:
# mode: shell-script
# eval: (sh-set-shell "/bin/sh" t nil)
# End:
