1#!/bin/sh
2
3CONFIG="/bin/config"
4IFCONFIG="/sbin/ifconfig"
5DEFAULT_NETMASK="255.255.0.0"
6FIREWALL="/www/cgi-bin/firewall.sh"
7RESOLV_CONF="/tmp/resolv.conf"
8
9# only for use as a "zcip" callback script
10if [ "x$interface" = "x" ]; then
11	exit 1
12fi
13
14case "$1" in
15init)
16	exit 0
17	;;
18config)
19	if [ "x$ip" = "x" ]; then
20		exit 1
21	fi
22
23	local ori_ip=$($IFCONFIG $interface | grep 'inet addr' | cut -f2 -d':' | cut -f1 -d' ')
24	if [ "${ip%% *}" = "$ori_ip" ]; then
25		exit 0
26	fi
27
28	$IFCONFIG $interface $ip netmask $DEFAULT_NETMASK
29	$CONFIG set ap_dhcp_ipaddr=$ip
30	$CONFIG set ap_dhcp_netmask=$DEFAULT_NETMASK
31	$CONFIG set ap_dhcp_gateway="0.0.0.0"
32	$CONFIG set ap_dhcp_server="0.0.0.0"
33	$CONFIG set dhcpc_lease_obtain=0
34	$CONFIG set dhcpc_lease_time=0
35	/bin/echo -n > $RESOLV_CONF
36	
37	# Restart DLNA
38	/sbin/cmddlna ip_restart
39
40	# Restart samba
41	/usr/bin/killall smbd
42	/usr/sbin/update_smb
43	$FIREWALL restart
44	;;
45deconfig)
46	if [ "x$ip" = "x" ]; then
47		exit 1
48	fi
49
50	# exec ip address del dev $interface local $ip
51	echo "zcip deconfig: delete $ip to $interface..." >/dev/console
52	;;
53esac
54exit 0
55