This file is indexed.

/lib/uruk/init/autodetect-ips is in uruk 20150921-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/sh

# this file maintained at http://git.mdcc.cx/uruk.git

# /lib/uruk/init/autodetect-ips - set variables ip{,6}_<interface>_default and
#   net{,6}_<interface>_default.  see uruk-rc(5) and the sample uruk rc file
#   as shipped with uruk in doc/rc.

# Copyright © 2012 Wessel Dankers
# Copyright © 2013 Casper Gielen
# Copyright © 2013 Joost van Baal-Ilić

# This file is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.
#
# You should have received a copy of the GNU GPL along with this file, see
# e.g. the file named COPYING.  If not, see <http://www.gnu.org/licenses/>.

# Usage: make sure your /etc/uruk/rc has leading line
# ". /lib/uruk/init/autodetect-ips", e.g. by running
#
#  sed -i '1i. /lib/uruk/init/autodetect-ips' /etc/uruk/rc
#

###############################################
# assign IPs and networks to network interfaces
###############################################

# FIXME
# set $interfaces dynamically too?

# For each interface <if> in interfaces, ip_<if> should be defined.

# First try Red Hat's init scripts

# This works fine with dash.  (As long as you don't have a file called
# 'ifcfg-*'.)  Other non-strict shells (zsh, e.g.) might print an error "no
# matches found: /etc/sysconfig/network-scripts/ifcfg-*"
for f in /etc/sysconfig/network-scripts/ifcfg-*
do
    test -e $f || continue
    iface=${f#/etc/sysconfig/network-scripts/ifcfg-}
    case $iface in *[!a-zA-Z0-9_]*|[!a-zA-Z_]*)
        continue
    esac
    eval "$(
        . $f
        echo ip_${iface}_default=$IPADDR
        echo net_${iface}_default=$IPADDR/$NETMASK
        echo ip6_${iface}_default=${IPV6ADDR%/*}
        echo net6_${iface}_default=$IPV6ADDR
    )"
done

# Second, Debian's init scripts
if test -f /etc/network/interfaces
then
    # bash 3.2 FIXME :  change `  ` back to $(  ) (twice), and change
    # eval ip="\"\\$ip_${iface}_default\"" back to
    # eval ip="\"\$ip_${iface}_default\"" : we are working around a bug in
    # bash 3.2, since june 2015.  Revert this stuff after dec 2015,
    eval "`
        while read -r key val val1 rest
        do
            case $key in iface)
                case $val in *[!a-zA-Z0-9_]*|[!a-zA-Z_]*)
                        iface=
                        type=
                ;; *)
                        iface=$val
                        type=$val1
                esac
                address=
                netmask=
                case $type in inet6)
                    netmask=64
                esac
            ;; address)
                    address=$val
                    case $address in */*)
                        netmask=${address##*/}
                        address=${address%/*}
                    esac
            ;; netmask)
                    netmask=$val
            esac
            case $iface,$address,$netmask in ?*,?*,?*)
                case $type in inet)
                    echo ip_${iface}_default=$address
                    echo net_${iface}_default=$address/$netmask
                ;; inet6)
                    echo ip6_${iface}_default=$address
                    echo net6_${iface}_default=$address/$netmask
                esac
                iface=
                type=
                address=
                netmask=
            esac
        done </etc/network/interfaces
    `"
fi

# now, parse output from ip(8).  We might find more interfaces and more IPs.
# E.g. IPs assigned not using interfaces or cfg

# if we haven't set any variables, try something like this dynamic trick:
# (beware, untested code)
#ip a | while read -r num iface rest
#   do
#    case $num in [0-9]*:) echo $iface
#    esac
#  done

if command -v ip >/dev/null 2>&1
then
    # bash 3.2 FIXME
    eval "`
iface=
# jeden dva tri četiri pet ostalo
ip a | \
  while read -r jeden dva tri cetiri ostalo
  do
    case $jeden in
      [0-9]*:)
        iface=${dva%:}
      ;;
      inet)
        # if ip_${iface}_default unset, assign to it
        # nested eval.  would that work?
        # bash 3.2 FIXME
        eval ip="\"\\$ip_${iface}_default\""
        if test -z "$ip"
        then
          address=${dva%/*}
          netmask=${dva#*/}
          echo ip_${iface}_default=$address
          echo net_${iface}_default=$address/$netmask
        fi
      ;;
      inet6)
        # bash 3.2 FIXME
        eval ip6="\"\\$ip6_${iface}_default\""
        if test -z "$ip6" -a global=$cetiri
        then
          # test scope?
          # inet6 fe80::250:56ff:fe31:3831/64 scope link
          # inet 192.168.1.3/24 brd 192.168.1.255 scope global wlan0
          address=${dva%/*}
          netmask=${dva#*/}
          echo ip6_${iface}_default=$address
          echo net6_${iface}_default=$address/$netmask
        fi
      ;; 
    esac
  done 
  `"
else
  cat <<EOT >&2
autodetecs-ips: command 'ip' not found.  might have missed to autodetect some
IPs. please install the iproute package.
EOT
fi

#(if we want to depend upon awk:
# ip a | awk '/^[0-9]:/ { print $2; exit }'
#)