#!/bin/sh

command=$1
case "$command" in
enable)
    autolinklocal=1
    ;;
disable)
    autolinklocal=0
    ;;
*)
    echo "usage: ${0##*/} [enable|disable]"
    exit 1
    ;;
esac

autolinklocal_sysctl="net.inet6.ip6.auto_linklocal"
if [ $(sysctl -n "$autolinklocal_sysctl") -eq $autolinklocal ]; then
    echo "autolinklocal support already ${command}d"
    exit 0
fi

isi_sysctl_cluster "${autolinklocal_sysctl}=$autolinklocal"

# In case of disabling auto link local address, reboot is must to take if
# effect. However in case of enabling auto link local address, this could be
# acheived by restarting interface.
if [ $autolinklocal -eq 1 ]; then
    echo "Would you like to restart your interfaces? [Y/n]"
    echo "WARNING: this could disconnect your session"
    read yesno
    case "$yesno" in
    [nN])
	echo "Exiting. Please reboot your cluster via 'isi config' for the changes to take effect"
        exit 0
	;;
    esac

    isi_for_array isi_restart_local_external_autolinklocal_interfaces
    if [ $? != 0 ]; then
	echo "Failed to restart ext interfaces on 1 or more nodes!"
	echo "Please reboot your cluster via 'isi config' for the changes to take effect"
    fi
else
    echo "Please reboot your cluster via 'isi config' for the changes to take effect"
fi


