Merge lp:~jontai/openvista-gtm-integration/replication into lp:~derek-name/openvista-gtm-integration/replication

Proposed by Jon Tai
Status: Merged
Approved by: Derek_
Approved revision: 265
Merged at revision: 515
Proposed branch: lp:~jontai/openvista-gtm-integration/replication
Merge into: lp:~derek-name/openvista-gtm-integration/replication
Diff against target: 150 lines (+55/-59)
1 file modified
scripts/usr/sbin/ovgenconfig (+55/-59)
To merge this branch: bzr merge lp:~jontai/openvista-gtm-integration/replication
Reviewer Review Type Date Requested Status
Derek_ Approve
Review via email: mp+41246@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Derek_ (derek-name) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/usr/sbin/ovgenconfig'
2--- scripts/usr/sbin/ovgenconfig 2010-11-02 15:56:19 +0000
3+++ scripts/usr/sbin/ovgenconfig 2010-11-18 22:36:10 +0000
4@@ -65,19 +65,6 @@
5 EOF
6 }
7
8-# "ROOT=$root" \
9-# "INSTANCE=$instance" \
10-# "REPLICATION_IP=$replication_ip" \
11-# "BIND_ADDRESS=$bind_address" \
12-# "USER=$user" \
13-# "RSYNC_PORT=$rsync_port" \
14-# "APACHE_USER=$apache_user" \
15-# "DOCROOT=$docroot" \
16-# "REPLICATION_MODE=$replication_mode" \
17-# "OTHER_INSTANCE=$other_instance" \
18-# "MUPIP_PORT=$mupip_port" \
19-# "INSTSECONDARY=$instsecondary" \
20-
21 # check permissions
22 if [[ $(id -u) != 0 ]]; then
23 exit_command 4 "Only root may edit OpenVista configuration files"
24@@ -114,71 +101,80 @@
25 is_openvista_instance "$instance" \
26 || exit_command $? "For instance \"$instance\": $ov_error"
27
28+install_dir="$root/$instance/$subdirectory"
29+[[ -d "$install_dir" ]] \
30+ || exit_command 1 "Directory \"$install_dir\" does not exist"
31+
32 if $edit_existing; then
33- # Not all types of configuration files can be sourced for their
34- # existing values in the same way as replication.conf.
35- # This case statement allows for other types being supported in the future.
36+ # Different config files have different formats. Support for each type of
37+ # file must be written explicitly.
38 case $conf_file in
39 "replication.conf")
40- # get the settings based on the existing file
41- . "$root/$instance/etc/replication.conf"
42- existing_settings=()
43- existing_settings+=( "REPLICATION_MODE=$replication_mode" )
44- existing_settings+=( "REPLICATION_IP=$replication_ip" )
45- existing_settings+=( "BIND_ADDRESS=$bind_address" )
46- existing_settings+=( "OTHER_INSTANCE=$other_instance" )
47- existing_settings+=( "MUPIP_PORT=$mupip_port" )
48- existing_settings+=( "INSTSECONDARY=$instsecondary" )
49- existing_settings+=( "RSYNC_PORT=$rsync_port" )
50- for setting in "${existing_settings[@]}"; do
51- key="${setting%%=*}"
52- value="${setting#*=}"
53- # if the new settings do not have the key,
54- # add the existing setting for it
55- array_lookup -q -d "=" "$key" "${settings[@]}" \
56- || settings+=( "$setting" )
57- done
58 ;;
59 *)
60 exit_command 2 "The -e option cannot be used with $conf_file"
61 ;;
62 esac
63+
64+ [[ -f "$install_dir/$conf_file" ]] \
65+ || exit_command 1 "File \"$install_dir/$conf_file\" is not found"
66+else
67+ template_file="/usr/share/openvista/$conf_file"
68+ [[ -f "$template_file" ]] \
69+ || exit_command 1 "File \"$template_file\" is not found"
70 fi
71
72-install_dir="$root/$instance/$subdirectory"
73-
74 log -l "Creating \"$install_dir/$conf_file\" for $instance"
75
76-template_file="/usr/share/openvista/$conf_file"
77-[[ -f "$template_file" ]] \
78- || exit_command 1 "File \"$template_file\" is not found"
79-
80 # create a temporary directory in which to generate the new file
81 tempdir=$(mktemp -d -p "$install_dir" .ovgenconfig.XXXXXXXXXX) \
82 || exit_command 1 "Failed to create temporary directory in $install_dir"
83
84-# make a copy of the template file in the temporary directory
85-install -o root -g $user -m 640 "$template_file" "$tempdir/" \
86- || exit_command 1 "Failed to create a temporary file from the template"
87-
88-if [[ "${settings[@]}" ]]; then
89- # replace the magic strings in the new copy of the template file
90- expressions=()
91- for setting in "${settings[@]}"; do
92- key="${setting%%=*}"
93- value="${setting#*=}"
94- expressions+=( -e "s!{$key}!$value!g" )
95- done
96- sed -i "$tempdir/$conf_file" "${expressions[@]}" \
97- || exit_command 1 "Failed to write new values to the temporary file"
98+if $edit_existing; then
99+ # make a copy of the config file in the temporary directory
100+ cp -p "$install_dir/$conf_file" "$tempdir/" \
101+ || exit_command 1 "Failed to create a temporary file from the existing" \
102+ "configuration file"
103+
104+ case $conf_file in
105+ "replication.conf")
106+ if [[ "${settings[@]}" ]]; then
107+ # replace only the settings given to us while leaving the rest of
108+ # the file alone
109+ expressions=()
110+ for setting in "${settings[@]}"; do
111+ key=$(to_lower "${setting%%=*}")
112+ value="${setting#*=}"
113+ expressions+=( -e "s!$key=.*\$!$key=$value!" )
114+ done
115+ sed -i "$tempdir/$conf_file" "${expressions[@]}" \
116+ || exit_command 1 "Failed to write new values to the temporary file"
117+ fi
118+ ;;
119+ esac
120+else
121+ # make a copy of the template file in the temporary directory
122+ install -o root -g $user -m 640 "$template_file" "$tempdir/" \
123+ || exit_command 1 "Failed to create a temporary file from the template"
124+
125+ if [[ "${settings[@]}" ]]; then
126+ # replace the magic strings in the new copy of the template file
127+ expressions=()
128+ for setting in "${settings[@]}"; do
129+ key="${setting%%=*}"
130+ value="${setting#*=}"
131+ expressions+=( -e "s!{$key}!$value!" )
132+ done
133+ sed -i "$tempdir/$conf_file" "${expressions[@]}" \
134+ || exit_command 1 "Failed to write new values to the temporary file"
135+ fi
136 fi
137
138-# copy the finished configuration file to the intended subdirectory
139-cp -p "$tempdir/$conf_file" "$install_dir/$conf_file" \
140+# move the finished configuration file to the intended subdirectory
141+mv -f "$tempdir/$conf_file" "$install_dir/$conf_file" \
142 || exit_command 1 "Failed to copy the temporary file to the intended" \
143 "subdirectory"
144
145-# remove the temporary file and temporary directory
146+# remove the temporary directory
147 rm -rf "$tempdir" \
148- || exit_command 1 "Failed to remove the temporary file and/or temporary" \
149- "directory"
150+ || exit_command 1 "Failed to remove the temporary directory"

Subscribers

People subscribed via source and target branches

to all changes: