-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackage.sh
More file actions
executable file
·211 lines (179 loc) · 4.68 KB
/
Copy pathpackage.sh
File metadata and controls
executable file
·211 lines (179 loc) · 4.68 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
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
#!/bin/bash
# colors
NC=`tput sgr0`
BCyan=$'\033[1;36m'
BRed=$'\033[1;31m'
BGreen=$'\033[1;32m'
White=$'\033[0;37m'
vFlag=false
sFlag=false
answer=n
version=
OWNER="2mt-software-solutions"
REPO="minetest-tinker"
MODNAME="twomt_tinker"
function status_error() {
printf " ${BRed}%5s${NC}\n" "ERROR"
exit 1
}
function status_ok() {
if ! $sFlag
then
printf " ${BGreen}%5s${NC}\n" "OK"
fi
}
function status_notice() {
if ! $sFlag
then
MSG="$1"
printf "${BCyan}%5s${NC}\n" "$MSG"
fi
}
function status_msg() {
if ! $sFlag
then
MSG="$1"
printf "${BCyan}%-40.40s${NC}" "$MSG"
fi
}
function help()
{
printf "Usage:\n${BCyan}$0${NC} -v [x.y.z]${NC}\n"
printf "\n"
printf "OPTIONS:\n"
printf " -h ${BWhite}help${NC} : Show this message\n"
printf " -s ${BWhite}silent${NC} : No output except on errors\n"
printf " -y ${BWhite}confirm${NC} : Don't ask for confirmation\n"
printf " -v ${BWhite}version${NC} : Version/Tag to build\n"
printf "\n"
}
options=':hysv:'
while getopts $options option
do
case $option in
v ) vFlag=true; version=$OPTARG;;
s ) sFlag=true; answer=y;;
y ) answer=y;;
h ) help; exit;;
\? ) printf "${BCyan}Unknown option:${White} -$OPTARG${NC}\n\n"; exit 1;;
: ) printf "${BCyan}Missing option argument for${White} -$OPTARG${NC}\n\n"; exit 1;;
* ) printf "${BCyan}Unimplemented option:${White} -$OPTARG${NC}\n\n"; exit 1;;
esac
done
# Head
if ! $sFlag
then
printf "\n"
printf "********** ${BCyan}2mt.ModPacker (minetest)${NC} **********\n"
printf "\n"
fi
shift $(($OPTIND - 1))
# grab latest tag from git on no user input
if ! $vFlag
then
#get highest tag number
latest=`git describe --abbrev=0 --tags`
bits=(${latest//./ })
major=${bits[0]}
minor=${bits[1]}
build=${bits[2]}
#create new tag
version="${major}.${minor}.${build}"
else
bits=(${version//./ })
major=${bits[0]}
minor=${bits[1]}
build=${bits[2]}
fi
# everything fine, continue
# version
if ! $sFlag
then
printf "${BCyan}%-12.12s${NC}" "Version:"
printf " ${White}%33s${NC}\n" "${version}"
fi
# shall we begin?
if [ ${answer} = "n" ]
then
printf "\n"
read -t 5 -n 1 -p $"${BCyan}Start packaging? ${NC}(y/n): " answer
[ -z "$answer" ] && answer="n"
fi
if [ ! $answer = "y" ]; then
printf "\n\n${BCyan}Build aborted!${NC}\n\n"
exit 1;
fi
# let me do my work plz!
stty -echo
SECONDS=0
if ! $sFlag
then
printf "\n${BCyan}Build starting...${NC}\n\n"
fi
# good to go, let's build
status_msg "Create build directories"
if [[ ! -e build ]]; then
mkdir build || status_error
fi
rm -rf build/* || status_error
status_ok
cd build
status_msg "Create version.txt"
echo "${version}" >> version.txt || status_error
status_ok
status_msg "Copy sources"
cp -r ../src/* . || status_error
status_ok
status_msg "Package everything together"
RELEASE_FILE="${MODNAME}-${version}.tgz"
tar -czf "../${RELEASE_FILE}" . || status_error
status_ok
# build => .
cd ..
# let's push it to github
# @see: https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
# Define variables.
GH_API="https://api.github.com"
GH_REPO="$GH_API/repos/${OWNER}/${REPO}"
GH_TAGS="$GH_REPO/releases/tags/${version}"
GH_RELEASES="$GH_REPO/releases"
AUTH="Authorization: token ${DEPLOYTOKEN}"
WGET_ARGS="--content-disposition --auth-no-challenge --no-cookie"
API_PAYLOAD=$(printf '{"tag_name": "%s","target_commitish": "master","name": "%s","body": "Release of version %s","draft": false,"prerelease": false}' ${version} ${version} ${version})
# Validate token.
status_msg "Validate access token"
curl -o /dev/null -sH "$AUTH" ${GH_REPO} || status_error
status_ok
# publish a new release
status_msg "Publish new release"
response=$(curl -sH "${AUTH}" --data "${API_PAYLOAD}" "${GH_RELEASES}")
# Get ID of the release.
eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
[ "$id" ] || {
# looks like it may already exists, let's check
response=$(curl -sH "${AUTH}" "${GH_TAGS}")
eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
[ "$id" ] || {
status_error
}
}
status_ok
status_msg "Upload ${RELEASE_FILE}"
GH_ASSET="https://uploads.github.com/repos/${OWNER}/${REPO}/releases/$id/assets?name=${RELEASE_FILE}"
response=$(curl -s --data-binary @"${RELEASE_FILE}" -H "${AUTH}" -H "Content-Type: application/octet-stream" "$GH_ASSET")
eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
[ "$id" ] || {
status_error
}
status_ok
# finished
duration=$SECONDS
if ! $sFlag
then
printf "\n"
printf "${BCyan}Build ${BGreen}finished${NC}\n"
printf "${BCyan}Duration: ${White}${duration} seconds${NC}\n"
printf "\n"
fi
# okay, I'm done!
stty echo