From d428b64adcd7aa90681669315f7ff847bb2af3ea Mon Sep 17 00:00:00 2001 From: William Harrington Date: Sat, 26 Apr 2014 20:51:13 -0500 Subject: Initial commit. --- clfs/services/bridge | 76 ++++++++++++++++++++++++++++++++ clfs/services/dhclient | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ clfs/services/dhcpcd | 69 +++++++++++++++++++++++++++++ clfs/services/wpa | 89 +++++++++++++++++++++++++++++++++++++ 4 files changed, 351 insertions(+) create mode 100644 clfs/services/bridge create mode 100644 clfs/services/dhclient create mode 100644 clfs/services/dhcpcd create mode 100644 clfs/services/wpa (limited to 'clfs/services') diff --git a/clfs/services/bridge b/clfs/services/bridge new file mode 100644 index 0000000..1750fca --- /dev/null +++ b/clfs/services/bridge @@ -0,0 +1,76 @@ +#!/bin/sh +######################################################################## +# Begin /lib/services/bridge +# +# Description : Bridge Boot Script +# +# Authors : Nathan Coulson - nathan@linuxfromscratch.org +# Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS-7.2 +# +######################################################################## + +. /lib/lsb/init-functions +. ${IFCONFIG} + +# Make compatible with older versions of init-functions +unset is_true + +is_true() +{ + [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] || + [ "$1" = "y" ] || [ "$1" = "t" ] +} + +if [ -z "${INTERFACE_COMPONENTS}" ]; then + log_failure_msg "INTERFACE_COMPONENTS variable missing from ${IFCONFIG}" + exit 1 +fi + +case "${2}" in + up) + log_info_msg2 "\n" + log_info_msg "Creating the ${1} interface..." + brctl addbr ${1} + evaluate_retval + + for I in ${INTERFACE_COMPONENTS}; do + log_info_msg "Adding ${I} to ${1}..." + brctl addif ${1} ${I} + evaluate_retval + done + + if is_true ${STP}; then + brctl stp ${1} on + log_success_msg "Setting spanning tree protocol" + fi + + if is_true ${IP_FORWARD}; then + sysctl -w net.ipv4.ip_forward=1 > /dev/null + log_success_msg "Setting net.ipv4.ip_forward = 1" + fi + ;; + + down) + for I in ${INTERFACE_COMPONENTS}; do + log_info_msg "Removing ${I} from ${1}..." + ip link set ${I} down && + brctl delif ${1} ${I} + evaluate_retval + done + + log_info_msg "Bringing down the ${1} interface..." + ip link set ${1} down + brctl delbr ${1} + evaluate_retval + ;; + + *) + echo "Usage: ${0} [interface] {up|down}" + exit 1 + ;; +esac + +# End /lib/services/bridge + diff --git a/clfs/services/dhclient b/clfs/services/dhclient new file mode 100644 index 0000000..2469901 --- /dev/null +++ b/clfs/services/dhclient @@ -0,0 +1,117 @@ +#!/bin/sh +# Begin services/dhclient + +# Origianlly based upon lfs-bootscripts-1.12 $NETWORK_DEVICES/if{down,up} +# Rewritten by Nathan Coulson +# Adapted for dhclient by DJ Lucas +# Update for LFS 7.0 by Ken Moffat + +# Call with: IFCONFIG= /lib/services/dhclient + +#$LastChangedBy: krejzi $ +#$Date: 2013-02-11 17:22:35 +0100 (Mon, 11 Feb 2013) $ + +. /lib/lsb/init-functions +. $IFCONFIG + +PIDFILE=/run/dhclient-$1.pid +LFILE=/var/lib/dhclient/dhclient-$1.leases + +getipstats() +{ + # Print the last 16 lines of dhclient.leases + sed -e :a -e '$q;N;17,$D;ba' ${LFILE} +} + +# Make compatible with older versions of init-functions +unset is_true + +is_true() +{ + [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] || + [ "$1" = "y" ] || [ "$1" = "t" ] +} + +case "$2" in + up) + + if [ -e ${PIDFILE} ]; then + ps $(cat ${PIDFILE}) | grep dhclient >/dev/null + if [ "$?" = "0" ]; then + log_warning_msg "\n dhclient appears to be running on $1" + exit 0 + else + rm ${PIDFILE} + fi + fi + + log_info_msg "\n Starting dhclient on the $1 interface..." + + /sbin/dhclient -lf ${LFILE} -pf ${PIDFILE} $DHCP_START $1 + + if [ "$?" != "0" ]; then + log_failure_msg2 + exit 1 + fi + + # Print the assigned settings if requested + if is_true "$PRINTIP" -o is_true "$PRINTALL"; then + # Get info from dhclient.leases file + + IPADDR=`getipstats | grep "fixed-address" | \ + sed 's/ fixed-address //' | \ + sed 's/\;//'` + + NETMASK=`getipstats | grep "subnet-mask" | \ + sed 's/ option subnet-mask //' | \ + sed 's/\;//'` + + GATEWAY=`getipstats | grep "routers" | \ + sed 's/ option routers //' | \ + sed 's/\;//'` + + DNS=`getipstats | grep "domain-name-servers" | \ + sed 's/ option domain-name-servers //' | \ + sed 's/\;//' | sed 's/,/ and /'` + + if [ "$PRINTALL" = "yes" ]; then + # This is messy, the messages are on one very long + # line on the screen and in the log + log_info_msg " DHCP Assigned Settings for $1:" + log_info_msg " IP Address: $IPADDR" + log_info_msg " Subnet Mask: $NETMASK" + log_info_msg " Default Gateway: $GATEWAY" + log_info_msg " DNS Server: $DNS" + else + log_info_msg " IP Addresss:""$IPADDR" + fi + fi + + log_success_msg2 + ;; + + down) + if [ ! -e ${PIDFILE} ]; then + log_warning_msg "\n dhclient doesn't appear to be running on $1" + exit 0 + fi + + log_info_msg "\n Stopping dhclient on the $1 interface..." + + /sbin/dhclient -r -lf ${LFILE} -pf ${PIDFILE} $DHCP_STOP $1 + + ps $(cat ${PIDFILE}) | grep dhclient >/dev/null + if [ "$?" != "0" ]; then + rm -f ${PIDFILE} + fi + + evaluate_retval + ;; + + *) + echo "Usage: $0 [interface] {up|down}" + exit 1 + ;; +esac + +# End services/dhclient diff --git a/clfs/services/dhcpcd b/clfs/services/dhcpcd new file mode 100644 index 0000000..0408df1 --- /dev/null +++ b/clfs/services/dhcpcd @@ -0,0 +1,69 @@ +#!/bin/bash +# Begin services/dhcpcd + +# Origianlly dased upon lfs-bootscripts-1.12 $NETWORK_DEVICES/if{down,up} +# Rewritten by Nathan Coulson +# Adapted for dhcpcd by DJ Lucas +# Update for LFS 7.0 by Bruce Dubbs + +# Call with: IFCONFIG= /lib/services/dhcpcd + +#$LastChangedBy: bdubbs $ +#$Date: 2012-04-09 21:48:51 +0200 (Mon, 09 Apr 2012) $ + +. /lib/lsb/init-functions +. $IFCONFIG + +pidfile="/var/run/dhcpcd-$1.pid" + +case "$2" in + up) + # Cosmetic output not needed for multiple services + if ! $(echo ${SERVICE} | grep -q " "); then + log_info_msg2 "\n" # Terminate the previous message + fi + + log_info_msg "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 /var/run/dhcpcd-$1.pid > /dev/null + + else + log_warning_msg "dhcpcd is already running!" + exit 2 + fi + fi + + /sbin/dhcpcd $1 $DHCP_START + evaluate_retval + ;; + + down) + log_info_msg "Stopping dhcpcd on the $1 interface..." + + if [ -z "$DHCP_STOP" ]; then + killproc -p "${pidfile}" /sbin/dhcpcd + + else + /sbin/dhcpcd $1 $DHCP_STOP &> /dev/null + + if [ "$?" -eq 1 ]; then + log_warning_msg "dhcpcd not running!" + exit 2 + fi + fi + + evaluate_retval + ;; + + *) + echo "Usage: $0 [interface] {up|down}" + exit 1 + ;; +esac + +# End services/dhcpcd diff --git a/clfs/services/wpa b/clfs/services/wpa new file mode 100644 index 0000000..a02f0e8 --- /dev/null +++ b/clfs/services/wpa @@ -0,0 +1,89 @@ +#!/bin/bash +# Begin services/wpa + +# Origianlly based upon lfs-bootscripts-1.12 $NETWORK_DEVICES/if{down,up} +# Written by Armin K. + +# Call with: IFCONFIG= /lib/services/wpa + +#$LastChangedBy: krejzi $ +#$Date: 2013-03-24 16:39:14 +0100 (Sun, 24 Mar 2013) $ + +. /lib/lsb/init-functions +. $IFCONFIG + +CFGFILE=/etc/sysconfig/wpa_supplicant-${IFCONFIG##*.}.conf +PIDFILE=/run/wpa_supplicant/$1.pid +CONTROL_IFACE=/run/wpa_supplicant/$1 + +case "$2" in + up) + + if [ -e ${PIDFILE} ]; then + ps $(cat ${PIDFILE}) | grep wpa_supplicant >/dev/null + if [ "$?" = "0" ]; then + log_warning_msg "\n wpa_supplicant already running on $1." + exit 0 + else + rm ${PIDFILE} + fi + fi + + if [ ! -e ${CFGFILE} ]; then + log_info_msg "\n wpa_supplicant configuration file ${CFGFILE} not present" + log_failure_msg2 + exit 1 + fi + + log_info_msg "\n Starting wpa_supplicant on the $1 interface..." + + mkdir -p /run/wpa_supplicant + + /sbin/wpa_supplicant -q -B -Dnl80211,wext -P${PIDFILE} -C/run/wpa_supplicant -c${CFGFILE} -i$1 ${WPA_ARGS} + + if [ "$?" != "0" ]; then + log_failure_msg2 + exit 1 + fi + + log_success_msg2 + + if [ -n "${WPA_SERVICE}" ]; then + if [ ! -e /lib/services/${WPA_SERVICE} -a ! -x /lib/services/${WPA_SERVICE} ]; then + log_info_msg "\n Cannot start ${WPA_SERVICE} on $1" + log_failure_msg2 + exit 1 + fi + + IFCONFIG=${IFCONFIG} /lib/services/${WPA_SERVICE} $1 up + fi + ;; + + down) + if [ -n "${WPA_SERVICE}" ]; then + if [ ! -e /lib/services/${WPA_SERVICE} -a ! -x /lib/services/${WPA_SERVICE} ]; then + log_warning_msg "\n Cannot stop ${WPA_SERVICE} on $1" + else + IFCONFIG=${IFCONFIG} /lib/services/${WPA_SERVICE} $1 down + fi + fi + + log_info_msg "\n Stopping wpa_supplicant on the $1 interface..." + + if [ -e ${PIDFILE} ]; then + kill -9 $(cat ${PIDFILE}) + rm -f ${PIDFILE} ${CONTROL_IFACE} + evaluate_retval + else + log_warning_msg "\n wpa_supplicant already stopped on $1" + exit 0 + fi + ;; + + *) + echo "Usage: $0 [interface] {up|down}" + exit 1 + ;; +esac + +# End services/wpa -- cgit v1.2.3-54-g00ecf