Author Topic: Where to put WiFi scripts for automatic execution at startup  (Read 10363 times)

joakim

  • Zen Apprentice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Where to put WiFi scripts for automatic execution at startup
« on: February 06, 2012, 09:00:42 am »
I have made a installation for a client of mine and they only offer WiFi connections where he rents his office. I have setup a gateway server that uses a WiFi card as the external interface. My problem is that I have to bring up the WiFi connection manually and Id like to have it automatic in the start up script.
I cant put it in the /etc/network/interfaces since that file gets overwritten at every reboot, so where do I put it to make the connection automatic at every reboot. Its basic WiFi connection strings
"wpa_supplicant -D wext -i wlan0 -c wpa.conf"
and
"dhclient wlan0"

best regards,
Joakim

joakim

  • Zen Apprentice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Where to put WiFi scripts for automatic execution at startup
« Reply #1 on: February 09, 2012, 08:12:39 am »
I got this tips from irc:
<ichat> joakim_ -  look at the zentyal  /usr/share/zentyal/network  section
<ichat> because there you can make that your  edits to /etc/network/interfaces get added to the file when it gets overwritten by zentyal

I couldnt find the /usr/share/zentyal/network but I found /usr/share/ebox-network/ebox-setup-wireless and that seemes to be a perl script for wifi but Im not sure how to use it, it doesnt execute (or do I need a GUI for that ? ) ?
Im running Zentyal 2.2.1 64-bit by the way.

jjmontes

  • Zentyal Staff
  • Zen Monk
  • *****
  • Posts: 86
  • Karma: +8/-0
    • View Profile
Re: Where to put WiFi scripts for automatic execution at startup
« Reply #2 on: February 13, 2012, 11:04:28 am »
A few points:

1) While Zentyal normally supports overriding configuration templates, by writing them to /etc/zentyal/stubs, the 'interfaces' file is an exception as it is generated by Zentyal core without using a template. Thus, this approach won't be valid for this.

2) On Zentyal 2.2, the wireless setup file is placed in /usr/share/zentyal-network/setup-wireless. If you see filenames containing 'ebox', then you are probably using an older version than 2.2? If you installed Zentyal packages from Ubuntu repositories, then I strongly suggest you to use a Zentyal CD or Zentyal APT repository (PPA) instead.

3) You basically need to add a configuration-hook, so the script is executed after every time that Zentyal writes the interfaces file. Information about using the setup-wireless script can be found at http://trac.zentyal.org/wiki/Documentation/Community/HowTo/SetupWireless (a bit outdated, but still valid).

Regards!


HeliTech

  • Zen Apprentice
  • *
  • Posts: 4
  • Karma: +1/-0
    • View Profile
Re: Where to put WiFi scripts for automatic execution at startup
« Reply #4 on: May 20, 2012, 05:18:38 am »
I got this straightened out in V 2.3

Here is /etc/zentyal/hooks/network.postsetconf
Code: [Select]
#!/bin/sh

# postsetconf scripts are run after the configuration for a given module is
# written. The module will check if an executable file called
# <module>.presetconf exists in /etc/zentyal/hooks and will try to run it



# set WLAN_IFACE to the name of your interface
export WLAN_IFACE=wlan0

# set WLAN_IFACE to the ESSID of your network
export WLAN_ESSID=essid.here

# set WLAN_CONF to contain any extra configuration needed in /etc/network/interfaces for your
# interface, for example, uncomment this line if you want to set up
# export WLAN_CONF="wireless-mode master"

# execute the helper script
/usr/share/zentyal-network/setup-wireless

# if you need to setup several wireless cards just set the variables and run the script again

# we need to tell ebox we have updated the interfaces file so we are not asked in the interface
# every time we save
/usr/share/zentyal/update-file-digest network /etc/network/interfaces

exit 0

And here is the altered helper script /usr/share/zentyal-network/setup-wireless

Code: [Select]
#!/usr/bin/perl

my $iface = $ENV{'WLAN_IFACE'};

defined($iface) or exit 0;

my $essid = $ENV{'WLAN_ESSID'};

defined($essid) or exit 0;

my $extra_conf = $ENV{'WLAN_CONF'};

my $conf = "    wireless-essid $essid\n";

if(defined($extra_conf)) {
    $conf .= ($extra_conf . "\n");
}

my $ifile = '/etc/network/interfaces';
my $newifile = '/etc/network/interfaces.new';

open(IFACES, $ifile);
open(NEW_IFACES, '>', $newifile);

my $print = 1;
for my $line (<IFACES>) {
    print NEW_IFACES $line;
    if ($line =~ m/^iface $iface/) {
        print NEW_IFACES $conf;
    }
}

close(NEW_IFACES);
close(IFACES);

rename($newifile, $ifile);

Notice the updates to the new file locations and the name changes in the essid conf. (from just  "essid" to "wireless-essid")

The Storm

  • Zen Apprentice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Where to put WiFi scripts for automatic execution at startup
« Reply #5 on: May 20, 2012, 08:30:39 pm »
Hi!

I'm also trying to get my wlan0 up (as external interface) knowing is can't be done by simply putting my conf settings (WPA2 credentials in particular) into /etc/network/interfaces.

My rig is a 2.2 up to date, for now running as a VM on virtual box on a real 12.04 LTS ubuntu minimal server, which provides (among others things) bridged eth0 & eth1 so that the virtualized zentyal server doesn't have to deal with the related issue. Obviously, it'd be way better for me to get everything done on a unique real zentyal box, since virtualization takes lots of bogomips...

Unfortunately, I must says I can't really figure out what to put into /etc/zentyal/hooks/network.postsetconf : I especially don't know how to get my wpa-supplicant.conf loaded & something like ifup wlan0 done on this basis. I also don't understand what the purpose of /usr/share/zentyal-network/setup-wireless and it's combination with the first named file.

Would someone be kind enough to provide us with a clear & documented (mini)how-to or, at least, links or tracks ? Thx by advance.