-
Notifications
You must be signed in to change notification settings - Fork 20
/
OTA.sh
159 lines (132 loc) · 5.13 KB
/
OTA.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
#!/bin/bash
# Copyright (C) 2020-23 The Superior OS Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# git pull if repo already exist
if [ -d ~/official_devices-gapps ]; then
echo "Pulling the latest changes from the official_devices-gapps repository..."
cd ~/official_devices-gapps
git pull
cd ~
fi
myname="$0"
function help() {
cat <<EOF
Syntax:
$myname <device> <folder_of_rom>
for example:
$myname ef63 superior
EOF
}
if [ $# -lt 2 ]; then
echo "ERROR: Not enough arguments provided"
help
exit 1
fi
device=$1
sourcerom=$2
DATE="$(grep ro.build.date.utc ~/$sourcerom/out/target/product/$device/system/build.prop | cut -d'=' -f2)"
if [ -z "$DATE" ]; then
echo "ERROR: Failed to retrieve build date"
exit 1
fi
echo ""
# make DATE human readable like 20230203
BUILDDATE="$(date -d @$DATE +%Y%m%d)"
DAY="$(date -d @$DATE +%d/%m/%Y)"
# get the zip path from out folder using the date
zip_path=~/$sourcerom/out/target/product/$device/*$BUILDDATE*.zip
# don't fail if there is no device json
set +e
if [ ! -d ~/official_devices-gapps ]; then
cd ~
git clone https://github.com/SuperiorOS-Devices/official_devices-gapps.git -b fourteen
fi
echo ""
if [ -d ~/official_devices-gapps ]; then
# datetime
timestamp=$(cat ~/$sourcerom/out/target/product/$device/system/build.prop | grep ro.build.date.utc | cut -d'=' -f2)
timestamp_old=$(cat ~/official_devices-gapps/$device.json | grep "datetime" | cut -d':' -f2 | cut -d',' -f1)
$(sed -i "s|$timestamp_old|$timestamp|g" ~/official_devices-gapps/$device.json)
# filename
zip_name=$(cat ~/$sourcerom/out/target/product/$device/system/build.prop | grep ro.superior.version | cut -d'=' -f2)
zip_name_old=$(cat ~/official_devices-gapps/$device.json | grep "filename" | cut -d':' -f2 | cut -d'"' -f2)
$(sed -i "s|$zip_name_old|$zip_name.zip|g" ~/official_devices-gapps/$device.json)
# id
id=$(sha256sum $zip_path | cut -d' ' -f1)
id_old=$(cat ~/official_devices-gapps/$device.json | grep "id" | cut -d':' -f2 | cut -d'"' -f2)
$(sed -i "s|$id_old|$id|g" ~/official_devices-gapps/$device.json)
# Rom type
type="RELEASE"
type_old=$(cat ~/official_devices-gapps/$device.json | grep "romtype" | cut -d':' -f2 | cut -d'"' -f2)
$(sed -i "s|$type_old|$type|g" ~/official_devices-gapps/$device.json)
# Rom size
size_new=$(stat -c "%s" $zip_path)
size_old=$(cat ~/official_devices-gapps/$device.json | grep "size" | cut -d':' -f2 | cut -d',' -f1)
$(sed -i "s|$size_old|$size_new|g" ~/official_devices-gapps/$device.json)
# Rom version
version=$(cat ~/$sourcerom/out/target/product/$device/system/build.prop | grep ro.modversion | cut -d'=' -f2)
version_old=$(cat ~/official_devices-gapps/$device.json | grep "version" | cut -d':' -f2 | cut -d'"' -f2)
$(sed -i "s|$version_old|$version|g" ~/official_devices-gapps/$device.json)
# url
url="https://master.dl.sourceforge.net/project/superioros/$device/gapps/$zip_name.zip"
url_old=$(cat ~/official_devices-gapps/$device.json | grep https | cut -d '"' -f4)
$(sed -i "s|$url_old|$url|g" ~/official_devices-gapps/$device.json)
fi
echo ""
# if there is no json file, create one
if [ ! -f ~/official_devices-gapps/$device.json ]; then
echo "No json file found, creating one"
echo "Creating json file for $device"
echo "{
\"response\": [
{
\"datetime\": $timestamp,
\"filename\": \"$zip_name.zip\",
\"id\": \"$id\",
\"romtype\": \"$type\",
\"size\": $size_new,
\"url\": \"$url\",
\"version\": \"$version\",
\"device_name\": \"Unknown\",
\"maintainer\": \"Noob\"
}
]
}" >~/official_devices-gapps/$device.json
sleep 1
echo "Done"
fi
echo ""
# if device name and maintainer is not set, ask for it
if [ "$(cat ~/official_devices-gapps/$device.json | grep "device_name" | cut -d':' -f2 | cut -d'"' -f2)" == "Unknown" ]; then
echo "Device name is not set, please enter it"
read -p "Device name: " device_name
device_name_old=$(cat ~/official_devices-gapps/$device.json | grep "device_name" | cut -d':' -f2 | cut -d'"' -f2)
$(sed -i "s|$device_name_old|$device_name|g" ~/official_devices-gapps/$device.json)
fi
if [ "$(cat ~/official_devices-gapps/$device.json | grep "maintainer" | cut -d':' -f2 | cut -d'"' -f2)" == "Noob" ]; then
echo "Maintainer is not set, please enter it"
read -p "Maintainer: " maintainer
maintainer_old=$(cat ~/official_devices-gapps/$device.json | grep "maintainer" | cut -d':' -f2 | cut -d'"' -f2)
$(sed -i "s|$maintainer_old|$maintainer|g" ~/official_devices-gapps/$device.json)
fi
# add & push commit to github
echo ""
echo "Making commit..."
cd ~/official_devices-gapps
git add --all
git commit -m "$device: update $DAY"
cd ~
rm -rf OTA.sh
echo "Done"
echo ""