Git init
[pkgs/e/elektra.git] / scripts / convert-hosts
1 #!/bin/sh
2
3 ########################################################################
4 ##
5 ## This script will read /etc/hosts and create an
6 ## equivalent registry tree under $ROOT.
7 ##
8 ## The correct way to run it is:
9 ##
10 ## # ./hosts-convert | sh -e
11 ##
12 ##
13 ## To make tests you can do:
14 ##
15 ## $ ROOT=user/test ./hosts-convert | sh -e
16 ##
17 ## Vladimir Shabanov <virl@mail.ru>
18 ## June 2004
19 ##
20 ## $Id$
21 ##
22 ########################################################################
23
24
25 [ -z "$RG" ] && RG="kdb"
26 [ -z "$ROOT" ] && ROOT="system/network/hosts"
27
28
29 cat /etc/hosts | sed /"#"/d | while read -a hosts; do
30
31         echo $RG set -c \"Hostname\" $ROOT/${hosts[0]}/hostname \'${hosts[1]}\'
32         
33         total_words=`echo ${hosts[*]} | wc -w`
34         for (( i=2; $((i < $total_words)); i++ )); do
35         num=$((i-2))
36         echo $RG set -c \"Hostname alias\" $ROOT/${hosts[0]}/host_alias$num \'${hosts[$i]}\'
37         done
38         
39 done