Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mass patch Android kernels on rom projects that use Gerrit
#!/bin/bash -x
set -o errexit
projectprefix="CyanogenMod_"
gerrit="review.cyanogenmod.org"
branch="cm-11.0"
# projectprefix="OmniROM_"
# gerrit="gerrit.omnirom.org"
# branch="android-4.4"
# projectprefix="NamelessRom_"
# gerrit="gerrit.nameless-rom.org"
# branch="android-4.4"
# projectprefix="AICP_"
# gerrit="gerrit.aicp-rom.com"
# branch="kitkat"
# projectprefix="AOSPA_"
# gerrit="gerrit.paranoidandroid.co"
# branch="lollipop"
# projectprefix="CarbonDev_"
# gerrit="review.carbonrom.org"
# branch="kk"
# projectprefix="SlimRoms_"
# gerrit="gerrit.slimroms.net"
# branch="lp5.0"
username="FrozenCow"
cherries=(680ff7911e5d0701e81cd0d0d5235b300ce44a86)
patchname="gadget_cdrom"
changeid="Idf83c74815b1ad370428ab9d3e5503d5f7bcd3b6"
topic="DriveDroid"
if [ -n "$(git status --porcelain)" ]; then
echo "There are uncommitted changes in the repository: cancel"
exit 1
fi
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
# Retrieve all kernel projects
projects=($(ssh -p 29418 ${username}@${gerrit} gerrit ls-projects | grep kernel_))
#projects=(CyanogenMod/android_kernel_acer_t20-common CyanogenMod/android_kernel_acer_t30 CyanogenMod/android_kernel_amazon_bowser-common CyanogenMod/android_kernel_amazon_otter-common CyanogenMod/android_kernel_asus_grouper CyanogenMod/android_kernel_asus_tf101 CyanogenMod/android_kernel_asus_tf201 CyanogenMod/android_kernel_asus_tf300t CyanogenMod/android_kernel_asus_tf700t CyanogenMod/android_kernel_asus_tf701t CyanogenMod/android_kernel_bn_acclaim CyanogenMod/android_kernel_bn_encore CyanogenMod/android_kernel_bn_omap CyanogenMod/android_kernel_goldfish CyanogenMod/android_kernel_google_msm CyanogenMod/android_kernel_google_steelhead CyanogenMod/android_kernel_htc_endeavoru CyanogenMod/android_kernel_htc_enrc2b CyanogenMod/android_kernel_htc_m7 CyanogenMod/android_kernel_htc_msm8660 CyanogenMod/android_kernel_htc_msm8960 CyanogenMod/android_kernel_htc_msm8974 CyanogenMod/android_kernel_lge_dory CyanogenMod/android_kernel_lge_g3 CyanogenMod/android_kernel_lge_hammerhead CyanogenMod/android_kernel_lge_ls970 CyanogenMod/android_kernel_lge_msm8974 CyanogenMod/android_kernel_lge_v500 CyanogenMod/android_kernel_lge_v909 CyanogenMod/android_kernel_motorola_ghost CyanogenMod/android_kernel_motorola_msm8226 CyanogenMod/android_kernel_motorola_msm8960-common CyanogenMod/android_kernel_motorola_msm8960dt-common CyanogenMod/android_kernel_motorola_omap4-common CyanogenMod/android_kernel_motorola_omap4-kexec-common CyanogenMod/android_kernel_oneplus_msm8974 CyanogenMod/android_kernel_oppo_find5 CyanogenMod/android_kernel_oppo_n1 CyanogenMod/android_kernel_samsung_aries CyanogenMod/android_kernel_samsung_crespo CyanogenMod/android_kernel_samsung_d2 CyanogenMod/android_kernel_samsung_epicmtd CyanogenMod/android_kernel_samsung_espresso10 CyanogenMod/android_kernel_samsung_exynos5410 CyanogenMod/android_kernel_samsung_exynos5420 CyanogenMod/android_kernel_samsung_galaxytab-cdma CyanogenMod/android_kernel_samsung_hlte CyanogenMod/android_kernel_samsung_jf CyanogenMod/android_kernel_samsung_klte CyanogenMod/android_kernel_samsung_ks01lte CyanogenMod/android_kernel_samsung_manta CyanogenMod/android_kernel_samsung_mondrianwifi CyanogenMod/android_kernel_samsung_msm8660-common CyanogenMod/android_kernel_samsung_msm8660-q1 CyanogenMod/android_kernel_samsung_msm8930-common CyanogenMod/android_kernel_samsung_n1 CyanogenMod/android_kernel_samsung_p1 CyanogenMod/android_kernel_samsung_p4 CyanogenMod/android_kernel_samsung_piranha CyanogenMod/android_kernel_samsung_smdk4210 CyanogenMod/android_kernel_samsung_smdk4412 CyanogenMod/android_kernel_samsung_t1 CyanogenMod/android_kernel_samsung_tuna CyanogenMod/android_kernel_samsung_victory CyanogenMod/android_kernel_sony_apq8064 CyanogenMod/android_kernel_sony_flamingo CyanogenMod/android_kernel_sony_mam7x27a-legacy CyanogenMod/android_kernel_sony_msm7x27a CyanogenMod/android_kernel_sony_msm7x27a-legacy CyanogenMod/android_kernel_sony_msm8660 CyanogenMod/android_kernel_sony_msm8930 CyanogenMod/android_kernel_sony_msm8960t CyanogenMod/android_kernel_sony_msm8974 CyanogenMod/android_kernel_sony_msm8974pro CyanogenMod/android_kernel_sony_msm8x27 CyanogenMod/android_kernel_sony_msm8x60 CyanogenMod/android_kernel_sony_tianchi CyanogenMod/android_kernel_toshiba_betelgeuse CyanogenMod/android_kernel_xiaomi_aries)
# Do not handle projects that are on the blacklist
blacklist_projects=()
#blacklist_projects=(CyanogenMod/android_kernel_{acer_t20-common,acer_t30,amazon_bowser-common,amazon_otter-common,samsung_msm8930-common,samsung_piranha,samsung_smdk4412,samsung_t1,samsung_tuna,sony_mam7x27a-legacy,sony_msm7x27a-legacy,sony_msm8660})
for project in ${blacklist_projects[@]}; do
projects=("${projects[@]/${project}}")
done
# Do not handle projects that already have $changeid submitted
changed_projects=($(curl -L -s "http://${gerrit}/changes/?q=change:${changeid}" | tail -n+2 | jq --raw-output '.[].project'))
for project in ${changed_projects[@]}; do
projects=("${projects[@]/${project}}")
done
for project in ${projects[@]}
do
# Make sure no '/' is used in the project name (ie CyanogenMod/android_kernel_lge_hammerhead).
# Also make sure the name is prefixed with $projectprefix if it didn't already have the prefix.
projectname="${project//\//_}"
projectname="${projectname#$projectprefix}"
projectname="${projectprefix}${projectname}"
echo "$project -> $projectname"
git remote add ${projectname} http://${gerrit}/${project} 2> /dev/null || true
if ! git fetch ${projectname}; then
echo "Failed to fetch ${projectname}: cancel"
continue
fi
if ! git show-ref --quiet remotes/${projectname}/${branch} > /dev/null 2>&1; then
echo "Branch ${branch} not found for ${project}: cancel"
continue
fi
if [ "$(git --no-pager log --quiet --grep="Change-Id: ${changeid}" --oneline ${projectname}/${branch})" != "" ]; then
echo "Already patched ${projectname}/${branch}: cancel"
continue
fi
git branch -D ${projectname}_${branch}_${patchname} > /dev/null 2>&1 || true
git branch ${projectname}_${branch}_${patchname} ${projectname}/${branch} > /dev/null 2>&1 || true
if ! git checkout ${projectname}_${branch}_${patchname} > /dev/null 2>&1; then
echo "Failed to checkout to branch ${projectname}_${branch}_${patchname}: cancel"
continue
fi
cherry_applied=0
for cherry in ${cherries[@]}; do
if ! git cherry-pick "${cherry}" > /dev/null 2> /dev/null; then
echo "Failed to apply cherry ${cherry} on ${projectname}_${branch}_${patchname}: continue"
git cherry-pick --abort
continue
fi
cherry_applied=1
done
if [ "$cherry_applied" = "0" ]; then
echo "Failed to cherry-pick on ${projectname}_${branch}_${patchname}: cancel"
fi
echo "Success ${projectname}_${branch}_${patchname}"
git push ssh://${username}@${gerrit}:29418/${project} HEAD:refs/for/${branch}/${topic} || true
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.