]> err.no Git - scalable-opengroupware.org/blob - Scripts/sql-update-20070724.sh
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1276 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / Scripts / sql-update-20070724.sh
1 #!/bin/bash
2
3 # this script only work with PostgreSQL, which at this time is the only
4 # database really supported by SOGo/SOPE
5
6 defaultusername=$USER
7 defaulthostname=localhost
8 defaultdatabase=$USER
9
10 read -p "Username ($defaultusername): " username
11 read -p "Hostname ($defaulthostname): " hostname
12 read -p "Database ($defaultdatabase): " database
13
14 if [ -z "$username" ]
15 then
16   username=$defaultusername
17 fi
18 if [ -z "$hostname" ]
19 then
20   hostname=$defaulthostname
21 fi
22 if [ -z "$database" ]
23 then
24   database=$defaultdatabase
25 fi
26
27 echo ""
28 echo "You will now be requested your password thrice..."
29 echo "After that, a list of SQL operations will scroll."
30 echo ""
31
32 sqlscript=""
33
34 function renameFields() {
35     oldIFS="$IFS"
36     IFS=" "
37     set $fields
38     for field in $@
39     do
40         part="`echo -e \"ALTER TABLE $table RENAME $field TO c_${field};\\n\"`";
41         sqlscript="$sqlscript$part"
42     done
43     IFS="$oldIFS"
44 }
45
46 table=sogo_user_profile
47 fields="uid defaults settings"
48 renameFields
49
50 fields="uid startdate enddate cycleenddate title cycleinfo participants isallday iscycle classification status priority isopaque location orgmail partmails partstates sequence component"
51 tables=`psql -U $username -h $hostname $database -c "select split_part(c_quick_location, '/', 5) from sogo_folder_info where c_folder_type ilike 'Appointment';" | grep _quick`
52 for table in $tables;
53 do
54   renameFields
55 done
56
57 fields="givenname cn sn l mail o ou telephonenumber screenname"
58 tables=`psql -U $username -h $hostname $database -c "select split_part(c_quick_location, '/', 5) from sogo_folder_info where c_folder_type ilike 'Contact';" | grep _quick`
59 for table in $tables;
60 do
61   renameFields
62 done
63
64 sqlscript="$sqlscript;"
65 echo "$sqlscript" | psql -e -U $username -h $hostname $database