Re: Configuring wireless adapters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Philip Prindeville wrote:
> Jim Wildman wrote:
> 
>> On Tue, 30 May 2006, Philip Prindeville wrote:
>>
>>  
>>
>>> solution is.  I'd like to be able to get the file as:
>>>
>>> /etc/sysconfig/network-scripts/ifcfg-iwlan0
>>>
>>> (or whatever) written out in a semi-automatic way, but I
>>> can't figure out how to do that.
>>>
>>>    
>>>
>> cat > /etc/sysconfig/network-scripts/ifcfg-iwlan0 <<ENDOFIWLAN0
>> neat config stuff
>> ENDOFIWLAN0
>>
>> comes to mind.
>>
>> gogole for 'bash "here document"'
>>  
>>
> 
> Um.... Look at Network.write() in /usr/lib/anaconda/network.py
> 
> I was thinking it would be nice to be able to do this in the same fashion
> without having to replicate code... Goes back to my earlier comment
> about being able to generate configs for interfaces that might be absent
> at install time (such as hot-swap PCMCIA cards, etc).


Philip, I'd agree with you that code reuse is great. network.py is
designed to generate these files from a wide assortment of systems.  If
you have a limited range of systems to support or they all have the same
hardware configuration, then a bash here doc makes a good solution too!
 The end result of network.py for
/etc/sysconfig/network-scripts/ifcfg-eth0 as an example is
# My card vendor
DEVICE=eth0
BOOTPROTO=static
HWADDR=variable mac address
IPADDR=ip address
NETMASK=your network mask
ONBOOT=yes


Just cause this looked fun to do, I give you mketh0.sh as
an example of what Jim is taking about. This kind-of code
in anaconda scripts rocks.
#!/bin/bash
# Ident: mketh0.sh
#
# Bash here doc for redhat_eth0.
# She's copyright 2006 and free under
# the GPL v2 and you get to keep
# both pieces if it is broken.
# Greg Morgan
# NOTE: Using short lines
# for sending via email.
#
# Steps:
# save code as mketh0.sh
# chmod u+x mketh0.sh
# ./mketh0.sh
#
# Uncomment out for production.
# redhat_netdb_path='/etc/sysconfig/network-scripts/'
# Use this path for practice to see how it works.
# Ya'll be careful hear!
#
# Define working variables.  Please change these.
#
redhat_netdb_path="${HOME}"
redhat_netdb_file='ifcfg-eth0'
# Don't forget the leading
# hash, #, in your string.
my_card_vendor='# MY Vendor'
my_device='eth0'
my_bootproto='static'
# I leave the thrill and joy of discovering
# how to dig the mac address out of the
# system dynamically to you.
# Notice the back tics!
# my_hwaddr=`some mystry command`
# My shoe size? ;-)
my_hwaddr=`echo '13:13:13:13:13:13'`
my_ipaddr=192.13.13.13
my_netmask=255.255.255.0
my_onboot=yes
#
# End of user change section.

# So now that the variables are set,
# let's create the config file.
# Make sure the file is gone first.
# We expect this error and it is ok if seen.
# rm: cannot remove `/home/drkludge/ifcfg-eth0': No such file or directory
#
rm ${redhat_netdb_path}/${redhat_netdb_file}

# Generate the file so that the data looks
# like this excluding leading hash for all
# lines except the first one.
#   My card vendor
#   DEVICE=eth0
#   BOOTPROTO=static
#   HWADDR=variable mac address
#   IPADDR=ip address
#   NETMASK=your network mask
#   ONBOOT=yes
# Improvements on code sent
# by Jim Wildman 20060530.
# Watch the word wrap in email on this line.
cat - > ${redhat_netdb_path}/${redhat_netdb_file} << ETH0EOF
${my_card_vendor}
DEVICE=${my_device}
BOOTPROTO=${my_bootproto}
HWADDR=${my_hwaddr}
IPADDR=${my_ipaddr}
NETMASK=${my_netmask}
ONBOOT=${my_onboot}
ETH0EOF
# Note do not indent the the code ETH0EOF
# to make the code look pretty.  The uppercase
# code that you pick must start at the
# beginning of the line!
#
# end of mketh0.sh


The output of this script looks like this
more ifcfg-eth0
# MY Vendor
DEVICE=eth0
BOOTPROTO=static
HWADDR=13:13:13:13:13:13
IPADDR=192.13.13.13
NETMASK=255.255.255.0
ONBOOT=yes


Works fine by me.

HTH,
Greg




-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFEfoz1xyxe5L6mr7IRAl+MAJ9/FJ/6wetn3bfIpBDJKwVR6USIwQCfSXOn
sx8g996OkVJ4mmgO/yzszHw=
=M4OU
-----END PGP SIGNATURE-----


[Index of Archives]     [Red Hat General]     [CentOS Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux