Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Other Things Gentoo
  • Search

[SOLVED] OpenRC: Passing env variables to init scripts

Still need help with Gentoo, and your question doesn't fit in the above forums? Here is your last bastion of hope.
Post Reply
Advanced search
4 posts • Page 1 of 1
Author
Message
amk
n00b
n00b
Posts: 12
Joined: Wed Apr 09, 2008 7:04 am

[SOLVED] OpenRC: Passing env variables to init scripts

  • Quote

Post by amk » Tue Jun 07, 2011 2:28 pm

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: Select all

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: Select all

Defaults env_keep += "SSID"
My preup() function in /etc/conf.d/net is like this:

Code: Select all

        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.
Top
mv
Watchman
Watchman
User avatar
Posts: 6795
Joined: Wed Apr 20, 2005 12:12 pm

  • Quote

Post by mv » Tue Jun 07, 2011 7:37 pm

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.
Top
amk
n00b
n00b
Posts: 12
Joined: Wed Apr 09, 2008 7:04 am

  • Quote

Post by amk » Tue Jun 07, 2011 11:46 pm

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.
Top
mv
Watchman
Watchman
User avatar
Posts: 6795
Joined: Wed Apr 20, 2005 12:12 pm

  • Quote

Post by mv » Thu Jun 09, 2011 8:32 pm

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: Select all

if test -f /var/lib/wlan_data
then . /var/lib/wlan_data
else : set default config
...
fi
Top
Post Reply

4 posts • Page 1 of 1

Return to “Other Things Gentoo”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy