summaryrefslogtreecommitdiffstats
path: root/netset
blob: cf28795124212354b3171b04ffcdd0587ac72701 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /bin/bash

NETCTL=$(which netctl)
if [ -z "$NETCTL" ]
then
    echo "netctl not found"
    exit 1
fi
if [ $UID -ne 0 ]
then
    echo "must be run as root"
    exit 1
fi
if [ $# -gt 0 ]
then
    profile=$1
else
    PROFILES=$($NETCTL list | sed 's/\*//' | sort)
    select profile in $PROFILES
    do
        [ -z "$profile" ] && exit 0
        break
    done
fi
if [ ! -r /etc/netctl/$profile ]
then
    echo "unknown network profile : $profile" && exit 1
fi
$NETCTL stop-all
echo "starting profile $profile" && sleep 1 && $NETCTL start $profile || exit 1
N=0
dev=$(cat /etc/netctl/$profile | sed -n 's/Interface\=\(.*\)/\1/p')
ADDR=""
while [ -z "$ADDR" ]
do
    N=$((N + 1))
    [ $N -eq 10 ] && echo " failure" && exit 1
    echo -n "." && sleep 1
    ADDR=$(ip -4 -c addr show dev $dev | sed -n '/inet/p')
done
echo
echo $ADDR