You are not logged in.

#1 2013-02-01 05:07:09

xworld
Member
Registered: 2012-05-27
Posts: 153

[SOLVED]Custom wifi connect script requires password.

Hi guys. I made a switch recently from NetworkManager to connecting manually at startup which went fine. I wrote a shell script to automate the process so I would'nt have to enter all of the commands at startup. Here's my script:

#! /bin/bash

# Bring up the WiFi interface
sudo ip link set wlan0 up

# Tell wpa_supplicant to use WEXT and associate with SSID
sudo wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant.conf
sleep 5

# Get an IP
sudo dhcpcd wlan0

# Verify
ip addr show wlan0
sleep 2

Originally what I had done what add this script to ~/.config/openbox/autostart and had a terminal open and run the commands. This worked fine except that I can't get it to run these commands without putting sudo in front of them in the script. I know there's a better way I'm just not sure what it is. The result of this is that the terminal opens up and asks me for my password instead of just running the script which I also don't like. So what I decided to do instead was write a .service file to make this happen for me.

[Unit]
Description=Network Connectivity
Wants=network.target

[Service]
Type=oneshot
ExecStart=/home/user/code/sh/connect.sh

[Install]
WantedBy=multi-user.target

I seemed to of not created it exactly right because while it worked, it still ran a shell once X started. I was hoping it would take execute the script before the system fully started like other systemd services. So obviously I left something out of the .service file that I needed to put in. Plus I imagine that even if I did get it to finish before X started it wouldn't work because the script requires my password. So I have to find a way to get it to execute those commands without needing my password.

Thanks for reading.

EDIT:

I also tried this instead to possibly avoid having to enter sudo:

[Unit]
Description=Network Connectivity
Wants=network.target

[Service]
Type=oneshot
ExecStart=/sbin/ip link set wlan0 up
ExecStart=/usr/sbin/wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant.conf
ExecStart=/sbin/dhcpcd wlan0


[Install]
WantedBy=multi-user.target

To no avail.

Last edited by xworld (2013-02-12 06:00:29)

Offline

#2 2013-02-01 06:00:56

the sad clown
Member
From: 192.168.0.X
Registered: 2011-03-20
Posts: 833

Re: [SOLVED]Custom wifi connect script requires password.

I don't want to tell you how to run your box, but it seems like a lot of what you are trying to do is covered by netcfg, so I was wondering why you don't want to use that?


I laugh, yet the joke is on me

Offline

#3 2013-02-01 06:04:12

xworld
Member
Registered: 2012-05-27
Posts: 153

Re: [SOLVED]Custom wifi connect script requires password.

Mostly for the learning experience. If I want this to be automated I already have Network Manager.

Offline

Board footer

Powered by FluxBB