#!/bin/bash
#    51-wsl-motd-news - print the live news from the Ubuntu WSL.
#    Copyright (C) 2020 Canonical Ltd.
#
#    Authors: Patrick Wu <patrick.wu@canonical.com>

set -eu

# Exit if not WSL
 [ -f /proc/sys/fs/binfmt_misc/WSLInterop ] || exit 0

# Source the local configuration
CUR_CONF_LOC=/etc/default/ubuntu-wsl/ubuntu-wsl.conf
[ -f "/etc/ubuntu-wsl.conf" ] && CUR_CONF_LOC=/etc/ubuntu-wsl.conf

__ubuntu_wsl_conf_handling() {
    section=""
    while IFS='=' read var val
    do
        if [[ $var =~ ^\;.*$ ]] || [[ $var =~ ^\#.*$ ]]
        then
            continue
        elif [[ $var =~ ^\[.*\]$ ]]
        then
            section="$(echo $var | tr -d '\[\]' | tr '[:lower:]' '[:upper:]')"
        elif [[ -n "$val" ]]
        then
            var="$(echo $var | tr -d '[:space:]' | tr '[:lower:]' '[:upper:]')"
            val="$(echo $val | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')"
            declare -r -g UBUNTU_WSL_${section}_${var}=${val}
        fi
    done < $CUR_CONF_LOC
}

[ -f "$CUR_CONF_LOC" ] && __ubuntu_wsl_conf_handling

# Exit immediately unless we're enabled
[ "$UBUNTU_WSL_MOTD_WSLNEWSENABLED" = "true" ] || exit 0

cat <<EOF

* Using WSL on your company workstation? Get credit for being a forward
  thinker and stay compliant with security policies.

 https://ubuntu.com/wsl

EOF


exit 0
