#!/bin/sh die(){ echo "$1" >&2 exit 1 } usage(){ die "Usage: $(basename "$0") add-alias\n\ $(basename "$0") tmp-alias IFACE\n\ $(basename "$0") set-defaults CAPNAME\n\ $(basename "$0") ntpdate\n\ $(basename "$0") remove-alias IFACE" } # main test_vars(){ for v in $REQUIRED_VARS ; do V="\$$v" if [ -z "$(eval echo $V)" ] ; then die "Invalid value for variable $V" fi done return 0 } [ "$1" ] || usage OPTION="$1" shift case "$OPTION" in add-alias) REQUIRED_VARS="CAP_NET_HOST_IFACE CAP_NET_HOST_ALIAS CAP_NET_HOST_IP CAP_NET_HOST_MASK" eval "$(llxcfg-showvars "$REQUIRED_VARS")" test_vars ifconfig "${CAP_NET_HOST_IFACE}:${CAP_NET_HOST_ALIAS}" $CAP_NET_HOST_IP netmask $CAP_NET_HOST_MASK ;; remove-alias) CAP_NET_HOST_IFACE="$1" [ "$CAP_NET_HOST_IFACE" ] || usage REQUIRED_VARS="CAP_NET_ALIAS CAP_NET_ADDRESS CAP_NET_MASK" eval "$(llxcfg-showvars "$REQUIRED_VARS")" test_vars ifconfig "${CAP_NET_HOST_IFACE}:${CAP_NET_ALIAS}" down ;; tmp-alias) CAP_NET_HOST_IFACE="$1" [ "$CAP_NET_HOST_IFACE" ] || usage REQUIRED_VARS="CAP_NET_ALIAS CAP_NET_ADDRESS CAP_NET_MASK" eval "$(llxcfg-showvars "$REQUIRED_VARS")" test_vars RANDOM=$$ CAP_BYTE=$((230 + $RANDOM%21)) CAP_NET_HOST_IP="${CAP_NET_ADDRESS%.*}.${CAP_BYTE}" ifconfig "${CAP_NET_HOST_IFACE}:${CAP_NET_ALIAS}" $CAP_NET_HOST_IP netmask $CAP_NET_MASK ;; set-defaults) # set CAP_FQDN & CAP_HOST_ID from SRV_DOMAIN.CAP_NET_DOMAIN & SRV_HOST_ID # CAP_PRINCIPAL from CODIGO_CENTRO # using lliurex-cap set-default CAPNAME="$1" REQUIRED_VARS="CAP_NET_DOMAIN SRV_HOST_ID" eval "$(llxcfg-showvars "$REQUIRED_VARS")" [ "$1" ] || die "CAPNAME isn't defined" test_vars lliurex-cap set-default CAP_FQDN="node-${SRV_HOST_ID}.${CAPNAME}.${CAP_NET_DOMAIN}" CAP_HOST_ID="$SRV_HOST_ID" ;; ntpdate) REQUIRED_VARS="CAP_NET_ADDRESS CAP_NET_MASK CAP_NET_CAPNAME CAP_NTP_ENABLE" eval "$(llxcfg-showvars "$REQUIRED_VARS CAP_ZERO_CAPNAME")" [ "$CAP_NET_CAPNAME" ] || CAP_NET_CAPNAME="$CAP_ZERO_CAPNAME" test_vars export $REQUIRED_VARS rc=0 lliurex-cap exec "$CAP_NET_CAPNAME" /usr/share/llxcfg-cap/llxcfg-ntpdate || rc=$? exit $rc ;; *) usage ;; esac exit 0