Modification on slabimporter to avoid creating an account when importing
[sfa.git] / sfa / senslab / config / bash_nukem
1 #!/bin/bash 
2
3 # Configuration first : set the local repository
4 # where the code can be found
5 # Test number of arguments 
6 if (( ! $# == 3 ))
7 then
8     echo " Usage : bash_nukem repository_directory vm (should be senslab or senslab2) and \
9     federation option (0 (not federated),1(other senslab) , 2(ple) 3 (senslab and ple))"
10     echo  $#
11     exit
12 fi
13
14 # Check if  directory exists
15 if [ -d $1 ]
16 then
17     git_local_repo=$1
18     echo "RESPOSITORY: "  $git_local_repo
19    
20 fi
21
22 # Set which vm we are working on (sfa-vm or sfa-vm2)
23 if [[ $2 = "senslab" || $2 = "senslab2" ]]
24 then
25     vm=$2
26     echo $vm
27 else
28     echo "Vm options should be senslab or senslab2, not " $2
29     exit 
30 fi
31
32 if [ $vm = "senslab" ]
33 then
34     federation_commented_line_nb=2
35 else
36     federation_commented_line_nb=3
37 fi
38
39 # First restart sfa (prevents stalling when connecting
40 # to the DB and dropping tables)
41 sudo service sfa restart
42
43 # Nuke the database 
44 sudo sfaadmin.py registry nuke
45
46 # Drop table in slab_sfa
47 # to avoid duplicates.
48 psql -d slab_sfa -U sfa -W -q -c "drop table slice_senslab;"
49 psql -d slab_sfa -U sfa -W -q -c "drop table slab_xp;"
50
51 # ATTENTION :Save the config file /etc/sfa/sfa_config
52 # before continuing
53
54 # Remove all the remaining gid, creds files
55 # of the server
56 sudo rm -rf /var/lib/sfa
57 cd /etc/sfa
58 sudo rm -rf *
59 sudo service sfa restart
60
61 # Put back the config file that you saved before
62 cd $git_local_repo
63 sudo make clean
64 make
65 sudo python setup.py install
66 # sudo service sfa restart
67
68 # Wrote /etc/sfa/configs/site.xml
69 # Merged
70 #         /etc/sfa/default_config.xml
71 # and     /etc/sfa/configs/site.xml
72 # into    /etc/sfa/sfa_config.xml
73 # sudo sfa-config-tty
74
75 #sudo cp $git_local_repo/sfa/senslab/config/$vm/sfa_config /etc/sfa/sfa_config
76 sudo cp $git_local_repo/sfa/senslab/config/$vm/sfa_config.xml /etc/sfa/sfa_config.xml
77 sudo cp $git_local_repo/sfa/senslab/config/$vm/default_config.xml /etc/sfa/default_config.xml
78 # sudo cp $git_local_repo/sfa/senslab/config/$vm/site.xml  /etc/sfa/site.xml
79 # sudo cp $git_local_repo/sfa/senslab/config/$vm/site_config  /etc/sfa/configs/site_config
80 # sudo ln -s ldap_config.py  /etc/sfa/ldap_config.py
81 sudo cp $git_local_repo/sfa/senslab/config/registries.xml /etc/sfa/registries.xml
82 sudo cp $git_local_repo/sfa/senslab/config/aggregates.xml /etc/sfa/aggregates.xml
83
84
85 case "$3" in
86     0) echo "No federation at all"
87         #Insert a # on every beginning of line except if there is 'aggregates'
88         sed -i '/aggregates/!s/^/#/g' /etc/sfa/aggregates.xml 
89         sed -i '/aggregates/!s/^/#/g' /etc/sfa/registries.xml   
90         ;;
91     1) echo "Setting up federation with other senslab "
92         #  Commenting out senslab and ple, lines 2 and 4 OR
93         #  Commenting out senslab2 and ple, lines 3 and 4
94         sed -i "${federation_commented_line_nb} s/^/#/" /etc/sfa/aggregates.xml 
95         sed -i "${federation_commented_line_nb} s/^/#/" /etc/sfa/registries.xml 
96         sed -i '4 s/^/#/' /etc/sfa/aggregates.xml 
97         sed -i '4 s/^/#/' /etc/sfa/registries.xml 
98         ;;
99
100     2) echo "Setting up federation with  ple " 
101         sed -i '2 s/^/#/' /etc/sfa/aggregates.xml 
102         sed -i '2 s/^/#/' /etc/sfa/registries.xml 
103         sed -i '3 s/^/#/' /etc/sfa/aggregates.xml 
104         sed -i '3 s/^/#/' /etc/sfa/registries.xml 
105         ;;  
106
107     3) echo "setting federation with other senslab and ple"
108         # Commenting out senslab or senslab2
109         sed -i "${federation_commented_line_nb} s/^/#/" /etc/sfa/aggregates.xml 
110         sed -i "${federation_commented_line_nb} s/^/#/" /etc/sfa/registries.xml 
111         ;;
112 esac
113
114 #Senslab LDAP and OAR access config files
115 if [ ! -f /etc/sfa/ldap_config.py ] 
116 then
117     sudo cp $git_local_repo/sfa/senslab/config/ldap_config.py  /etc/sfa/ldap_config.py 
118 fi
119
120 if [ ! -f /etc/sfa/oar_config.py ] 
121 then
122     sudo cp $git_local_repo/sfa/senslab/config/oar_config.py  /etc/sfa/oar_config.py 
123 fi
124
125 sudo service sfa restart
126
127 # User stuff : clean your folder
128 cd  ~/.sfi
129 rm *.sscert *.cred *.gid sfi_cache.dat
130 cd ~
131
132 # Import the datbase form ldap
133 sudo sfaadmin.py registry import_registry
134 sudo service sfa restart
135
136 sudo rm -rf /var/lib/sfa/authorities/plc