File: update_version_number.sh

package info (click to toggle)
exult 1.12.1-1
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 43,856 kB
  • sloc: cpp: 170,016; xml: 7,400; yacc: 2,850; makefile: 2,419; java: 1,901; ansic: 1,654; lex: 673; sh: 550; objc: 416
file content (233 lines) | stat: -rwxr-xr-x 8,603 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/bash

# run from the root of our source to update all version numbers and possible git/snapshot identifiers

# Check if version number argument is provided
if [ -z "$1" ]; then
	echo "Error: No version number provided."
	echo "Usage: ./update_version_number.sh VERSION"
	echo "Example: ./update_version_number.sh 1.12"
	exit 1
fi

NEW_VERSION="$1"
echo "Updating version to $NEW_VERSION"

# Check if version contains "git"
git=false
if [[ "$NEW_VERSION" == *"git"* ]]; then
	git=true
	echo "Git version detected"
fi

# Extract the base version without "git" for file version numbers
BASE_VERSION=$(echo "$NEW_VERSION" | sed 's/git//')

# Split version into components for FILE_VERSION
# Handle cases with two or three components (e.g., 1.12 or 1.12.3)
if [[ "$BASE_VERSION" =~ ^([0-9]+)\.([0-9]+)$ ]]; then
	# Two components like 1.12
	FILE_VERSION="${BASH_REMATCH[1]},${BASH_REMATCH[2]},0,0"
	SHORT_VERSION="${BASH_REMATCH[1]},${BASH_REMATCH[2]},0"
elif [[ "$BASE_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
	# Three components like 1.12.3
	FILE_VERSION="${BASH_REMATCH[1]},${BASH_REMATCH[2]},${BASH_REMATCH[3]},0"
	SHORT_VERSION="${BASH_REMATCH[1]},${BASH_REMATCH[2]},${BASH_REMATCH[3]}"
else
	echo "Error: Invalid version format. Expected formats: X.Y or X.Y.Z"
	exit 1
fi

echo "Base version: $BASE_VERSION"
echo "File version: $FILE_VERSION"

# For macOS, use LC_ALL=C to handle UTF-8 content
export LC_ALL=C

# Update configure.ac
if [ -f configure.ac ]; then
	echo "Updating configure.ac..."
	perl -i.bak -pe "s/AC_INIT\(\[Exult\],\[[0-9.]*[a-z]*\],/AC_INIT([Exult],[$NEW_VERSION],/" configure.ac
fi

# Update makefile.common
if [ -f makefile.common ]; then
	echo "Updating makefile.common..."
	perl -i.bak -pe "s/VERSION:=[0-9.]*[a-z]*/VERSION:=$NEW_VERSION/" makefile.common
fi

# Update Windows resource files
update_rc_file() {
	local file=$1
	if [ -f "$file" ]; then
		echo "Updating $file..."
        
		# Create a temporary file
		temp_file=$(mktemp)
        
		# Process the file using perl which handles UTF-8 better
		perl -pe "s/FILEVERSION [0-9,]*/FILEVERSION $FILE_VERSION/g" "$file" > "$temp_file"
		mv "$temp_file" "$file"
        
		temp_file=$(mktemp)
		perl -pe "s/PRODUCTVERSION [0-9,]*/PRODUCTVERSION $FILE_VERSION/g" "$file" > "$temp_file"
		mv "$temp_file" "$file"
        
		temp_file=$(mktemp)
		perl -pe "s/VALUE \"FileVersion\", \"[0-9., ]*[a-z]*\\\\0\"/VALUE \"FileVersion\", \"$NEW_VERSION\\\\0\"/" "$file" > "$temp_file"
		mv "$temp_file" "$file"
        
		temp_file=$(mktemp)
		perl -pe "s/VALUE \"ProductVersion\", \"[0-9.]*[a-z]*\\\\0\"/VALUE \"ProductVersion\", \"$NEW_VERSION\\\\0\"/" "$file" > "$temp_file"
		mv "$temp_file" "$file"
	fi
}

for rc_file in win32/exconfig.rc win32/exultico.rc win32/exultstudioico.rc; do
	update_rc_file "$rc_file"
done

# Update installer files - use perl for better UTF-8 handling
update_iss_file() {
	local file=$1
	if [ -f "$file" ]; then
		echo "Updating $file..."
        
		# Update VersionInfoVersion
		temp_file=$(mktemp)
		perl -pe "s/VersionInfoVersion=[0-9.]*/VersionInfoVersion=$BASE_VERSION/" "$file" > "$temp_file"
		mv "$temp_file" "$file"
        
		# Handle AppVerName based on file type
		if [ "$file" = "win32/exult_installer.iss" ]; then
			temp_file=$(mktemp)
			if [ "$git" = true ]; then
				# For git versions, add Snapshot
				perl -pe "s/AppVerName=Exult.*$/AppVerName=Exult $NEW_VERSION Snapshot/" "$file" > "$temp_file"
			else
				# For non-git versions, no Snapshot text
				perl -pe "s/AppVerName=Exult.*$/AppVerName=Exult $NEW_VERSION/" "$file" > "$temp_file"
			fi
			mv "$temp_file" "$file"
		elif [ "$file" = "win32/exult_studio_installer.iss" ]; then
			# Special case for studio installer
			temp_file=$(mktemp)
			if [ "$git" = true ]; then
				perl -pe "s/AppVerName=.*$/AppVerName=Exult Studio Git/" "$file" > "$temp_file"
			else
				perl -pe "s/AppVerName=.*$/AppVerName=Exult Studio $NEW_VERSION/" "$file" > "$temp_file"
			fi
			mv "$temp_file" "$file"
		elif [ "$file" = "win32/exult_tools_installer.iss" ]; then
			# Special case for tools installer
			temp_file=$(mktemp)
			if [ "$git" = true ]; then
				perl -pe "s/AppVerName=.*$/AppVerName=Exult Tools Git/" "$file" > "$temp_file"
			else
				perl -pe "s/AppVerName=.*$/AppVerName=Exult Tools $NEW_VERSION/" "$file" > "$temp_file"
			fi
			mv "$temp_file" "$file"
		elif [ "$file" = "win32/exult_shpplugin_installer.iss" ]; then
			# Special case for shape plugin installer
			temp_file=$(mktemp)
			if [ "$git" = true ]; then
				perl -pe "s/AppVerName=.*$/AppVerName=Shape plug-in Git/" "$file" > "$temp_file"
			else
				perl -pe "s/AppVerName=.*$/AppVerName=Shape plug-in $NEW_VERSION/" "$file" > "$temp_file"
			fi
			mv "$temp_file" "$file"
		fi
	fi
}

for iss_file in win32/exult_installer.iss win32/exult_studio_installer.iss win32/exult_tools_installer.iss win32/exult_shpplugin_installer.iss; do
	update_iss_file "$iss_file"
done

# Update MSVC include file
if [ -f msvcstuff/vs2019/msvc_include.h ]; then
	echo "Updating msvcstuff/vs2019/msvc_include.h..."
	temp_file=$(mktemp)
	perl -pe "s/#define VERSION[ ]*\"[0-9.]*[a-z]*\"/#define VERSION       \"$NEW_VERSION\"/" msvcstuff/vs2019/msvc_include.h > "$temp_file"
	mv "$temp_file" msvcstuff/vs2019/msvc_include.h
fi

# Update iOS config.h
if [ -f ios/include/config.h ]; then
	echo "Updating ios/include/config.h..."
	temp_file=$(mktemp)
	perl -pe "s/#define VERSION \"[0-9.]*[a-z]*\"/#define VERSION \"$NEW_VERSION\"/" ios/include/config.h > "$temp_file"
	mv "$temp_file" ios/include/config.h
    
	temp_file=$(mktemp)
	perl -pe "s/#define PACKAGE_VERSION \"[0-9.]*[a-z]*\"/#define PACKAGE_VERSION \"$NEW_VERSION\"/" ios/include/config.h > "$temp_file"
	mv "$temp_file" ios/include/config.h
    
	temp_file=$(mktemp)
	perl -pe "s/#define PACKAGE_STRING \"Exult [0-9.]*[a-z]*\"/#define PACKAGE_STRING \"Exult $NEW_VERSION\"/" ios/include/config.h > "$temp_file"
	mv "$temp_file" ios/include/config.h
fi

# Update iOS info.plist
if [ -f ios/info.plist ]; then
	echo "Updating ios/info.plist..."
	temp_file=$(mktemp)
	perl -0777 -i.bak -pe "s/<key>CFBundleShortVersionString<\/key>\s*<string>[0-9.]*[a-z]*<\/string>/<key>CFBundleShortVersionString<\/key>\n\t<string>$BASE_VERSION<\/string>/" ios/info.plist
fi

# Update Aseprite plugin version
if [ -f tools/aseprite_plugin/package.json ]; then
	echo "Updating tools/aseprite_plugin/package.json..."
	temp_file=$(mktemp)
	perl -pe "s/\"version\": \"[0-9.]*[a-z]*\",/\"version\": \"$NEW_VERSION\",/" tools/aseprite_plugin/package.json > "$temp_file"
	mv "$temp_file" tools/aseprite_plugin/package.json
fi

# Update macosx/macosx.am
if [ -f macosx/macosx.am ]; then
	echo "Updating macosx/macosx.am..."
    
	# Use a temporary file for each operation
	temp_file=$(mktemp)
    
	# First update: Exult volume name (main Exult DMG)
	# This pattern will match --volname "Exult..." but NOT --volname "Exult Studio..."
	if [ "$git" = true ]; then
		# For git versions, use "Exult Git Snapshot"
		perl -pe 's/--volname "Exult(?!\s+Studio)[^"]*"/--volname "Exult Git Snapshot"/g' macosx/macosx.am > "$temp_file"
	else
		# For release versions, use "Exult VERSION"
		perl -pe 's/--volname "Exult(?!\s+Studio)[^"]*"/--volname "Exult '"$NEW_VERSION"'"/g' macosx/macosx.am > "$temp_file"
	fi
	mv "$temp_file" macosx/macosx.am
    
	# Second update: Exult Studio volume name
	temp_file=$(mktemp)
	if [ "$git" = true ]; then
		# For git versions, use "Exult Studio Git Snapshot"
		perl -pe 's/--volname "Exult Studio[^"]*"/--volname "Exult Studio Git Snapshot"/g' macosx/macosx.am > "$temp_file"
	else
		# For release versions, use "Exult Studio VERSION"
		perl -pe 's/--volname "Exult Studio[^"]*"/--volname "Exult Studio '"$NEW_VERSION"'"/g' macosx/macosx.am > "$temp_file"
	fi
	mv "$temp_file" macosx/macosx.am

	# Third update: DMG filenames for Exult and Exult Studio
	temp_file=$(mktemp)
	if [ "$git" = true ]; then
		# For git versions, use snapshot filenames
		perl -pe 's/"Exult-[^\"]*\.dmg"/"Exult-snapshot.dmg"/g' macosx/macosx.am > "$temp_file"
		perl -pe 's/"ExultStudio-[^\"]*\.dmg"/"ExultStudio-snapshot.dmg"/g' macosx/macosx.am > "$temp_file"	
		mv "$temp_file" macosx/macosx.am
	else
 		# For release versions, use versioned filenames
		temp_file=$(mktemp)
		perl -pe "s/\"Exult-[^\"]*\\.dmg\"/\"Exult-$NEW_VERSION.dmg\"/g" macosx/macosx.am > "$temp_file"
		perl -pe "s/\"ExultStudio-[^\"]*\\.dmg\"/\"ExultStudio-$NEW_VERSION.dmg\"/g" macosx/macosx.am > "$temp_file"
		mv "$temp_file" macosx/macosx.am
	fi
fi

find . -name "*.bak" -type f -delete

echo "Version updated to $NEW_VERSION successfully!"