~ubuntu-branches/ubuntu/trusty/nordugrid-arc/trusty

« back to all changes in this revision

Viewing changes to src/utils/ngclient2arc

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2013-11-29 13:39:10 UTC
  • mfrom: (3.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20131129133910-sy6ayoavphc5hozs
Tags: 4.0.0-1
4.0.0 Release (Closes: #715131) (LP: #1049798)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
 
3
 
get_giis_from_section() { # args: file_name, section_name; output: array of URLs
4
 
  # sed script to find all the sections in file_name with the given section_name and parse out the URLs
5
 
  if [[ -f $1 ]]; then
6
 
    sed -n '{
7
 
      # if a section start is found, jump to ":section" to process it
8
 
      /^\s*\[/ b section
9
 
      # if this line is not a section start, append it to the hold buffer
10
 
      H
11
 
      # if this is the last line, jump to ":section" to process it
12
 
      $ b section
13
 
      # otherwise skip the ":section" part
14
 
      b
15
 
      # process a section
16
 
      :section
17
 
        # put the lines from the hold buffer (containing the whole
18
 
        # previous section) the patter space and also put the line
19
 
        # from the pattern space (containing the header of the next
20
 
        # section) to the hold buffer
21
 
        x
22
 
        # if it starts with the section name we want, print it
23
 
        /^\s*\[\s*'$2'\s*\]/ p
24
 
        # otherwise dont do anything: skip this section
25
 
    }' $1 | sed -n 's/^\s*giis\s*=\s*"\(.*\)"\s*$/\1/p' # get the URLs from the lines starting with giis=
26
 
  fi
27
 
}
28
 
 
29
 
get_giis_from_file() { # args: file_name; output: array of URLs
30
 
  if [[ -f $1 ]]; then
31
 
    cat $1
32
 
  fi
33
 
}
34
 
 
35
 
echo ''
36
 
echo '=== ARC client configuration conversion ==='
37
 
echo ''
38
 
 
39
 
# 1. giis options in client section in $HOME/.arc/client.conf
40
 
giislist=`get_giis_from_section $HOME/.arc/client.conf client`
41
 
if [[ ! $giislist ]]; then
42
 
  # 2. giis options in common section in $HOME/.arc/client.conf
43
 
  giislist=`get_giis_from_section $HOME/.arc/client.conf common`
44
 
  if [[ ! $giislist ]]; then
45
 
    # 3. $HOME/.nggiislist (one GIIS per line, ARC <= 0.5.48)
46
 
    giislist=`get_giis_from_file $HOME/.nggiislist`
47
 
    if [[ ! $giislist ]]; then
48
 
      # 4. giis options in client section in $ARC_LOCATION/etc/arc.conf
49
 
      giislist=`get_giis_from_section $ARC_LOCATION/etc/arc.conf client`
50
 
      if [[ ! $giislist ]]; then
51
 
        # 5. giis options in common section in $ARC_LOCATION/etc/arc.conf
52
 
        giislist=`get_giis_from_section $ARC_LOCATION/etc/arc.conf common`
53
 
        if [[ ! $giislist ]]; then
54
 
          # 6. $ARC_LOCATION/etc/giislist (one GIIS per line)
55
 
          giislist=`get_giis_from_file $ARC_LOCATION/etc/giislist`
56
 
          if [[ ! $giislist ]]; then
57
 
            # 7. giis options in client section in /etc/arc.conf
58
 
            giislist=`get_giis_from_section /etc/arc.conf client`
59
 
            if [[ ! $giislist ]]; then
60
 
              # 8. giis options in common section in /etc/arc.conf
61
 
              giislist=`get_giis_from_section /etc/arc.conf common`
62
 
              if [[ ! $giislist ]]; then
63
 
                # 9. /etc/giislist (one GIIS per line)
64
 
                giislist=`get_giis_from_file /etc/giislist`
65
 
              fi
66
 
            fi
67
 
          fi
68
 
        fi
69
 
      fi
70
 
    fi
71
 
  fi
72
 
fi
73
 
 
74
 
conffile=$HOME/.arc/client.conf
75
 
 
76
 
echo '--- GIIS URLs ---'
77
 
echo ''
78
 
 
79
 
if [[ $giislist ]]; then
80
 
 
81
 
  if [[ -f $conffile ]]; then
82
 
    conffile_exists=true
83
 
  fi
84
 
 
85
 
  if [[ ! $conffile_exists ]]; then
86
 
    echo "Please create the file $HOME/.arc/client.conf. Edit the following as needed and put it into that file!"
87
 
  else
88
 
    echo "Please edit the following if needed and put it into your $HOME/.arc/client.conf!"
89
 
  fi
90
 
  echo ''
91
 
 
92
 
  for giis in ${giislist[@]}; do
93
 
    # use hostname as alias
94
 
    hostname=`echo $giis | sed 's#^ldap://\(.*\):.*#\1#'`
95
 
    # check if index or local ARIS
96
 
    islocal=`echo $giis | grep -i "mds-vo-name=local"`
97
 
    
98
 
    if [[ $islocal ]]; then
99
 
      echo "[computing/$hostname]"
100
 
      echo "url=$hostname"
101
 
      echo "infointerface=org.nordugrid.ldapng"
102
 
      echo "jobinterface=org.nordugrid.gridftpjob"
103
 
    else
104
 
      echo "[registry/$hostname]"
105
 
      echo "url=$giis"
106
 
      echo "registryinterface=org.nordugrid.ldapegiis"
107
 
    fi
108
 
    # In ARC 0.x all giises were used by default
109
 
    echo "default=yes"
110
 
    echo ''
111
 
  done
112
 
 
113
 
else
114
 
  
115
 
  echo 'No GIIS URLs found in the old configs.'
116
 
 
117
 
fi
118
 
 
119
 
echo ''
120
 
echo '--- ALIASes ---'
121
 
echo ''
122
 
 
123
 
tempfile=`mktemp /tmp/ngclient2arc.XXXXXXXXXX`
124
 
 
125
 
if [[ $? = 0 ]]; then
126
 
  if [[ -f $HOME/.arc/client.conf ]]; then
127
 
    sed -n 's/^\s*alias\s*=\s*\"\s*\(.*\)\s*\"\s*$/\1/p' $HOME/.arc/client.conf > $tempfile
128
 
  fi
129
 
  if [[ -f $HOME/.ngalias ]]; then
130
 
    cat $HOME/.ngalias >> $tempfile
131
 
  fi
132
 
 
133
 
  if [[ -s $tempfile ]]; then
134
 
 
135
 
    if [[ -f $conffile ]]; then
136
 
      conffile_exists=true
137
 
    else
138
 
      conffile_exists=
139
 
    fi
140
 
 
141
 
    if [[ ! $conffile_exists ]]; then
142
 
      echo "Please create the file $HOME/.arc/client.conf. Edit the following as needed and put it into that file!"
143
 
    else
144
 
      echo "Please edit the following if needed and put it into your $HOME/.arc/client.conf!"
145
 
    fi
146
 
 
147
 
    echo ''
148
 
 
149
 
    # channel the file into stdin
150
 
    exec 9<&0
151
 
    exec < $tempfile
152
 
 
153
 
    # for each alias line
154
 
    while read line; do
155
 
      # get the alias name (before the '=')
156
 
      newalias=`echo $line | sed -n 's/^\s*\([^=]*\)\s*=.*$/\1/p'`
157
 
      # get the URLs (after the '=')
158
 
      urls=`echo $line | sed -n 's/^[^=]*=\(.*\)$/\1/p'`
159
 
      # for each URL
160
 
      for url in $urls; do
161
 
        # if the URL can be found among the aliases (before an '=')
162
 
        if [[ `sed -n '/^\s*'$url'\s*=.*$/ p' $tempfile` ]]; then
163
 
          # then this is an alias and not a URL
164
 
          # TODO: automatically add group= to each section
165
 
          echo "To use $newalias as a group alias put group=$newalias in the [computing/$url] block"
166
 
        else
167
 
          # else this is a real URL
168
 
          echo "[computing/$newalias]"
169
 
          echo "url=$url"
170
 
          echo "infointerface=org.nordugrid.ldapng"
171
 
          echo "jobinterface=org.nordugrid.gridftpjob"
172
 
        fi
173
 
      done
174
 
      echo ''
175
 
    done
176
 
 
177
 
    # restore stdin
178
 
    exec 0<&9 9<&-
179
 
 
180
 
  else
181
 
    
182
 
    echo 'No aliases found in the old config files.'
183
 
 
184
 
  fi
185
 
 
186
 
  rm $tempfile
187
 
  
188
 
  echo ''
189
 
 
190
 
else
191
 
  
192
 
  echo '  Error creating tempfile: alias conversion failed.'
193
 
  echo ''
194
 
 
195
 
fi
196
 
 
197
 
echo '--- Active jobs ---'
198
 
echo ''
199
 
echo 'In order to use arc* commands to manipulate the jobs you submitted with ngsub,'
200
 
echo 'you have to run the arcsync command with specifying clusters and/or GIISes:'
201
 
echo '  arcsync [-c cluster1 -c cluster2 ...] [-g giis1 -g giis2 ...]'
202
 
echo ''
 
 
b'\\ No newline at end of file'