1#!/bin/bash
2
3# script to push new prebuilt kernel from cros builder
4
5show_usage()
6{
7	echo usage: $0 [artifact_path] [rootdir] [kernel_path]
8	echo For: echo Artifacts[smaug]: smaug-release/R45-7199.0.0
9	echo artifact_path=smaug-release/R45-7199.0.0
10	echo If kernel comes from nvidia-kernel:
11	echo kernel_path=src/partner_private/nvidia-kernel
12	exit 1
13}
14
15artifact_path=$1
16TOP="$2"
17if [ -z "$TOP" ]; then
18	TOP="$(pwd)"
19fi
20kernel_path="$3"
21if [ -z "$kernel_path" ]; then
22	kernel_path="src/third_party/kernel/v3.18"
23fi
24
25gsbase=gs://chromeos-image-archive
26# smaug-release - works well
27# smaug-canary - works well - old, no longer works
28# smaug-paladin - potentially has kernel changes that are not upstream
29# trybot-smaug-paladin - works well with: cbuildbot --remote smaug-paladin
30build=smaug-release
31built_kernel="$TOP/device/google/dragon-kernel"
32kernel="$TOP/kernel/private/dragon"
33preamble="dragon: Update prebuilt kernel to"
34
35if [ ! -d "$built_kernel" ]; then
36	echo ERROR: missing prebuilt directory $built_kernel
37	show_usage
38fi
39
40if [ ! -d "$kernel" ]; then
41	echo ERROR: missing kernel directory $kernel
42	show_usage
43fi
44
45if [ -z "$artifact_path" ]; then
46	latest=$(gsutil.py cat ${gsbase}/${build}/LATEST-master)
47	if [ $? -ne 0 ]; then
48		echo ERROR: could not determine artifact_path
49		exit 1
50	fi
51	artifact_path=${build}/${latest}
52fi
53gspath=${gsbase}/${artifact_path}
54
55echo promoting kernel from $gspath
56
57cd "$built_kernel"
58gsutil.py cat ${gspath}/stripped-packages.tar | bsdtar -s '/.*kernel.*tbz2/kernel.tbz2/' -x -f - '*kernel*'
59if [ $? -ne 0 ]; then
60	echo ERROR: could not retrieve stripped-packages
61	exit 1
62fi
63bsdtar -s '/.*vmlinuz-3.18.*/Image.fit/' -jxf kernel.tbz2 '*vmlinuz-3.18*'
64rm kernel.tbz2
65newrev=$(gsutil.py cat ${gspath}/manifest.xml | grep "path=\"${kernel_path}\"" | sed -e 's/.*revision="\([0123456789abcdef]\+\).*/\1/')
66oldrev=$(git log --oneline | head -1 | sed -e "s/.*${preamble} \(.*\)/\1/")
67
68cd "$kernel"
69git remote update
70commitmsg=$(mktemp /tmp/msg.XXXXXX)
71cat >>$commitmsg <<EOD
72$preamble $newrev
73
74Build: $artifact_path
75
76Changes include:
77EOD
78git log --graph --oneline $oldrev..$newrev >> $commitmsg
79
80cd "$built_kernel"
81git add Image.fit
82git commit -t $commitmsg
83rm $commitmsg
84