| 1 |
#! /usr/bin/perl |
| 2 |
# |
| 3 |
# Copyright (c) Members of the EGEE Collaboration. 2004-2010. |
| 4 |
# See http://www.eu-egee.org/partners/ for details on the copyright |
| 5 |
# holders. |
| 6 |
# |
| 7 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
# you may not use this file except in compliance with the License. |
| 9 |
# You may obtain a copy of the License at |
| 10 |
# |
| 11 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
# |
| 13 |
# Unless required by applicable law or agreed to in writing, software |
| 14 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
# See the License for the specific language governing permissions and |
| 17 |
# limitations under the License. |
| 18 |
# |
| 19 |
# |
| 20 |
# Authors: |
| 21 |
# 2009- |
| 22 |
# Oscar Koeroo <[email protected]> |
| 23 |
# Mischa Sall\'e <[email protected]> |
| 24 |
# David Groep <[email protected]> |
| 25 |
# NIKHEF Amsterdam, the Netherlands |
| 26 |
# <[email protected]> |
| 27 |
# |
| 28 |
# 2007-2009 |
| 29 |
# Oscar Koeroo <[email protected]> |
| 30 |
# David Groep <[email protected]> |
| 31 |
# NIKHEF Amsterdam, the Netherlands |
| 32 |
# |
| 33 |
# 2003-2007 |
| 34 |
# Martijn Steenbakkers <[email protected]> |
| 35 |
# Gerben Venekamp <[email protected]> |
| 36 |
# Oscar Koeroo <[email protected]> |
| 37 |
# David Groep <[email protected]> |
| 38 |
# NIKHEF Amsterdam, the Netherlands |
| 39 |
|
| 40 |
#ldapsearch -H ldap://tbn06.nikhef.nl/ \ |
| 41 |
# -b "ou=poolaccounts,dc=farmnet,dc=nikhef,dc=nl" -LLL -x \ |
| 42 |
# description | \ |
| 43 |
# awk -F: '/export/ {print "mkdir $NF" }' | \ |
| 44 |
# xargs mkdir |
| 45 |
|
| 46 |
use Net::LDAP qw(:all); # for all code |
| 47 |
use Net::LDAP::Util qw(ldap_error_name |
| 48 |
ldap_error_text); # for error handling |
| 49 |
|
| 50 |
use Getopt::Long; |
| 51 |
|
| 52 |
@optdef=qw( v:i ); |
| 53 |
|
| 54 |
$0 =~ s/.*\///; |
| 55 |
$Getopt::Long::ignorecase=0; |
| 56 |
&GetOptions(@optdef); |
| 57 |
|
| 58 |
$ldap = Net::LDAP->new( "tbn06.nikhef.nl", port=>389, timeout=>20 ); |
| 59 |
$ldap or |
| 60 |
die "Cannot contact remote tbn06: $!\n". |
| 61 |
" $ldap_error_name $ldap_error_text\n"; |
| 62 |
|
| 63 |
$results=$ldap->search( |
| 64 |
base=>"ou=poolaccounts,dc=farmnet,dc=nikhef,dc=nl", |
| 65 |
scope=>"sub", |
| 66 |
filter=>"(objectclass=*)" |
| 67 |
); |
| 68 |
|
| 69 |
my @entries=$results->entries; |
| 70 |
|
| 71 |
foreach $entry ( @entries ) { |
| 72 |
$desc=$entry->get_value("description"); |
| 73 |
($dir=$desc)=~s/.*://; |
| 74 |
$dir=~/\/export\// or next; |
| 75 |
|
| 76 |
$uid=$entry->get_value("uidNumber"); |
| 77 |
$gid=$entry->get_value("gidNumber"); |
| 78 |
|
| 79 |
|
| 80 |
print "mkdir -p $dir ; mkdir $dir/.ssh ; mkdir $dir/.globus\n"; |
| 81 |
print "ssh-keygen -f $dir/.ssh/id_rsa -q -t rsa -N \"\" -C \"autogenerated\" < /dev/null\n"; |
| 82 |
print "cat $dir/.ssh/id_rsa.pub > $dir/.ssh/authorized_keys2\n"; |
| 83 |
print "chmod 755 $dir\n"; |
| 84 |
print "chmod 755 $dir/.ssh\n"; |
| 85 |
print "chown -R $uid:$gid $dir\n"; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|