-
Notifications
You must be signed in to change notification settings - Fork 0
/
lineage_oms_merge.sh
executable file
·248 lines (202 loc) · 6.67 KB
/
lineage_oms_merge.sh
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
#!/bin/bash
#
# Copyright (C) 2017 Nathan Chancellor
#
# 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/>
###########
# #
# USAGE #
# #
###########
# PURPOSE: Merge Substratum support from LineageOS-OMS-Update org into LineageOS repos
#
# USAGE: $ bash lineage_oms_merge.sh -h
############
# #
# COLORS #
# #
############
BOLD="\033[1m"
GREEN="\033[01;32m"
RED="\033[01;31m"
RESTORE="\033[0m"
###############
# #
# FUNCTIONS #
# #
###############
# PRINTS A FORMATTED HEADER TO POINT OUT WHAT IS BEING DONE TO THE USER
function echoText() {
echo -e ${RED}
echo -e "====$( for i in $( seq ${#1} ); do echo -e "=\c"; done )===="
echo -e "== ${1} =="
echo -e "====$( for i in $( seq ${#1} ); do echo -e "=\c"; done )===="
echo -e ${RESTORE}
}
# FORMATS THE TIME
function format_time() {
MINS=$(((${1}-${2})/60))
SECS=$(((${1}-${2})%60))
if [[ ${MINS} -ge 60 ]]; then
HOURS=$((${MINS}/60))
MINS=$((${MINS}%60))
fi
if [[ ${HOURS} -eq 1 ]]; then
TIME_STRING+="1 HOUR, "
elif [[ ${HOURS} -ge 2 ]]; then
TIME_STRING+="${HOURS} HOURS, "
fi
if [[ ${MINS} -eq 1 ]]; then
TIME_STRING+="1 MINUTE"
else
TIME_STRING+="${MINS} MINUTES"
fi
if [[ ${SECS} -eq 1 && -n ${HOURS} ]]; then
TIME_STRING+=", AND 1 SECOND"
elif [[ ${SECS} -eq 1 && -z ${HOURS} ]]; then
TIME_STRING+=" AND 1 SECOND"
elif [[ ${SECS} -ne 1 && -n ${HOURS} ]]; then
TIME_STRING+=", AND ${SECS} SECONDS"
elif [[ ${SECS} -ne 1 && -z ${HOURS} ]]; then
TIME_STRING+=" AND ${SECS} SECONDS"
fi
echo ${TIME_STRING}
}
# PRINTS A HELP MENU
function help_menu() {
echo -e "\n${BOLD}OVERVIEW:${RESTORE} Merges full Substratum support from LineageOS-OMS-Update organization into a LineageOS set of repos\n"
echo -e "${BOLD}USAGE:${RESTORE} bash lineage_oms_merge.sh <source_dir>\n"
echo -e "${BOLD}EXAMPLE:${RESTORE} bash lineage_oms_merge.sh ~/Android/Lineage\n"
echo -e "${BOLD}Required options:${RESTORE}"
echo -e " source_dir: Location of the Lineage tree; this needs to exist for the script to properly proceed\n"
}
# CREATES A NEW LINE IN TERMINAL
function newLine() {
echo -e ""
}
# PRINTS AN ERROR IN BOLD RED
function reportError() {
RED="\033[01;31m"
RESTORE="\033[0m"
echo -e ""
echo -e ${RED}"${1}"${RESTORE}
if [[ -z ${2} ]]; then
echo -e ""
fi
}
# PRINTS AN WARNING IN BOLD YELLOW
function reportWarning() {
YELLOW="\033[01;33m"
RESTORE="\033[0m"
echo -e ""
echo -e ${YELLOW}"${1}"${RESTORE}
if [[ -z ${2} ]]; then
echo -e ""
fi
}
###############
# #
# VARIABLES #
# #
###############
if [[ $# -eq 0 ]]; then
reportError "Source directory not specified!" -c; help_menu && exit
fi
while [[ $# -ge 1 ]]; do
case "${1}" in
"-h"|"--help")
help_menu && exit ;;
*)
SOURCE_DIR=${1}
if [[ ! -d ${SOURCE_DIR} ]]; then
reportError "Source directory not found!" && exit
elif [[ ! -d ${SOURCE_DIR}/.repo ]]; then
reportError "This is not a valid Android source folder as there is no .repo folder!" && exit
fi ;;
esac
shift
done
# DO NOT EDIT THIS
SUBS_REPOS="
frameworks/base
frameworks/native
packages/apps/Contacts
packages/apps/ContactsCommon
packages/apps/Dialer
packages/apps/ExactCalculator
packages/apps/PackageInstaller
packages/apps/PhoneCommon
packages/apps/Settings
system/sepolicy
vendor/cm"
unset RESULT_STRING
################
# #
# SCRIPT START #
# #
################
# START TRACKING TIME
START=$( date +%s )
for FOLDER in ${SUBS_REPOS}; do
# PRINT TO THE USER WHAT WE ARE DOING
newLine; echoText "Merging ${FOLDER}"
# SHIFT TO PROPER FOLDER
cd ${SOURCE_DIR}/${FOLDER}
# SET PROPER URL
URL=android_$( echo ${FOLDER} | sed "s/\//_/g" )
BRANCH=cm-14.1
# FETCH THE REPO
git fetch https://github.com/LineageOS-OMS-Update/${URL} ${BRANCH}
# GIT GYMNASTICS (GETS MESSY, BEWARE)
# FIRST HASH WILL ALWAYS BE THE FETCH HEAD
FIRST_HASH=$(git log --format=%H -1 FETCH_HEAD)
# SECOND HASH WILL BE THE LAST THING I COMMITTED
NUMBER_OF_COMMITS=$(( $( git log --format=%H --committer="Nathan Chancellor" FETCH_HEAD | wc -l ) - 1 ))
SECOND_HASH=$( git log --format=%H --committer="Nathan Chancellor" FETCH_HEAD~${NUMBER_OF_COMMITS}^..FETCH_HEAD~${NUMBER_OF_COMMITS} )
# NOW THAT WE HAVE THE HASHES, WE WANT TO TRY AND SEE IF OMS ALREADY EXISTS
# THIS SCRIPT NEEDS TO BE RUN ON A CLEAN REPO
SECOND_COMMIT_MESSAGE=$( git log --format=%s ${SECOND_HASH}^..${SECOND_HASH} | sed "s/\[\([^]]*\)\]/\\\[\1\\\]/g" )
if [[ $( git log --format=%h --grep="${SECOND_COMMIT_MESSAGE}" --all-match | wc -l ) > 0 && ${URL} != "android" ]]; then
reportError "PREVIOUS COMMITS FOUND; SCRIPT MUST BE RUN ON A CLEAN REPO! EITHER REPO SYNC OR PICK COMMITS MANUALLY!" && exit
fi
# RESET ANY LOCAL CHANGES SO THAT CHERRY-PICK DOES NOT FAIL
git reset --hard HEAD
# PICK THE COMMITS IF EVERYTHING CHECKS OUT
git cherry-pick ${SECOND_HASH}^..${FIRST_HASH}
# ADD TO RESULT STRING
if [[ $? -ne 0 ]]; then
RESULT_STRING+="${FOLDER}: ${RED}FAILED${RESTORE}\n"
else
RESULT_STRING+="${FOLDER}: ${GREEN}SUCCESS${RESTORE}\n"
fi
done
# SHIFT BACK TO THE TOP OF THE REPO
cd ${SOURCE_DIR}
# SYNC THEME INTERFACER REPO
newLine; echoText "Syncing packages/services/ThemeInterfacer"
# Make sure that the local manifest exists
if [[ ! -f .repo/local_manifests/substratum.xml ]]; then
mkdir -p .repo/local_manifests
curl --silent --output .repo/local_manifests/substratum.xml \
https://raw.githubusercontent.com/LineageOS-OMS-Update/merge_script/master/substratum.xml
fi
repo sync --force-sync packages/services/ThemeInterfacer
# PRINT RESULTS
echoText "RESULTS"
echo -e ${RESULT_STRING}
# STOP TRACKING TIME
END=$( date +%s )
# PRINT RESULT TO USER
echoText "SCRIPT COMPLETED!"
echo -e ${RED}"TIME: $(format_time ${END} ${START})"${RESTORE}; newLine