-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetProjectVersion.sh
More file actions
executable file
·53 lines (43 loc) · 1.44 KB
/
SetProjectVersion.sh
File metadata and controls
executable file
·53 lines (43 loc) · 1.44 KB
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
#!/bin/bash
# Usage message
USAGE="[i] Usage: ./SetProjectVersion.sh <version number>"
VERSION_FORMAT="[i] Acceptable format: ^[0-9]+\.[0-9]+\.[0-9]+$"
# Check if version number is provided
if [ -z "$1" ]; then
echo "[!] A version number is needed for this script to work."
echo "$USAGE"
exit 1
fi
# Assign the provided version number to a variable
newVersion="$1"
# Verify version number format
if ! [[ $newVersion =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "[!] Invalid version number format."
echo "$VERSION_FORMAT"
exit 1
fi
# Define the version pattern and new pattern
versionPattern="<Version>0\.0\.0</Version>"
newPattern="<Version>$newVersion</Version>"
# Escape the slash with backslash!
sedVersionPattern="<Version>0\.0\.0<\/Version>"
sedNewPattern="<Version>$newVersion<\/Version>"
# Find matching project configuration files
projectFiles=$(find . -name "osu.*.csproj")
updatedCount=0
# Loop through each project file
for file in $projectFiles; do
# Check if the file contains the version pattern
if grep -q "$versionPattern" "$file"; then
echo "[i] Updating file: $file"
# Use sed to replace the version pattern with the new pattern
sed -i "s/$sedVersionPattern/$sedNewPattern/g" "$file"
updatedCount=$((updatedCount+1))
fi
done
# Output the result
if [ $updatedCount -eq 0 ]; then
echo "[i] No project file needs updating."
else
echo "[i] Updated $updatedCount file(s)."
fi