OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [get-ip.sh] - Blame information for rev 866

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 548 jeremybenn
#!/bin/bash
2
 
3
# Copyright (C) 2010 Embecosm Limited
4
 
5
# Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
6
 
7
# A script to get the IP of the next available Linux session
8
 
9
# This program is free software; you can redistribute it and/or modify it
10
# under the terms of the GNU General Public License as published by the Free
11
# Software Foundation; either version 3 of the License, or (at your option)
12
# any later version.
13
 
14
# This program is distributed in the hope that it will be useful, but WITHOUT
15
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17
# more details.
18
 
19
# You should have received a copy of the GNU General Public License along
20
# with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 
22
# ------------------------------------------------------------------------------
23
 
24
# Usage
25
 
26
# ./get-ip.sh [--rotate] [--delete <ip_address>]
27
 
28
# Get the top IP address from a file of addresses, rotating it to the bottom
29
# of the file if --rotate is specified. Delete the given IP address if
30
# --delete is specified.
31
 
32
ipfile=`dirname ${DEJAGNU}`/ip-avail.txt
33
tmp=/tmp/get-ip-$$
34
lockfile=`dirname ${DEJAGNU}`/get-ip-lockfile
35
arg1=$1
36
arg2=$2
37
 
38
# Lock all the file manipulation.
39
(
40
    flock -e 200
41
 
42
    # Check we have an IP address available
43
    if [ ! -s ${ipfile} ]
44
    then
45
        echo "No IP addresses available" >&2
46
        exit 255
47
    fi
48
 
49
    # Get the top IP address
50
    ip=`head -1 ${ipfile}`
51
 
52
    # Optionally move it to the bottom of the IP file or delete it
53
    if [ "x--rotate" == "x${arg1}" ]
54
    then
55
        tail -n +2 ${ipfile} > ${tmp}
56
        echo ${ip} >> ${tmp}
57
        mv ${tmp} ${ipfile}
58
    fi
59
 
60
    if [ "x--delete" == "x${arg1}" ]
61
    then
62
        sed -i ${ipfile} -e "/${arg2}/d"
63
    fi
64
 
65
    # Echo the IP address unless we are deleting
66
    if [ "x--delete" != "x${arg1}" ]
67
    then
68
        echo ${ip}
69
    fi
70
 
71
) 200> ${lockfile}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.