about summary refs log tree commit diff stats
path: root/core/conf/rc.d/wlan
blob: c9c60ec311e06eb8db8b0d19b65df6a877f11d8a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
#
# /etc/rc.d/wlan: start/stop wireless interface
#

# Connection type: "DHCP" or "static"
#TYPE="DHCP"
TYPE="static"

DEV=wlp7s0

SSD=/sbin/start-stop-daemon
PROG_DHCP=/sbin/dhcpcd
PROG_WIFI=/usr/sbin/wpa_supplicant
PID_DHCP=/var/run/dhcpcd.pid
PID_WIFI=/var/run/wpa_supplicant.pid

OPTS_DHCP="--waitip -h $(/bin/hostname) -z $DEV"
OPTS_WIFI="-B -P $PID_WIFI -D nl80211,wext -c /etc/wpa_supplicant.conf -i $DEV"

ADDR=192.168.1.67
MASK=24
GW=192.168.1.254


print_status() {
	$SSD --status --pidfile $2
	case $? in
	0) echo "$1 is running with pid $(cat $2)" ;;
	1) echo "$1 is not running but the pid file $2 exists" ;;
	3) echo "$1 is not running" ;;
	4) echo "Unable to determine the program status" ;;
	esac
}

case $1 in
	start)

		if [ "${TYPE}" = "DHCP" ]; then
			$SSD --start --pidfile $PID_WIFI --exec $PROG_WIFI -- $OPTS_WIFI && \
			$SSD --start --pidfile $PID_DHCP --exec $PROG_DHCP -- $OPTS_DHCP
			RETVAL=$?
		else

			/sbin/ip link set ${DEV} up

			$SSD --start --pidfile $PID_WIFI --exec $PROG_WIFI -- $OPTS_WIFI 

			RETVAL=$?

			/sbin/ip addr add ${ADDR}/${MASK} dev ${DEV} broadcast +
			/sbin/ip route add default via ${GW}
		fi
		;;
	stop)

		if [ "${TYPE}" = "DHCP" ]; then
			( $SSD --stop --retry 10 --pidfile $PID_DHCP 
			  $SSD --stop --retry 10 --pidfile $PID_WIFI )
			RETVAL=$?
		else
			$SSD --stop --retry 10 --pidfile $PID_WIFI 
			RETVAL=$?

			/sbin/ip link set ${DEV} down
			/sbin/ip route del default
			/sbin/ip addr del ${ADDR}/${MASK} dev ${DEV}
		fi
		;;
	restart)
		$0 stop
		$0 start
		;;
	status)
		print_status $PROG_WIFI $PID_WIFI
		print_status $PROG_DHCP $PID_DHCP
		;;
	*)
		echo "Usage: $0 [start|stop|restart|status]"
		;;
esac

exit $RETVAL

# End of file