LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices

Reply
 
Search this Thread
Old 09-18-2011, 04:59 PM   #1
blumbri
LQ Newbie
 
Registered: Aug 2011
Location: California
Distribution: lfs-svn / slackware
Posts: 2

Rep: Reputation: 1
Quick and Easy wpa_supplicant / dhcpcd Script


Hey folks,

I'm relatively new to LFS but have had to rebuild it three times due to experimenting and fine-tuning. One of the first things I do after building the base is to get my wireless internet working. As neither LFS nor BLFS have a built-in bootscript for connecting my wlan0 interface with both 'dhcpcd' and 'wpa_supplicant', I thought I'd write my own. I've seen a couple other scripts posted on the BLFS wiki and in the hints, but they didn't seem simple enough. Anyways, this is my third time writing this script as I always forget to back it up prior to a reformat.

I am posting this to keep it off my computer so I can always get it again. If it helps anyone else out...all the better.

*** Ensure you have 'dhcpcd' and 'wpa_supplicant' installed and configured prior to continuing ***

First here is my 'ifconfig.wlan0' config file. I am using (at the time of writing) the development version SVN-20110918 so I have this file in the '/etc/sysconfig' directory. If you're running the stable version 6.8, place it in the '/etc/sysconfig/network-devices' directory instead:
Code:
# Begin /etc/sysconfig/ifconfig.wlan0

ONBOOT=yes
SERVICE=wpa-dhcpcd
IFACE=wlan0
DRIVER=wext
WPA_CONF="/etc/wpa_supplicant.conf"
DHCP_START=""
DHCP_STOP="-k"

# Set PRINTIP="yes" to have the script print
# the DHCP assigned IP address
PRINTIP="yes"

# Set PRINTALL="yes" to print the DHCP assigned values for
# IP, SM, DG, and 1st NS. This requires PRINTIP="yes".
PRINTALL="yes"

# End /etc/sysconfig/ifconfig.wlan0

And last, 'wpa-dhcpcd' goes in the '/lib/services' directory (if running on the development branch). If you're using 6.8, instead place this file in the '/etc/sysconfig/network-devices/services' directory:
Code:
#!/bin/sh
# Begin /lib/services/wpa-dhcpcd

# Based upon lfs-bootscripts-1.12 $network_devices/if{down,up}
# Rewritten by Nathan Coulson <nathan NOatSPAM linuxfromscratch NOdotSPAM org>
# Adapted for dhcpcd by DJ Lucas <dj NOatSPAM lucasit NOdotSPAM com>
# Adapted for wpa_supplicant by Brian Blumberg <blumbri NOatSPAM gmail NOdotSPAM com>

#$LastChangedBy: blumbri $
#$Date: 2011-09-18 11:16:21 +0000 (Sun, 18 Sep 2011) $

. /etc/sysconfig/rc
. $rc_functions
. $IFCONFIG

PIDFILE="/var/run/dhcpcd-$1.pid"
LEASEINFO="/var/lib/dhcpcd/dhcpcd-$1.info"
WPACTRL="/var/run/wpa_supplicant/$1"

case "$2" in
	up)
                boot_mesg -n "Starting wpa_supplicant on the $1 interface..."
                if [ -r "$WPACTRL" ]
                then
                        boot_mesg "wpa_supplicant already running!" ${WARNING}
                        echo_warning
                        exit 2
                fi
                /sbin/wpa_supplicant -i $IFACE -B -D $DRIVER -c "$WPA_CONF"
                # Save the return value
                RET="$?"
                echo ""
                $(exit "$RET")
                evaluate_retval

		boot_mesg -n "Starting dhcpcd on the $1 interface..."
		# Test to see if there is a stale pid file
		if [ -f "$PIDFILE" ]
		then
			ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null
			if [ $? != 0 ]
			then
				rm -f $PIDFILE > /dev/null
			else
				boot_mesg "dhcpcd already running!" ${WARNING}
				echo_warning
				exit 2
			fi
		fi
		/sbin/dhcpcd $1 $DHCP_START
		# Save the return value
		RET="$?"
		# Print the assigned settings if requested
		if [ "$RET" = "0" -a "$PRINTIP" = "yes" ]; then
			. $LEASEINFO
			if [ "$PRINTALL" = "yes" ]; then
				echo ""
				echo_ok
				boot_mesg "           DHCP Assigned Settings for $1:"
				boot_mesg_flush
				boot_mesg "           IP Address:      $IPADDR"
				boot_mesg_flush
				boot_mesg "           Subnet Mask:     $NETMASK"
				boot_mesg_flush
				boot_mesg "           Default Gateway: $GATEWAYS"
				boot_mesg_flush
				boot_mesg "           DNS Server:      $DNSSERVERS"
				boot_mesg_flush
			else
				boot_mesg " IP Addresss: $IPADDR"
				echo_ok
			fi
		else
			echo ""
			$(exit "$RET")
			evaluate_retval
		fi
	;;

	down)
		boot_mesg -n "Stopping dhcpcd on the $1 interface..."
		if [ -z "$DHCP_STOP" ]
		then
			echo ""
			killproc -p "$PIDFILE" /sbin/dhcpcd
		else
			/sbin/dhcpcd $1 $DHCP_STOP &> /dev/null
			RET="$?"
			if [ "$RET" -eq 0 ]; then
				echo ""
				echo_ok
			elif [ "$RET" -eq 1 ]; then
				boot_mesg "dhcpcd not running!" ${WARNING}
				echo_warning
			else
				echo ""
				echo_failure
			fi
		fi

                boot_mesg -n "Stopping wpa_supplicant on the $1 interface..."
                WPAPID=$(echo $(ps x | grep /sbin/wpa_supplicant | grep $IFACE) | cut -d' ' -f1)
                if [ "x$WPAPID" != "x" ]
                then
                        kill $WPAPID &> /dev/null
                        RET="$?"
                        if [ "$RET" -eq 0 ]; then
                                echo ""
                                echo_ok
                        else
                                echo ""
                                echo_failure
                        fi
                else
                        boot_mesg "wpa_supplicant not running!" ${WARNING}
                        echo_warning
                fi
	;;

	*)
		echo "Usage: $0 [interface] {up|down}"
		exit 1
	;;
esac

# End /lib/services/wpa-dhcpcd
After doing this, upon boot (or running '/etc/rc.d/init.d/network start') your interface should be brought up, wpa_supplicant started, and dhcpcd loaded. Hopefully this helps someone!

Please let me know if you have any questions/comments.

-- blumbri

Last edited by blumbri; 09-19-2011 at 12:27 PM. Reason: Changed directory from /lib/boot to /lib/services as per LFS SVN-20110918 Changelog
 
Old 10-19-2011, 12:37 PM   #2
poly_s
Member
 
Registered: Sep 2011
Distribution: Arch
Posts: 46

Rep: Reputation: Disabled
Brilliant!!

ZRD
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dhcpcd not getting ip adderss w/ wpa_supplicant jim_fields Linux - Wireless Networking 1 07-07-2008 10:23 PM
How do I configure wpa_supplicant to try all hidden SSIDs in quick succession? warmana Slackware 5 11-17-2006 08:41 AM
"wpa_supplicant and dhcpcd" known problems? the_mich Linux - Networking 0 03-13-2006 09:38 AM
2 quick easy questions.... kevingpo Fedora 1 07-24-2005 08:54 AM
2 quick and easy questions Nicksan Linux - General 3 06-30-2003 11:41 PM


All times are GMT -5. The time now is 08:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration