~percona-toolkit-dev/percona-toolkit/pqd-enhanced-resume-file

« back to all changes in this revision

Viewing changes to util/update-modules

  • Committer: Daniel Nichter
  • Date: 2012-08-17 17:27:41 UTC
  • mto: This revision was merged to the branch mainline in revision 365.
  • Revision ID: daniel@percona.com-20120817172741-d0uj1sve5fitmwql
Add lib/Percona/Toolkit.pm for $Percona::Toolkit::VERSION.  Put that in pt-diskstats.  Add util/tool-header to update %INC magic when bin/update-modules is ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
# Standard startup, find the branch's root directory
5
5
# ############################################################################
6
6
 
7
 
exit_status=0
 
7
EXIT_STATUS=0
8
8
 
9
9
die() {
10
10
   echo $1  >&2
13
13
 
14
14
warn() {
15
15
   echo $1 >&2
16
 
   exit_status=$((exit_status | 1))
 
16
   EXIT_STATUS=$((EXIT_STATUS | 1))
17
17
}
18
18
 
19
19
cwd="$PWD"
34
34
# Global variables
35
35
# ############################################################################
36
36
 
37
 
CHECK=${CHECK:-1}
 
37
# None
38
38
 
39
39
# ############################################################################
40
40
# Subroutines
41
41
# ############################################################################
42
42
 
43
 
file_is_modified() {
44
 
   local file=$1
45
 
   if [ $CHECK -eq 1 ]; then
46
 
      bzr status $file | grep -q modified
47
 
   else
48
 
      return 1
49
 
   fi
50
 
}
51
 
 
52
43
pkgs_in_tool() {
53
44
   local tool=$1
54
45
   if [ "$tool_lang" = "perl" ]; then
55
 
      pkgs=$(grep '^package [A-Za-z]*;' $tool | cut -d' ' -f2 | cut -d';' -f1)
 
46
      pkgs=$(grep '^package [A-Za-z:]*;' $tool | cut -d' ' -f2 | cut -d';' -f1)
56
47
   else
57
48
      pkgs=$(grep '^# [a-z_]* package' $tool | awk '{print $2}')
58
49
   fi
82
73
      echo "# $pkg package
83
74
# This package is a copy without comments from the original.  The original
84
75
# with comments and its test file can be found in the Bazaar repository at,
85
 
#   lib/$pkg.pm
86
 
#   t/lib/$pkg.t
 
76
#   lib/$pkg_file_base.pm
 
77
#   t/lib/$pkg_file_base.t
87
78
# See https://launchpad.net/percona-toolkit for more information.
88
79
# ###########################################################################
89
80
{" >> $tmp_file
108
99
# End $pkg package" >> $tmp_file
109
100
 
110
101
   tail -n +$pkg_end_line  $tool_file >> $tmp_file
111
 
 
 
102
 
112
103
   mv $tmp_file $tool_file
113
104
114
105
 
 
106
update_tool_header() {
 
107
   local tool_file=$1
 
108
 
 
109
   local start_line=$(grep -m 1 -n "^# ###" $tool_file | cut -d':' -f1)
 
110
   if [ -z "$start_line" ]; then
 
111
      warn "$tool_file does not have a package header line"
 
112
      return 1
 
113
   fi
 
114
   start_line=$((start_line - 1))
 
115
 
 
116
   tail -n +$start_line $tool_file > $tool_file-code
 
117
   $BRANCH/util/tool-header $tool_file > $tool_file-header
 
118
   if [ $? -ne 0 ]; then
 
119
      warn "Failed to update tool header for $tool_file"
 
120
      return 1
 
121
   fi
 
122
   cat $tool_file-header $tool_file-code > $tool_file
 
123
}
 
124
 
115
125
# ############################################################################
116
126
# Script starts here
117
127
# ############################################################################
119
129
tool_file=$1
120
130
 
121
131
if [ -z "$tool_file" ]; then
122
 
   die "Usage: $0 TOOL [MODULE...]"
 
132
   die "Usage: $0 TOOL [MODULES]"
123
133
fi
124
134
 
125
135
if [ ! -f $tool_file ]; then
150
160
   fi
151
161
 
152
162
   if [ "$tool_lang" = "perl" ]; then
 
163
      # Perl :: package separators translate to directory slashes.
153
164
      pkg_file="$BRANCH/lib/$pkg.pm"
 
165
      pkg_file=${pkg_file//"::"/"/"}
 
166
      pkg_file_base=${pkg//"::"/"/"}
154
167
   else
155
168
      pkg_file="$BRANCH/lib/bash/$pkg.sh"
156
169
   fi
160
173
      continue
161
174
   fi
162
175
 
163
 
   # if file_is_modified $pkg_file; then
164
 
      # warn "$pkg_file has uncommitted changes"
165
 
      # continue
166
 
   # fi 
167
 
 
168
176
   replace_pkg_in_tool $tmp_tool_file
169
177
   if [ $? -eq 0 ]; then
170
178
      echo "Updated $pkg"
172
180
   fi
173
181
done
174
182
 
175
 
if [ $pkgs_updated -ne 0 ]; then
176
 
   cp $tmp_tool_file $tool_file
 
183
if [ $pkgs_updated -gt 0 ]; then
 
184
   update_tool_header $tmp_tool_file
177
185
   if [ $? -ne 0 ]; then
178
 
      warn "Failed to copy $tmp_tool_file to $tool_file"
179
 
   else
180
 
      rm $tmp_tool_file > /dev/null
181
 
      exit_status=$((exit_status | $?))
 
186
      warn "Failed to update tool header"
 
187
   else 
 
188
      cp $tmp_tool_file $tool_file
 
189
      if [ $? -ne 0 ]; then
 
190
         warn "Failed to copy $tmp_tool_file to $tool_file"
 
191
      else
 
192
         rm $tmp_tool_file > /dev/null
 
193
         EXIT_STATUS=$((EXIT_STATUS | $?))
 
194
      fi
182
195
   fi
183
196
fi
184
197
 
185
 
exit $exit_status
 
198
exit $EXIT_STATUS