├── README.md ├── tags.txt └── find_tags.sh /README.md: -------------------------------------------------------------------------------- 1 | # Script to find the base kernel tag for a kernel source 2 | 3 | Steps to use it 4 | 5 | 1. Download your devices kernel source with no edits from you. 6 | 2. Run the script, find_tags.sh, and tell it the root path of your kernel source 7 | and the tag regex you are targeting. 8 | 3. Wait for it to finish to tell you the best tag. [Optional] See the entire list 9 | of tags checked in file, tags.txt, which the script generates in the same path 10 | as where you run this script. 11 | 4. Enjoy. 12 | 13 | [Optional] 14 | 15 | The script offers support to run in parallel to speed up the process. This 16 | performance will vary upon your systems specs. See, ./find_tags.sh -h, for usage. 17 | -j|--jobs will default to running only 1 process unless otherwise specified. 18 | 19 | 20 | Some examples for the script, targeting device platform msm8998: 21 | 22 | ./find_tags.sh -t *89xx* -k /path/to/kernel 23 | 24 | ./find_tags.sh -t LA.UM.*89xx* -k /path/to/kernel 25 | 26 | ./find_tags.sh --kernel=/path/to/kernel --tags=LA.UM.*89xx* 27 | 28 | ./find_tags.sh -t *89xx* -k /path/to/kernel -j 4 29 | 30 | ./find_tags.sh --kernel=/path/to/kernel --tags=LA.UM.*89xx* --jobs=4 31 | 32 | 33 | NOTE: 34 | 35 | The script will verify if your tag regex returns true and is validated. 36 | If it returns false then the tag(s) you seek for do not exist and the script 37 | will abort giving you an error about your regex and to try again. It is 38 | the sole responsibility of the user to insure they know what tag(s) they 39 | seek for. 40 | -------------------------------------------------------------------------------- /tags.txt: -------------------------------------------------------------------------------- 1 | LA.BR.1.2.3-00310-8x09.0 2 | LA.BR.1.2.3-00710-8x09.0 3 | LA.BR.1.2.3-00910-8x09.0 4 | LA.BR.1.2.3-01310-8x09.0 5 | LA.BR.1.2.3-01510-8x09.0 6 | LA.BR.1.2.3-02010-8x09.0 7 | LA.BR.1.2.3-02510-8x09.0 8 | LA.BR.1.2.3-02910-8x09.0 9 | LA.BR.1.2.3-03110-8x09.0 10 | LA.BR.1.2.3-03610-8x09.0 11 | LA.BR.1.2.3-04110-8x09.0 12 | LA.BR.1.2.3-04610-8x09.0 13 | LA.BR.1.2.3-04910-8x09.0 14 | LA.BR.1.2.3-05410-8x09.0 15 | LA.BR.1.2.3-05810-8x09.0 16 | LA.BR.1.2.3-06410-8x09.0 17 | LA.BR.1.2.3-06610-8x09.0 18 | LA.BR.1.2.3-07110-8x09.0 19 | LA.BR.1.2.3-07210-8x09.0 20 | LA.BR.1.2.3-07310-8x09.0 21 | LA.BR.1.2.3-07510-8x09.0 22 | LA.BR.1.2.3-07610-8x09.0 23 | LA.BR.1.2.3-07710-8x09.0 24 | LA.BR.1.2.3-07910-8x09.0 25 | LA.BR.1.2.3-08010-8x09.0 26 | LA.BR.1.2.3-08110-8x09.0 27 | LA.BR.1.2.3-08210-8x09.0 28 | LA.BR.1.2.3-08310-8x09.0 29 | LA.BR.1.2.3-08510-8x09.0 30 | LA.BR.1.2.3-08710-8x09.0 31 | LA.BR.1.2.3-08810-8x09.0 32 | LA.BR.1.2.3-09110-8x09.0 33 | LA.BR.1.2.3-09310-8x09.0 34 | LA.BR.1.2.3-09410-8x09.0 35 | LA.BR.1.2.3-09510-8x09.0 36 | LA.BR.1.2.3-09710-8x09.0 37 | LA.BR.1.2.3-09810-8x09.0 38 | LA.BR.1.2.3-09910-8x09.0 39 | LA.BR.1.2.3-10110-8x09.0 40 | LA.BR.1.2.3-10210-8x09.0 41 | LA.BR.1.2.3-10310-8x09.0 42 | LA.BR.1.2.3-10410-8x09.0 43 | LA.BR.1.2.3-10510-8x09.0 44 | LA.BR.1.2.3-10710-8x09.0 45 | LA.BR.1.2.3-10810-8x09.0 46 | LA.BR.1.2.3-11010-8x09.0 47 | LA.BR.1.2.3-11110-8x09.0 48 | LA.BR.1.2.3-11310-8x09.0 49 | LA.BR.1.2.3-11410-8x09.0 50 | LA.BR.1.2.3-11510-8x09.0 51 | LA.BR.1.2.3-11610-8x09.0 52 | LA.BR.1.2.3-11910-8x09.0 53 | LA.BR.1.2.3-12110-8x09.0 54 | LA.BR.1.2.3-12210-8x09.0 55 | LA.BR.1.2.3-12310-8x09.0 56 | LA.BR.1.2.3-12710-8x09.0 57 | LA.BR.1.2.3-12910-8x09.0 58 | LA.BR.1.2.3-13010-8x09.0 59 | LA.BR.1.2.3-13210-8x09.0 60 | LA.BR.1.2.3-13310-8x09.0 61 | LA.BR.1.2.3-13510-8x09.0 62 | LA.BR.1.2.3-13610-8x09.0 63 | LA.BR.1.2.3-13810-8x09.0 64 | LA.BR.1.2.3.c1-00300-8x09.0 65 | LA.BR.1.2.3.c2-02000-8x09.0 66 | LA.BR.1.2.3.c2-03700-8x09.0 67 | LA.BR.1.2.3.c2-04600-8x09.0 68 | LA.BR.1.2.3.c2-05300-8x09.0 69 | LA.BR.1.2.3.c2-05900-8x09.0 70 | LA.BR.1.2.3.c2-06800-8x09.0 71 | LA.BR.1.2.3.c2-08300-8x09.0 72 | LA.BR.1.2.3.c2-10600-8x09.0 73 | LA.BR.1.2.3.c3-00300-8x09.0 74 | LA.BR.1.2.3.c3-00600-8x09.0 75 | LA.BR.1.2.3.c3-00800-8x09.0 76 | LA.BR.1.2.3.c3-01200-8x09.0 77 | LA.BR.1.2.3.c3-01900-8x09.0 78 | LA.BR.1.2.3.c3-02200-8x09.0 79 | LA.BR.1.2.3.c3-02600-8x09.0 80 | LA.BR.1.2.3.c3-03000-8x09.0 81 | LA.BR.1.2.3.c3-03300-8x09.0 82 | LA.BR.1.2.3.c3-03600-8x09.0 83 | LA.BR.1.2.3.c3-03800-8x09.0 84 | LA.BR.1.2.3.c3-04400-8x09.0 85 | LA.BR.1.2.5-00200-8x09.0 86 | LA.BR.1.2.5-00220-8x09.0 87 | LA.BR.1.2.5-00400-8x09.0 88 | LA.BR.1.2.5-00500-8x09.0 89 | LA.BR.1.2.5-00620-8x09.0 90 | LA.BR.1.2.5-01020-8x09.0 91 | LA.BR.1.2.5-01420-8x09.0 92 | LA.BR.1.2.5-01520-8x09.0 93 | LA.BR.1.2.5-01720-8x09.0 94 | LA.BR.1.2.5-01820-8x09.0 95 | LA.BR.1.2.5-02000-8x09.0 96 | LA.BR.1.2.5-02220-8x09.0 97 | LA.BR.1.2.5-02420-8x09.0 98 | LA.BR.1.2.5-02520-8x09.0 99 | LA.BR.1.2.5-02620-8x09.0 100 | LA.BR.1.2.5-02720-8x09.0 101 | LA.BR.1.2.5-02820-8x09.0 102 | LA.BR.1.2.5-03020-8x09.0 103 | LA.BR.1.2.5-03420-8x09.0 104 | LA.BR.1.2.5-03500-8x09.0 105 | LA.BR.1.2.5-03520-8x09.0 106 | LA.BR.1.2.5-03620-8x09.0 107 | LA.BR.1.2.5-03720-8x09.0 108 | LA.BR.1.2.5-04020-8x09.0 109 | LA.BR.1.2.5-04220-8x09.0 110 | LA.BR.1.2.5-04320-8x09.0 111 | LA.BR.1.2.5-04520-8x09.0 112 | LA.BR.1.2.5-04920-8x09.0 113 | LA.BR.1.2.5-05020-8x09.0 114 | LA.BR.1.2.5-05120-8x09.0 115 | LA.BR.1.2.5-05820-8x09.0 116 | LA.BR.1.2.5-05900-8x09.0 117 | LA.BR.1.2.5-06320-8x09.0 118 | LA.BR.1.2.5-06420-8x09.0 119 | LA.BR.1.2.5-06820-8x09.0 120 | LA.BR.1.2.5-06920-8x09.0 121 | LA.BR.1.2.5-08300-8x09.0 122 | LA.BR.1.2.5-09200-8x09.0 123 | LA.BR.1.2.5-14100-8x09.0 124 | LA.BR.1.2.5.c1-01300-8x09.0 125 | LA.BR.1.2.6-00110-8x09.0 126 | LA.BR.1.2.6-00210-8x09.0 127 | LA.BR.1.2.6-00410-8x09.0 128 | LA.BR.1.2.6-00610-8x09.0 129 | LA.BR.1.2.6-00810-8x09.0 130 | LA.BR.1.2.6-00910-8x09.0 131 | LA.BR.1.2.6-01010-8x09.0 132 | LA.BR.1.2.6-01210-8x09.0 133 | LA.BR.1.2.6-01310-8x09.0 134 | LA.BR.1.2.6-01610-8x09.0 135 | LA.BR.1.2.6-01710-8x09.0 136 | LA.BR.1.2.6-01810-8x09.0 137 | LA.BR.1.2.6-01910-8x09.0 138 | LA.BR.1.2.6-02310-8x09.0 139 | LA.BR.1.2.6-02610-8x09.0 140 | LA.BR.1.2.6-02710-8x09.0 141 | LA.BR.1.2.6-02810-8x09.0 142 | LA.BR.1.2.6-02910-8x09.0 143 | LA.BR.1.2.6-03010-8x09.0 144 | LA.BR.1.2.6-03110-8x09.0 145 | LA.BR.1.2.6-03210-8x09.0 146 | LA.BR.1.2.6-03310-8x09.0 147 | LA.BR.1.2.6-03410-8x09.0 148 | LA.BR.1.2.6-03710-8x09.0 149 | LA.BR.1.2.6-03910-8x09.0 150 | LA.BR.1.2.6-04010-8x09.0 151 | LA.BR.1.2.6-04310-8x09.0 152 | LA.BR.1.2.6-04410-8x09.0 153 | LA.BR.1.2.6-04510-8x09.0 154 | LA.BR.1.2.6-04710-8x09.0 155 | LA.BR.1.2.6-04810-8x09.0 156 | LA.BR.1.2.6-04910-8x09.0 157 | LA.BR.1.2.6-05010-8x09.0 158 | LA.BR.1.2.6-05110-8x09.0 159 | LA.BR.1.2.6.c1-00400-8x09.0 160 | LA.BR.1.2.6.c1-00600-8x09.0 161 | LA.BR.1.2.6.c1-01000-8x09.0 162 | LA.BR.1.2.6.c1-01200-8x09.0 163 | LA.BR.1.2.6.c1-01500-8x09.0 164 | LA.BR.1.2.6.c1-01700-8x09.0 165 | LA.BR.1.2.6.c1-02100-8x09.0 166 | LA.BR.1.2.6.c1-02900-8x09.0 167 | LA.BR.1.2.6.c1-03600-8x09.0 168 | LA.BR.1.2.6.c1-04000-8x09.0 169 | LA.BR.1.2.6.c1-04500-8x09.0 170 | LA.BR.1.2.7-00510-8x09.0 171 | LA.BR.1.2.7-00610-8x09.0 172 | LA.BR.1.2.7-00710-8x09.0 173 | LA.BR.1.2.7-00910-8x09.0 174 | LA.BR.1.2.7-01010-8x09.0 175 | LA.BR.1.2.7-01210-8x09.0 176 | LA.BR.1.2.7-01510-8x09.0 177 | LA.BR.1.2.7-01710-8x09.0 178 | LA.BR.1.2.7-01910-8x09.0 179 | LA.BR.1.2.7-02010-8x09.0 180 | LA.BR.1.2.7-02110-8x09.0 181 | LA.BR.1.2.7-02710-8x09.0 182 | LA.BR.1.2.7-02810-8x09.0 183 | LA.BR.1.2.7-02900-8x09.0 184 | LA.BR.1.2.7-03010-8x09.0 185 | LA.BR.1.2.7-03210-8x09.0 186 | LA.BR.1.2.7-03610-8x09.0 187 | LA.BR.1.2.7-03810-8x09.0 188 | LA.BR.1.2.7-04010-8x09.0 189 | LA.BR.1.2.7-04210-8x09.0 190 | LA.BR.1.2.7-04310-8x09.0 191 | LA.BR.1.2.7-04510-8x09.0 192 | LA.BR.1.2.7-04610-8x09.0 193 | LA.BR.1.2.7-04710-8x09.0 194 | LA.BR.1.2.7-04810-8x09.0 195 | LA.BR.1.2.7-05010-8x09.0 196 | LA.BR.1.2.7-05310-8x09.0 197 | LA.BR.1.2.7-05400-8x09.0 198 | LA.BR.1.2.7-05410-8x09.0 199 | LA.BR.1.2.7-05610-8x09.0 200 | LA.BR.1.2.7-05810-8x09.0 201 | LA.BR.1.2.7-05910-8x09.0 202 | LA.BR.1.2.7-06010-8x09.0 203 | LA.BR.1.2.7-06210-8x09.0 204 | LA.BR.1.2.7-06410-8x09.0 205 | LA.BR.1.2.7-06610-8x09.0 206 | LA.BR.1.2.7-06710-8x09.0 207 | LA.BR.1.2.7-06910-8x09.0 208 | LA.BR.1.2.7-07110-8x09.0 209 | LA.BR.1.2.7-08900-8x09.0 210 | LA.BR.1.2.7-13300-8x09.0 211 | LA.BR.1.2.7-18500-8x09.0 212 | LA.BR.1.2.7.c1-02200-8x09.0 213 | LA.BR.1.2.7.c1-03500-8x09.0 214 | LA.BR.1.2.7.c1-04300-8x09.0 215 | LA.BR.1.2.7.c1-05400-8x09.0 216 | LA.BR.1.2.7.c1-06000-8x09.0 217 | LA.BR.1.2.7.c1-07800-8x09.0 218 | LA.BR.1.2.7.c1-08400-8x09.0 219 | LA.BR.1.2.7.c1-10200-8x09.0 220 | LA.BR.1.2.7.c1-10900-8x09.0 221 | LA.BR.1.2.7.c1-12200-8x09.0 222 | LA.BR.1.2.7.c1-14500-8x09.0 223 | LA.BR.1.2.7.c1-18800-8x09.0 224 | LA.BR.1.2.7.c1-20300-8x09.0 225 | LA.BR.1.2.7.c1-20900-8x09.0 226 | LA.BR.1.2.7.c1-21600-8x09.0 227 | LA.BR.1.2.7.c1-21900-8x09.0 228 | LA.BR.1.2.7.c1-23200-8x09.0 229 | LA.BR.1.2.7.c1-23800-8x09.0 230 | LA.BR.1.2.7.c1-24800-8x09.0 231 | LA.BR.1.2.8-03400-8x09.0 232 | LA.BR.1.2.8-06000-8x09.0 233 | LA.BR.1.2.8-07400-8x09.0 234 | LA.BR.1.2.8-09900-8x09.0 235 | LA.BR.1.2.8-13400-8x09.0 236 | LA.BR.1.2.8-16400-8x09.0 237 | LA.BR.1.2.8-20100-8x09.0 238 | LA.BR.1.2.9-00810-8x09.0 239 | LA.BR.1.2.9-00910-8x09.0 240 | LA.BR.1.2.9-01010-8x09.0 241 | LA.BR.1.2.9-01310-8x09.0 242 | LA.BR.1.2.9-01510-8x09.0 243 | LA.BR.1.2.9-01610-8x09.0 244 | LA.BR.1.2.9-01710-8x09.0 245 | LA.BR.1.2.9-01810-8x09.0 246 | LA.BR.1.2.9-02210-8x09.0 247 | LA.BR.1.2.9-02310-8x09.0 248 | LA.BR.1.2.9-02510-8x09.0 249 | LA.BR.1.2.9-02910-8x09.0 250 | LA.BR.1.2.9-03310-8x09.0 251 | LA.BR.1.2.9-03510-8x09.0 252 | LA.BR.1.2.9-03610-8x09.0 253 | LA.BR.1.2.9-03710-8x09.0 254 | LA.BR.1.2.9-03910-8x09.0 255 | LA.BR.1.2.9-04110-8x09.0 256 | LA.BR.1.2.9-04310-8x09.0 257 | LA.BR.1.2.9-04510-8x09.0 258 | LA.BR.1.2.9-04610-8x09.0 259 | LA.BR.1.2.9-04810-8x09.0 260 | LA.BR.1.2.9-04910-8x09.0 261 | LA.BR.1.2.9-05110-8x09.0 262 | LA.BR.1.2.9-05310-8x09.0 263 | LA.BR.1.2.9-05410-8x09.0 264 | LA.BR.1.2.9-06010-8x09.0 265 | LA.BR.1.2.9-06510-8x09.0 266 | LA.BR.1.2.9.c1-00400-8x09.0 267 | LA.BR.1.2.9.c1-00600-8x09.0 268 | -------------------------------------------------------------------------------- /find_tags.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ^ the above shebang is preferred for portability between distros since bash 3 | # isn't always installed at /bin and env has a higher probability of being 4 | # located at /usr/bin across other distros than bash being found at /bin 5 | # This script requires bash 4.4+ 6 | 7 | ### Don't change anything below this line unless you know what you are doing. 8 | 9 | tags_file="$(pwd)/tags.txt" 10 | out_file="report.txt" 11 | temp_changed_file="$(pwd)/temp_changes.txt" 12 | temp_tag_file="$(pwd)/temp_tags.txt" 13 | caf_url="https://source.codeaurora.org/quic/la/kernel/msm" 14 | 15 | N=1 # DEFAULT for -j|--jobs and can be overwritten from commandline 16 | 17 | # Colors for script 18 | #BOLD="\033[1m" 19 | GRN="\033[01;32m" 20 | RED="\033[01;31m" 21 | RST="\033[0m" 22 | YLW="\033[01;33m" 23 | 24 | # https://github.com/pollev/bash_progress_bar/blob/c2c8312d8d6fb4f2f1693a524c0942e34439215b/progress_bar.sh#L14-#L22 25 | # Constants for progress bar 26 | CODE_SAVE_CURSOR="\033[s" 27 | CODE_RESTORE_CURSOR="\033[u" 28 | CODE_CURSOR_IN_SCROLL_AREA="\033[1A" 29 | COLOR_FG="\e[31m" # Foreground Red color 30 | COLOR_BG="\e[40m" # Background Black color 31 | RESTORE_FG="\e[39m" # Default foreground color 32 | RESTORE_BG="\e[49m" # Default background color 33 | 34 | # Alias for echo to handle escape codes like colors 35 | # https://github.com/android-linux-stable/script/blob/9236762b163b3ae8ac78d6f5187c8b61a4184377/linux-stable.sh#L29-#L32 36 | function echo() { 37 | command echo -e "$@" 38 | } 39 | 40 | function echoNew() { 41 | command echo -ne "$@" 42 | } 43 | 44 | # Prints a formatted header to point out what is being done to the user 45 | # https://github.com/android-linux-stable/script/blob/9236762b163b3ae8ac78d6f5187c8b61a4184377/linux-stable.sh#L35-#L49 46 | function header() { 47 | if [[ -n "${2}" ]]; then 48 | COLOR="${2}" 49 | else 50 | COLOR="${RED}" 51 | fi 52 | echo "${COLOR}" 53 | # shellcheck disable=SC2034 54 | echo "====$(for i in $(seq ${#1}); do echo "=\c"; done)====" 55 | echo "== ${1} ==" 56 | # shellcheck disable=SC2034 57 | echo "====$(for i in $(seq ${#1}); do echo "=\c"; done)====" 58 | echo "${RST}" 59 | } 60 | 61 | function getKernelVersion() { 62 | # Makefile can be located at the root of the kernel source and it already 63 | # tells us what the kernelversion is. We can automatically grab this information 64 | # without requiring user interaction then use that for caf. 65 | mapfile -t kv < <(grep -E 'VERSION|PATCHLEVEL' <(head -n 3 "${REPO_DIR}"/Makefile) | grep -Eo '[0-9][0-9]*') 66 | kernel_version="${kv[0]}.${kv[1]}" 67 | } 68 | 69 | function checkGitRemote() { 70 | if git -C "${REPO_DIR}" remote -v | grep -E "${caf_url}-${kernel_version}" >> /dev/null 2>&1; then 71 | # Remote for caf already exists so use theirs instead of creating a new remote 72 | # The remote should be pure and untouched, and I can't think of any reason 73 | # as to why it wouldn't be. TODO: Maybe add a condition statement to verify 74 | # if the remote is clean or polluted and handle it accordingly? 75 | mapfile -t gr < <(git -C "${REPO_DIR}" remote -v | grep -E "${caf_url}-${kernel_version}" | awk '{print $1}') 76 | caf_remote="${gr[0]}" 77 | else 78 | # Missing remote for caf so lets create one and make sure the remote name 79 | # doesn't already exist. We will attempt to use fqkt in this instance, but 80 | # should it exist, then we will amend a $RANDOM value. 81 | # fqkt is short for find-qcom-kernel-tag. 82 | caf_remote="fqkt" 83 | if git -C "${REPO_DIR}" config remote."${caf_remote}".url; then 84 | caf_remote="fqkt-${RANDOM}" 85 | fi 86 | git -C "${REPO_DIR}" remote add "${caf_remote}" "${caf_url}"-"${kernel_version}" 87 | fi 88 | } 89 | 90 | function fetchGitRemote() { 91 | header "Fetching Remote: ${caf_remote}" 92 | # Fetch/update remote 93 | git -C "${REPO_DIR}" fetch "${caf_remote}" 94 | } 95 | 96 | # There are many ways for someone to populate the tags file. Some methods will 97 | # create a newline at the end of the file which is what we need since we rely on 98 | # wc to give an accurate count. Since the opposite effect can happen we need to 99 | # check and insure this newline even exists and if it doesn't then create one. 100 | # Additionally, we want to insure there are not multiple inclusions of newlines 101 | # at the end of the file so using cat to recreate the tags file will resolve all 102 | # problems without hassle. 103 | # 104 | # NOTE: This isn't needed any longer, but lets keep it around since it is 105 | # harmless, and will provide extra protection. 106 | function fixNewLine() { 107 | cat <<< "$(<"${tags_file}")" > "./temp.txt" 108 | cat <<< "$(<./temp.txt)" > "${tags_file}" 109 | rm ./temp.txt 110 | } 111 | 112 | function getParallelJobs () { 113 | # Get number of current runnning jobs. 114 | jobs -lpr >/dev/null 115 | jobs -lpr | wc -l 116 | } 117 | 118 | function checkParallelRestrictedJobs () { 119 | # Wait for the number of running jobs to be reduced 120 | # then start a new job when there is room available. 121 | if (( "${1}" <= $(getParallelJobs) )); then 122 | wait -n # Wait for 'a' job to finish 123 | fi 124 | } 125 | 126 | # https://github.com/pollev/bash_progress_bar/blob/c2c8312d8d6fb4f2f1693a524c0942e34439215b/progress_bar.sh#L29-#L51 127 | function setupScrollArea() { 128 | # We will want to activate it whenever we setup the scroll area and remove 129 | # it when we break the scroll area. 130 | trapOnInterrupt 131 | 132 | lines=$(tput lines) 133 | lines=$((lines - 1)) 134 | # Scroll down a bit to avoid visual glitch when the screen area shrinks by 135 | # one row. 136 | echoNew "\n" 137 | 138 | # Save cursor 139 | echoNew "${CODE_SAVE_CURSOR}" 140 | # Set scroll region (this will place the cursor in the top left) 141 | echoNew "\033[0;${lines}r" 142 | 143 | # Restore cursor but ensure its inside the scrolling area 144 | echoNew "${CODE_RESTORE_CURSOR}" 145 | echoNew "${CODE_CURSOR_IN_SCROLL_AREA}" 146 | 147 | # Start empty progress bar 148 | drawProgressBar 0 149 | } 150 | 151 | # https://github.com/pollev/bash_progress_bar/blob/c2c8312d8d6fb4f2f1693a524c0942e34439215b/progress_bar.sh#L53-#L74 152 | function destroyScrollArea() { 153 | lines=$(tput lines) 154 | # Save cursor 155 | echoNew "${CODE_SAVE_CURSOR}" 156 | # Set scroll region (this will place the cursor in the top left) 157 | echoNew "\033[0;${lines}r" 158 | 159 | # Restore cursor but ensure its inside the scrolling area 160 | echoNew "${CODE_RESTORE_CURSOR}" 161 | echoNew "${CODE_CURSOR_IN_SCROLL_AREA}" 162 | 163 | # We are done so clear the scroll bar 164 | clearProgressBar 165 | 166 | # Scroll down a bit to avoid visual glitch when the screen area grows by one row 167 | echoNew "\n\n" 168 | 169 | # Once the scroll area is cleared, we want to remove any trap previously set. 170 | # Otherwise, ctrl+c will exit our shell. 171 | trap - INT 172 | } 173 | 174 | # https://github.com/pollev/bash_progress_bar/blob/c2c8312d8d6fb4f2f1693a524c0942e34439215b/progress_bar.sh#L157-#L161 175 | function trapOnInterrupt() { 176 | # If this function is called, we setup an interrupt handler to cleanup the progress bar 177 | trap cleanupOnInterrupt INT 178 | } 179 | 180 | # https://github.com/pollev/bash_progress_bar/blob/c2c8312d8d6fb4f2f1693a524c0942e34439215b/progress_bar.sh#L163-#L166 181 | # Clean up scroll area and temp files if the script is interrupted such as ctrl+c 182 | function cleanupOnInterrupt() { 183 | destroyScrollArea 184 | # Clean up temp files 185 | rm -rf "${temp_dir}" 2> /dev/null 186 | rm "${temp_changed_file}" 2> /dev/null 187 | rm "${temp_tag_file}" 2> /dev/null 188 | exit 189 | } 190 | 191 | # https://github.com/pollev/bash_progress_bar/blob/c2c8312d8d6fb4f2f1693a524c0942e34439215b/progress_bar.sh#L76-#L95 192 | function drawProgressBar() { 193 | percentage="${1}" 194 | lines=$(tput lines) 195 | lines="${lines}" 196 | # Save cursor 197 | echoNew "${CODE_SAVE_CURSOR}" 198 | 199 | # Move cursor position to last row 200 | echoNew "\033[${lines};0f" 201 | 202 | # Clear progress bar 203 | tput el 204 | 205 | # Draw progress bar 206 | printBarText "${percentage}" 207 | 208 | # Restore cursor position 209 | echoNew "${CODE_RESTORE_CURSOR}" 210 | } 211 | 212 | # https://github.com/pollev/bash_progress_bar/blob/c2c8312d8d6fb4f2f1693a524c0942e34439215b/progress_bar.sh#L118-#L132 213 | function clearProgressBar() { 214 | lines=$(tput lines) 215 | lines="${lines}" 216 | # Save cursor 217 | echoNew "${CODE_SAVE_CURSOR}" 218 | 219 | # Move cursor position to last row 220 | echoNew "\033[${lines};0f" 221 | 222 | # clear progress bar 223 | tput el 224 | 225 | # Restore cursor position 226 | echoNew "${CODE_RESTORE_CURSOR}" 227 | } 228 | 229 | # https://github.com/pollev/bash_progress_bar/blob/c2c8312d8d6fb4f2f1693a524c0942e34439215b/progress_bar.sh#L134-#L151 230 | function printBarText() { 231 | percentage="${1}" 232 | cols=$(tput cols) 233 | bar_size=$((cols - 18)) 234 | 235 | color="${COLOR_FG}${COLOR_BG}" 236 | 237 | # Prepare progress bar 238 | complete_size=$(((bar_size * percentage ) / 100)) 239 | remainder_size=$((bar_size - complete_size)) 240 | progress_bar=$( 241 | echoNew "["; 242 | echoNew "${color}"; 243 | printf_new "#" ${complete_size}; 244 | echoNew "${RESTORE_FG}${RESTORE_BG}"; 245 | if [[ "${percent}" -lt "100" ]]; then 246 | printf_new "." "${remainder_size}"; 247 | else 248 | echoNew "${color}"; 249 | printf_new "#" "${remainder_size}"; 250 | echoNew "${RESTORE_FG}${RESTORE_BG}"; 251 | fi; 252 | echoNew "]" 253 | ); 254 | 255 | # Print progress bar 256 | echoNew " Progress ${percentage}% ${progress_bar}" 257 | } 258 | 259 | # https://github.com/pollev/bash_progress_bar/blob/c2c8312d8d6fb4f2f1693a524c0942e34439215b/progress_bar.sh#L168-#L173 260 | function printf_new() { 261 | str="${1}" 262 | num="${2}" 263 | v=$(printf "%-${num}s" "${str}") 264 | echoNew "${v// /$str}" 265 | } 266 | 267 | # Variable is used in subshells and ultimately lost. 268 | # Call this function to write the value to a temp file to save it. 269 | function hackOldResult() { 270 | echo "${1}" > "${temp_changed_file}" 271 | } 272 | 273 | # Variable is used in subshells and ultimately lost. 274 | # Call this function to write the value to a temp file to save it. 275 | function hackBestTag() { 276 | echo "${1}" > "${temp_tag_file}" 277 | } 278 | 279 | # Prints information on how to use the script. 280 | function usage() { 281 | cat <, --kernel , --kernel= 291 | Target kernel source at the root. 292 | 293 | -t , --tags , --tags= 294 | Populate tags.txt with a list from CAF. 295 | 296 | -j , --jobs , --jobs= 297 | Run script with N processes. [optional] 298 | 299 | EOF 300 | } 301 | 302 | # Logging and error handling functions for usage option commands. 303 | function log() { echo ""; echo "$*"; } 304 | function error() { log "${RED}ERROR: $*${RST}" >&2; } 305 | function fatal() { error "$*"; exit 1; } 306 | function usageFatal() { error "$*"; usage >&2; exit 1; } 307 | 308 | # Parse non positional options 309 | while [ "$#" -gt 0 ]; do 310 | arg="${1}" 311 | case "${1}" in 312 | # Convert "--opt=the value" to --opt "the value". 313 | # The quotes around the equals sign is to work around a 314 | # bug in emacs' syntax parsing. 315 | --*'='*) shift; set -- "${arg%%=*}" "${arg#*=}" "$@"; continue;; 316 | -j|--jobs) shift; N="${1}";; 317 | -k|--kernel) shift; REPO_DIR="${1}";; 318 | -t|--tags) shift; GIT_TAGS="${1}";; 319 | -h|--help) usage; exit 0;; 320 | -*) usageFatal "unknown option: '$1'";; 321 | *) usageFatal "unknown option: '$1'";; 322 | esac 323 | shift || usageFatal "option '${arg}' requires a value" 324 | done 325 | 326 | # If the kernel source isn't specified with -k|--kernel, then abort. 327 | if [[ -z "${REPO_DIR}" ]]; then 328 | echo "" 329 | echo "${RED}Invalid kernel source location specified! Folder does not exist.${RST}" 330 | usage 331 | exit 0 332 | fi 333 | 334 | # If -k|--kernel is specified, check to see if Makefile exists as a way to validate 335 | # that the path is correct. 336 | if [[ ! -f ${REPO_DIR}/Makefile ]]; then 337 | echo "" 338 | echo "${RED}Invalid kernel source location specified! No Makefile present.${RST}" 339 | usage 340 | exit 0 341 | fi 342 | 343 | # Check if the path of the kernel source has a trailing forward slash and 344 | # remove it if it does to prevent issues. 345 | if echo "${REPO_DIR}" | grep -o /$ >/dev/null 2>&1; then 346 | REPO_DIR="${REPO_DIR%?}" 347 | fi 348 | 349 | # Check if tags is set after being specified with -t|--tags, and abort if not. 350 | if [[ -z "${GIT_TAGS}" ]]; then 351 | echo "" 352 | echo "${RED}No specific points referenced in a repository's history! No tag present.${RST}" 353 | usage 354 | exit 0 355 | fi 356 | 357 | # Check if the specified tag returns true, or we need to abort, then report 358 | # that the regex is invalid and to try again. 359 | if [ -n "$(git -C "${REPO_DIR}" tag -l "${GIT_TAGS}")" ]; then 360 | # We need to populate tags.txt so lets do it as specified by -t|--tags. 361 | git -C "${REPO_DIR}" tag -l "${GIT_TAGS}" > "${tags_file}" 362 | else 363 | echo "" 364 | echo "${RED}'${GIT_TAGS}' is invalid and does not exist! Try again.${RST}" 365 | usage 366 | exit 0 367 | fi 368 | 369 | # Let's kick off some sanity checks before starting the main labor of this script 370 | getKernelVersion 371 | checkGitRemote 372 | fetchGitRemote 373 | fixNewLine 374 | 375 | process_count="0" # This is primarily for parallel jobs but can be used either way. 376 | carriage="\r" 377 | trail_nl="n" 378 | count_base="0" 379 | count_index=$(wc -l < "${tags_file}") 380 | clear # Clean up any junk on the screen 381 | header "Find-Qcom-Kernel-Tag" 382 | setupScrollArea # Create initial progress bar for staging 383 | 384 | # Create a temp directory to isolate the temp files created during the loop 385 | temp_dir="$(pwd)/${RANDOM}_temp" 386 | mkdir -p "${temp_dir}" 387 | echo "999999999" > "${temp_changed_file}" # Temp file for changed results in diffed files 388 | 389 | while IFS= read -r tag; do 390 | process_count=$((process_count + 1)) # Temp file extensions 391 | count_base=$((count_base + 1)) # Progress bar 392 | percent=$((count_base * 100 / count_index)) # Progress bar 393 | 394 | # Generate progress bar as script moves forward 395 | drawProgressBar "${percent}" 396 | 397 | { 398 | tag_hash=$(git -C "${REPO_DIR}" show -s --format=%H "${tag}" | tail -n1) 399 | git -C "${REPO_DIR}" fetch "${caf_remote}" "${tag_hash}" >> /dev/null 2>&1 400 | git -c diff.renameLimit=9999 -C "${REPO_DIR}" diff "${tag_hash}" --shortstat > "${temp_dir}"/"${out_file}"-"${process_count}" 401 | mapfile -t result < <(echo grep -Eo '[0-9][0-9]* files changed' | grep -Eo '[0-9][0-9]*' "${temp_dir}"/"${out_file}"-"${process_count}") 402 | if [ "${count_base}" == "${count_index}" ]; then 403 | carriage="" 404 | trail_nl="" 405 | fi 406 | 407 | # Need to make sure the array, $result, isn't empty or it will report an 408 | # error expecting an integer expression. 409 | if (( ${#result[@]} )); then 410 | if [ "${result[0]}" -le "$(cat "${temp_changed_file}")" ]; then 411 | hackOldResult "${result[0]}" 412 | hackBestTag "${tag}" 413 | echo -${trail_nl}e " ${YLW}New best tag: ${tag}, files changed: ${result[0]}${RST} ${carriage}" 414 | else 415 | old_result=$(<"${temp_changed_file}") 416 | best_tag=$(<"${temp_tag_file}") 417 | echo -${trail_nl}e " ${GRN}Current best tag: ${best_tag}, files changed: ${old_result}${RST} ${carriage}" 418 | fi 419 | else 420 | old_result=$(<"${temp_changed_file}") 421 | best_tag=$(<"${temp_tag_file}") 422 | echo -${trail_nl}e " ${GRN}Current best tag: ${best_tag}, files changed: ${old_result}${RST} ${carriage}" 423 | fi 424 | } & # This ampersand will run it in the background 425 | 426 | # Allow only to execute $N jobs in parallel if -j|--jobs was used. 427 | # Put on queue until a job has finished and opens up another slot 428 | # for another job. 429 | if [[ -n "${N}" ]]; then 430 | checkParallelRestrictedJobs "${N}" 431 | else 432 | # Kill the script and clean up. 433 | # N must return a value to prevent an infinite loop. 434 | cleanupOnInterrupt 435 | fi 436 | 437 | done < <(grep -v '^ *#' < "${tags_file}") # Process substitution 438 | wait # Wait for pending jobs 439 | 440 | # Cleanup leftover files 441 | rm -rf "${temp_dir}" 2> /dev/null && rm "${temp_changed_file}" 2> /dev/null && rm "${temp_tag_file}" 2> /dev/null 442 | destroyScrollArea # Remove progress bar 443 | 444 | # Before finishing up, let the user know how to remove the caf remote at their 445 | # own discretion when they are ready. 446 | echo "" 447 | echo "To save space you can now remove the caf remote when you are ready." 448 | echo "Manually remove the caf remote with command: ${RED}git remote rm ${caf_remote}${RST}" 449 | echo "" 450 | --------------------------------------------------------------------------------