-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion
executable file
·202 lines (181 loc) · 5.81 KB
/
version
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
#####
# SOF START
# @name Mod versions
# @file version
# @author HashtagShell
# @depends xdotool
# SOF END
#####
#!/bin/bash
# Script to change mod versions from conveniently from commandline
# @author HashtagShell https://github.com/HashtagShell/
# FUNCTION DECLARATION START
function choose {
local v e default
v=$1
shift 2
default=$1
shift 2
i=1
for e in "$@"
do
echo "$i) $e"
let i=i+1
done
echo -ne "\t> "
if [[ $default ]]; then xdotool type $default; fi
read REPLY
case $REPLY in
'') eval $v="";;
[1-9]*) eval $v="\$$REPLY";;
*) eval $v="$REPLY";;
esac
}
function readProperty {
local file property resultvar result
property=$1
file=$3
resultvar=$5
result=$(cat "$file" | grep -v "#" | grep "^$property" | tail -n 1 | cut -d "=" -f2-)
if [[ $resultvar ]]; then eval $resultvar="$result"; else echo "$result"; fi
}
# FUNCTION DECLARATION END
# HELP START
if [ "$1" == "--help" ] || [ "$1" == "-h" ]
then
echo -e """
This script by HashtagShell allows you to conveniently modify
mod versions stored in a java properties file from commandline.
Usage: version --help
version <file>
version --cmdmode <file> <releasetype=0> <version> <build>
version --get <file> <property>
file Specifies the file that properties will be
read from.
If left empty, the \"build.properties\" file
in the working directory will be used.
-h --help Prints this help information.
--cmdmode Disabled user input prompts and get the info
from commandline in this order
--get print a property from file to stdout.
When the script is run, the user can choose the different
important versions of the mod (releasetype, version, build).
Only java-style properties are supported.
For questions where the user can select an option, both the
entry's number or the the string itself will be accepted.
For questions where no options are given, the input string
will be used, and no checks will be performed.
If an answer is left empty, the value will be left unchanged.
This \"unchanged\" value will be displayed in (parentheses)
after every question.
These are the property names, followed by a recommended value
regex and example.
Properties:
releasetype alpha|beta|release \"release\"
version ([.]*\d+[.]*)+ \"3.10.12\"
build \d+ \"125\"
Although these are recommendations only, that's how modders
tend to do stuff.
If the build number is shorter than three digits, then the
appropriate number of zeros will be prefixed to it. If it's
three or more digits long, no changes will be made.
"""
exit
fi
# HELP END
# CMDMODE START
if [ "$1" == "--cmdmode" ]
then
shift 1
file=$1
#releasetype=$2
version=$3
build=$4
#oldreleasetype=`readProperty releasetype from $file`
oldversion=`readProperty version from $file`
oldbuild=`readProperty build from $file`
#sed -i "s%releasetype=$oldreleasetype%releasetype=$releasetype%" $file
sed -i "s%version=$oldversion%version=$version%" $file
sed -i "s%build=$oldbuild%build=$build%" $file
echo "Saved values \"$version-build$build\" to \"$file\""
#echo "Saved values \"$releasetype-$version-build$build\" to \"$file\""
exit
fi
# CMDMODE END
# GET START
if [ "$1" == "--get" ]
then
shift 1
printf "%s" "$(readProperty $2 from $1)"
exit
fi
# GET END
# PROPERTY DECLARATION START
filename=$(if [[ $1 && -f $1 ]]; then echo "$1"; else echo "build.properties"; fi)
#oldreleasetype=`readProperty releasetype from $filename`
oldversion=`readProperty version from $filename`
oldbuild=`readProperty build from $filename`
#releasetype=$oldreleasetype
version=$oldversion
build=$oldbuild
# PROPERTY DECLARATION END
# QUESTIONS START
# QUESTION 1 RELEASETYPE BLOCK
#clear
#echo "What shall the releasetype be? ($releasetype)"
#echo "Leave empty to keep unchanged"
#echo
#choose selectvar with "" in "alpha" "beta" "release"
# if [[ "$selectvar" ]]; then releasetype="$selectvar"; fi
# QUESTION 2 VERSION BLOCK
clear
echo "What shall the version be? ($version)"
echo
echo -ne "\t> "
read -p "" readvar
if [[ $readvar ]]; then version=$readvar; fi
# QUESTION 3 BUILD BLOCK
clear
echo "What shall the build number be? ($build)"
echo
echo -ne "\t> "
read -p "" readvar
if [[ $readvar ]]; then if [ $(expr 3 - ${#readvar}) -gt 0 ]; then build=$(printf '0%.0s' $(seq 1 $(expr 4 - ${#readvar})))${readvar}; else build=${readvar}; fi; fi
# QUESTIONS END
# INFORMATION START
# INFO SELECTION BLOCK
clear
echo "Your Selection:"
echo -e "\t> $version-build$build"
#echo -e "\t> $releasetype-$version-build$build"
echo
echo "Do you want to save to file? ($filename)"
echo
choose selectvar with 1 in "Yes" "No";
if [ "$selectvar" == "Yes" ] || [ "$selectvar" == "yes" ] || [ "$selectvar" == "Y" ] || [ "$selectvar" == "y" ] || ! [[ $selectvar ]]
then
# sed -i "s%releasetype=$oldreleasetype%releasetype=$releasetype%" $filename
sed -i "s%version=$oldversion%version=$version%" $filename
sed -i "s%build=$oldbuild%build=$build%" $filename
clear
echo
echo "Saved values \"$version-build$build\" to \"$filename\""
# echo "Saved values \"$releasetype-$version-build$build\" to \"$filename\""
echo
exit
fi
clear
echo
echo "Discarded values \"$version-build$build\""
#echo "Discarded values \"$releasetype-$version-build$build\""
echo
exit
# INFORMATION END
#####
# EOF START
# @name Mod versions
# @file version
# @author HashtagShell
# @depends xdotool
# EOF END
#####