Roman Kiryanov | 17cde29 | 2020-03-16 17:51:29 -0700 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Examples: |
| 4 | # to update |
| 5 | # * modules only: |
| 6 | # ./update_54_kernel.sh --bug 123 --goldfish_bid 6300759 |
| 7 | # * the kernel file only (from common): |
| 8 | # ./update_54_kernel.sh --bug 123 --kernel common --common_bid 6299923 |
| 9 | # * modules and the kernel file (from common or goldfish): |
| 10 | # ./update_54_kernel.sh --bug 123 --kernel common --goldfish_bid 6300759 --common_bid 6299923 |
| 11 | # ./update_54_kernel.sh --bug 123 --kernel goldfish --goldfish_bid 6300759 --common_bid 6299923 |
| 12 | |
| 13 | set -e |
| 14 | set -o errexit |
| 15 | source gbash.sh |
| 16 | |
| 17 | DEFINE_int bug 0 "Bug with the reason for the update" |
| 18 | DEFINE_int goldfish_bid 0 "Build id for goldfish modules" |
| 19 | DEFINE_string kernel "none" "Choose where you want to fetch the kernel from, (common|goldfish|none)" |
| 20 | DEFINE_int common_bid 0 "Build id for the kernel binary (common)" |
| 21 | DEFINE_string goldfish_branch "aosp_kernel-r-goldfish-android-5.4" "'fetch_artifact branch' for goldfish modules" |
| 22 | DEFINE_string common_branch "aosp_kernel-common-android-5.4" "'fetch_artifact branch' for tke kernel binary" |
| 23 | |
| 24 | fetch_arch() { |
| 25 | scratch_dir="${1}" |
| 26 | kernel_bid="${2}" |
| 27 | kernel_branch="${3}" |
| 28 | goldfish_bid="${4}" |
| 29 | goldfish_branch="${5}" |
| 30 | kernel_target="${6}" |
| 31 | kernel_artifact="${7}" |
| 32 | |
| 33 | mkdir "${scratch_dir}" |
| 34 | pushd "${scratch_dir}" |
| 35 | |
| 36 | if [[ "${kernel_bid}" -ne 0 ]]; then |
| 37 | /google/data/ro/projects/android/fetch_artifact \ |
| 38 | --bid "${kernel_bid}" \ |
| 39 | --target "${kernel_target}" \ |
| 40 | --branch "${kernel_branch}" \ |
| 41 | "${kernel_artifact}" |
| 42 | fi |
| 43 | |
| 44 | if [[ "${goldfish_bid}" -ne 0 ]]; then |
| 45 | /google/data/ro/projects/android/fetch_artifact \ |
| 46 | --bid "${goldfish_bid}" \ |
| 47 | --target "${kernel_target}" \ |
| 48 | --branch "${goldfish_branch}" \ |
| 49 | "*.ko" |
| 50 | fi |
| 51 | |
| 52 | popd |
| 53 | } |
| 54 | |
| 55 | move_artifacts() { |
| 56 | scratch_dir="${1}" |
| 57 | dst_dir="${2}" |
| 58 | kernel_artifact="${3}" |
| 59 | goldfish_bid="${4}" |
| 60 | |
| 61 | pushd "${scratch_dir}" |
| 62 | |
| 63 | if [[ -f "${kernel_artifact}" ]]; then |
| 64 | mv "${kernel_artifact}" "${dst_dir}/kernel-qemu2" |
| 65 | fi |
| 66 | |
| 67 | if [[ "${goldfish_bid}" -ne 0 ]]; then |
| 68 | rm -rf "${dst_dir}/ko-new" |
| 69 | rm -rf "${dst_dir}/ko-old" |
| 70 | mkdir "${dst_dir}/ko-new" |
| 71 | mv *.ko "${dst_dir}/ko-new" |
| 72 | mv "${dst_dir}/ko" "${dst_dir}/ko-old" |
| 73 | mv "${dst_dir}/ko-new" "${dst_dir}/ko" |
| 74 | rm -rf "${dst_dir}/ko-old" |
| 75 | fi |
| 76 | |
| 77 | popd |
| 78 | } |
| 79 | |
| 80 | main() { |
| 81 | fail=0 |
| 82 | |
| 83 | if [[ "${FLAGS_bug}" -eq 0 ]]; then |
| 84 | echo Must specify --bug 1>&2 |
| 85 | fail=1 |
| 86 | fi |
| 87 | |
| 88 | kernel_bid="0" |
| 89 | kernel_branch="empty" |
| 90 | case "${FLAGS_kernel}" in |
| 91 | common) |
| 92 | if [[ "${FLAGS_common_bid}" -eq 0 ]]; then |
| 93 | echo Must specify --common_bid 1>&2 |
| 94 | fail=1 |
| 95 | else |
| 96 | kernel_bid=${FLAGS_common_bid} |
| 97 | kernel_branch=${FLAGS_common_branch} |
| 98 | fi |
| 99 | ;; |
| 100 | goldfish) |
| 101 | if [[ "${FLAGS_goldfish_bid}" -eq 0 ]]; then |
| 102 | echo Must specify --goldfish_bid 1>&2 |
| 103 | fail=1 |
| 104 | else |
| 105 | kernel_bid=${FLAGS_goldfish_bid} |
| 106 | kernel_branch=${FLAGS_goldfish_branch} |
| 107 | fi |
| 108 | ;; |
| 109 | *) |
| 110 | ;; |
| 111 | esac |
| 112 | |
| 113 | if [[ "${fail}" -ne 0 ]]; then |
| 114 | exit "${fail}" |
| 115 | fi |
| 116 | |
| 117 | here="$(pwd)" |
| 118 | x86_dst_dir="${here}/x86_64/5.4" |
| 119 | arm_dst_dir="${here}/arm64/5.4" |
| 120 | |
| 121 | scratch_dir="$(mktemp -d)" |
| 122 | x86_scratch_dir="${scratch_dir}/x86" |
| 123 | arm_scratch_dir="${scratch_dir}/arm" |
| 124 | |
| 125 | fetch_arch "${x86_scratch_dir}" \ |
| 126 | "${kernel_bid}" "${kernel_branch}" \ |
| 127 | "${FLAGS_goldfish_bid}" "${FLAGS_goldfish_branch}" \ |
| 128 | "kernel_x86_64" "bzImage" |
| 129 | |
| 130 | # fetch_arch "${arm_scratch_dir}" \ |
| 131 | # "${kernel_bid}" "${kernel_branch}" \ |
| 132 | # "${FLAGS_goldfish_bid}" "${FLAGS_goldfish_branch}" \ |
| 133 | # "kernel_aarch64" "Image.gz" |
| 134 | |
| 135 | move_artifacts "${x86_scratch_dir}" "${x86_dst_dir}" "bzImage" "${FLAGS_goldfish_bid}" |
| 136 | # move_artifacts "${arm_scratch_dir}" "${arm_dst_dir}" "Image.gz" "${FLAGS_goldfish_bid}" |
| 137 | |
| 138 | git add "${x86_dst_dir}" |
| 139 | # git add "${arm_dst_dir}" |
| 140 | |
| 141 | if [[ "${FLAGS_goldfish_bid}" -ne 0 ]]; then |
| 142 | git commit -a -m "$( |
| 143 | echo Update kernel modules to ${FLAGS_goldfish_bid} |
| 144 | echo |
| 145 | echo kernel: ${kernel_branch}/${kernel_bid} |
| 146 | echo modules: $FLAGS_goldfish_branch/$FLAGS_goldfish_bid |
| 147 | echo |
| 148 | echo Test: TreeHugger |
| 149 | echo "Bug: ${FLAGS_bug}" |
| 150 | )" |
| 151 | else |
| 152 | git commit -a -m "$( |
| 153 | echo Update kernel to ${kernel_bid} |
| 154 | echo |
| 155 | echo kernel: ${kernel_branch}/${kernel_bid} |
| 156 | echo |
| 157 | echo Test: TreeHugger |
| 158 | echo "Bug: ${FLAGS_bug}" |
| 159 | )" |
| 160 | fi |
| 161 | |
| 162 | git commit --amend -s |
| 163 | } |
| 164 | |
| 165 | gbash::main "$@" |
| 166 | |