Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] OpenRC: Passing env variables to init scripts
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
amk
n00b
n00b


Joined: 09 Apr 2008
Posts: 12

PostPosted: Tue Jun 07, 2011 2:28 pm    Post subject: [SOLVED] OpenRC: Passing env variables to init scripts Reply with quote

Hi,

My recent emerge installed openrc and I found myself in a problem with setting up wireless network.
Basically I use environment variable to specify the SSID as there are more available around
and one of them requires parameters not supported by gnome-network-manager.

So far everything worked using simple alias:
Code:
alias wifionh='sudo SSID=RequiredSSID /etc/init.d/net.wlan0 start'


All I needed to do was to allow sudo passing the variable in /etc/sudoers:
Code:
Defaults env_keep += "SSID"


My preup() function in /etc/conf.d/net is like this:
Code:
        if [[ ${IFACE} = "wlan0" ]]; then
                [[ ${IN_BACKGROUND} = "true" ]] && return 0
                if [[ -z ${USER} ]] && grep -qv wifi /proc/cmdline ; then
                        ewarn "Wifi not requested in command line"
                        return 1
                fi

                WPA=/etc/wpa_supplicant
                if [[ -z ${SSID} ]]; then
                        einfo "Default - all SSIDS"
                        cat $WPA/wpa_conf.* > $WPA/wpa_supplicant.conf || return 1
                else
                        einfo "Request only $SSID"
                        cp $WPA/wpa_conf.$SSID $WPA/wpa_supplicant.conf || return 1
                fi

                einfo "Loading WiFi driver module"
                modprobe iwlagn || return 1
        fi


After upgrade to OpenRC I found that the SSID variable does not make it to the function.

Is there any rc configuration option either to make it working again, or to have the wpa_supplicant config specified using another way while invoking the init script?
I can probably fix it using a /tmp file but wondering that there might be a more elegant solution or provision I just missed checking the openRC upgrade docs.

Thanks


Last edited by amk on Tue Jun 07, 2011 10:57 pm; edited 1 time in total
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6294

PostPosted: Tue Jun 07, 2011 7:37 pm    Post subject: Reply with quote

There is rc_env_allow in /etc/rc.conf. However, sourcing some setup in /etc/conf.d/net.wlan0 might be more in the spirit of openrc.
Back to top
View user's profile Send private message
amk
n00b
n00b


Joined: 09 Apr 2008
Posts: 12

PostPosted: Tue Jun 07, 2011 11:46 pm    Post subject: Reply with quote

Thanks for the hint, it worked.

Not sure what you mean by /etc/conf.d/net.wlan0,
do not see any hint even in /usr/share/doc/openrc-0.8.2-r1/net.example

My previous HW required load/unload of kernel module from preup/postdown
and I just copied the config to new PC. If there is a better place to hook
the update of wpa_supplicant.conf, or allow user to select SSID when starting
the interface I would appreciate any pointer.
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6294

PostPosted: Thu Jun 09, 2011 8:32 pm    Post subject: Reply with quote

amk wrote:
Not sure what you mean by /etc/conf.d/net.wlan0

The name depends on the name of your /etc/init.d/... script which you use to bring up your wlan - with "oldnet" I guess that this would be /etc/init.d/net.wlan0:
The corresponding /etc/conf.d/... is usually sourced before the corresponding init.d-script is executed so that you can set variables there.

If you want to modify your configuration "automatically" you can either modify this /etc/conf.d/... file directly, or you can source from there another file which can contain such data. Something like
Code:
if test -f /var/lib/wlan_data
then . /var/lib/wlan_data
else : set default config
...
fi
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum