summaryrefslogtreecommitdiffstats
path: root/release.sh
blob: a711d7f5771e19b5a7aff72ba7527e843e6bc735 (plain)
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/bin/sh
#
# Copyright (C) 2011 Denis 'GNUtoo' Carikli <GNUtoo@no-log.org>
# Copyright (C) 2011-2015 Paul Kocialkowski <contact@paulk.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# Variables
SCRIPT=$0
REPLICANT_DIR=$1
RELEASE_DIR=$2
RELEASE_TYPE=$3

ARGS_COUNT=2
REPO="../tools/repo"
RELEASE_TOOLS_DIR="$REPLICANT_DIR/out/host/linux-x86/bin"
RELEASE_TOOLS="adb fastboot heimdall mkbootimg"
RELEASE_SDK_DIR="$REPLICANT_DIR/out/host/linux-x86/sdk"
RELEASE_SDK="replicant-sdk_linux-x86.zip"
RELEASE_IMAGES_DIR="$REPLICANT_DIR/out/target/product"
RELEASE_IMAGES="recovery.img replicant-4.2-crespo.zip replicant-4.2-galaxysmtd.zip replicant-4.2-i9100.zip replicant-4.2-n7000.zip replicant-4.2-maguro.zip replicant-4.2-p3100.zip replicant-4.2-p3110.zip replicant-4.2-p5100.zip replicant-4.2-p5110.zip replicant-4.2-i9300.zip replicant-4.2-n7100.zip replicant-4.2-gta04.zip bootable.zip replicant_gta04_install.sh"
RELEASE_DEVICES="crespo galaxysmtd i9100 n7000 maguro p3100 p3110 p5100 p5110 i9300 n7100 gta04"
RELEASE_SCRIPTS_DIR=$( dirname "$SCRIPT" )
RELEASE_SCRIPTS="release.sh releasediff.sh releasetag.sh"
RELEASE_SECURITY_DIR="$REPLICANT_DIR/vendor/replicant-security"
RELEASE_SECURITY="media.x509.pem platform.x509.pem shared.x509.pem system.x509.pem"
RELEASE_KEY="4A80EB23"

METADATA="$RELEASE_DIR/metadata"
SECURITY="$RELEASE_DIR/security"
SCRIPTS="$RELEASE_DIR/scripts"
TOOLS="$RELEASE_DIR/tools"
IMAGES="$RELEASE_DIR/images"
SDK="$RELEASE_DIR/sdk"

VERSION="4.2"
RELEASE="0004"

release_signatures_tools () {
	if ! [ -d "$TOOLS" ]
	then
		return
	fi

	dir=$( pwd )

	cd "$TOOLS"
	for tool in $RELEASE_TOOLS
	do
		gpg --default-key "$RELEASE_KEY" --armor --output "$tool.asc" --detach-sign "$tool"
	done
	cd "$dir"
}

release_signatures_sdk () {
	if ! [ -d "$SDK" ]
	then
		return
	fi

	dir=$( pwd )

	cd "$SDK"
	for sdk in $RELEASE_SDK
	do
		gpg --default-key "$RELEASE_KEY" --armor --output "$sdk.asc" --detach-sign "$sdk"
	done
	cd "$dir"
}

release_signatures_images () {
	if ! [ -d "$IMAGES" ]
	then
		return
	fi

	cd "$IMAGES"
	for device in $RELEASE_DEVICES
	do
		if ! [ -d "$IMAGES/$device" ]
		then
			continue
		fi

		for image in $RELEASE_IMAGES
		do
			if [ -f "$IMAGES/$device/$image" ]
			then
				gpg --default-key "$RELEASE_KEY" --armor --output "$IMAGES/$device/$image.asc" --detach-sign "$IMAGES/$device/$image"
			fi
		done
	done
}

release_signatures () {
	echo "Releasing signatures"

	release_signatures_tools
	release_signatures_sdk
	release_signatures_images

	mkdir -p "$SECURITY"
	gpg --armor --output "$SECURITY/$RELEASE_KEY.asc" --export "$RELEASE_KEY"

	dir=$( pwd )

	cd "$SECURITY"
	rm "security.sha256"
	sha256sum * > "security.sha256"
	cd "$dir"
}

release_images () {
	echo "Releasing images"
	mkdir -p "$IMAGES"

	for device in $RELEASE_DEVICES
	do
		echo "Releasing images for $device"
		mkdir -p "$IMAGES/$device"

		for image in $RELEASE_IMAGES
		do
			if [ -f "$RELEASE_IMAGES_DIR/$device/$image" ]
			then
				cp "$RELEASE_IMAGES_DIR/$device/$image" "$IMAGES/$device/"
			fi
		done

		dir=$( pwd )

		cd "$IMAGES/$device"
		sha256sum * > "$device.sha256"
		cd "$dir"
	done
}

release_sdk () {
	echo "Releasing sdk"
	mkdir -p "$SDK"

	for sdk in $RELEASE_SDK
	do
		cp "$RELEASE_SDK_DIR/$sdk" "$SDK/"
	done

	dir=$( pwd )

	cd "$SDK"
	sha256sum * > "sdk.sha256"
	cd "$dir"
}

release_tools () {
	echo "Releasing tools"
	mkdir -p "$TOOLS"

	for tool in $RELEASE_TOOLS
	do
		cp "$RELEASE_TOOLS_DIR/$tool" "$TOOLS/"
	done

	dir=$( pwd )

	cd "$TOOLS"
	sha256sum * > "tools.sha256"
	cd "$dir"
}

release_scripts () {
	echo "Releasing scripts"
	mkdir -p "$SCRIPTS"

	for script in $RELEASE_SCRIPTS
	do
		cp "$RELEASE_SCRIPTS_DIR/$script" "$SCRIPTS/"
	done
}

release_security () {
	echo "Releasing security"
	mkdir -p "$SECURITY"

	for security in $RELEASE_SECURITY
	do
		cp "$RELEASE_SECURITY_DIR/$security" "$SECURITY/"
	done

	dir=$( pwd )

	cd "$SECURITY"
	sha256sum * > "security.sha256"
	cd "$dir"
}

release_metadata_about () {
	cat "$REPLICANT_DIR/vendor/replicant/README.mkdn" | awk "/^Replicant$/{replicant=1} /^CyanogenMod$/{replicant=0} replicant" > "$METADATA/readme.txt"
}

release_metadata_date () {
	date "+%Y-%m-%d" > "$METADATA/date.txt"
}

release_metadata_changelog () {
	cat "$REPLICANT_DIR/vendor/replicant/CHANGELOG.mkdn" | awk "/### .*/{n++} n==1, /### .*/ {n++} n==2" > "$METADATA/changelog.txt"
}

release_metadata_release () {
	echo "replicant-$VERSION-$RELEASE" > "$METADATA/release.txt"
}

release_metadata_prebuilt () {
	dir=$( pwd )

	cd "$REPLICANT_DIR/vendor/replicant/prebuilt/common/apps/"
	sha256sum *.apk > "$METADATA/prebuilt.sha256"
	cd "$dir"
}

release_metadata_git () {
	dir=$( pwd )
	cd "$REPLICANT_DIR"

	for git_repo in ".repo/manifests"
	do
		cd $git_repo
		echo "manifest"
		git show --format=oneline -s "replicant-$VERSION-$RELEASE" 2>/dev/null || git show --format=oneline -s
		echo ""
		cd "$REPLICANT_DIR"
		
	done > "$METADATA/git-tags.txt"

	$REPO list | while read git_repo
	do
		cd $git_repo
		echo "$git_repo" | sed "s/ : .*$/ /g"
		git show --format=oneline -s "replicant-$VERSION-$RELEASE" 2>/dev/null || git show --format=oneline -s
		echo ""
		cd "$REPLICANT_DIR"
	done >> "$METADATA/git-tags.txt"

	$REPO manifest -r > "$METADATA/manifest.xml"

	cd "$dir"
}

release_metadata_sdk() {
	echo "Releasing metadata"
	mkdir -p "$METADATA"
	release_metadata_git
	release_metadata_prebuilt
	release_metadata_release
	release_metadata_date
	release_metadata_about
}

release_metadata () {
	echo "Releasing metadata"
	mkdir -p "$METADATA"
	release_metadata_git
	release_metadata_prebuilt
	release_metadata_release
	release_metadata_changelog
	release_metadata_date
	release_metadata_about
}

print_help () {
	echo "$SCRIPT: [REPLICANT_DIR] [RELEASE_DIR] (RELEASE_TYPE)"
}

# Check for the correct number of args
if [ "$#"  -lt "$ARGS_COUNT" ]
then
	print_help
	exit 1
fi

case "$RELEASE_TYPE" in
	"signatures")
		release_signatures
		;;
	"sdk")
		release_metadata_sdk
		release_scripts
		release_sdk
		;;
	*)
		release_metadata
		release_security
		release_scripts
		release_tools
		release_images
		;;
esac