Browse Source

refactoring the code

pull/3/head
Martin Dünkelmann 3 years ago
parent
commit
cc075a5ca1
Signed by untrusted user: MartinX3 GPG Key ID: 992977C753423FB8
  1. 9
      create_zip.sh
  2. 265
      tmp/patch_dualsim.sh

9
create_zip.sh

@ -1,5 +1,10 @@
#!/usr/bin/env sh
VERSION=3
mkdir -p zips
rm zips/sony-dualsim-patcher-v$VERSION.zip
zip zips/sony-dualsim-patcher-v$VERSION.zip tmp/* META-INF/com/google/android/update-binary META-INF/com/google/android/updater-script
if [ -f zips/sony-dualsim-patcher-v${VERSION}.zip ]
then
rm zips/sony-dualsim-patcher-v${VERSION}.zip
fi
zip -r zips/sony-dualsim-patcher-v${VERSION}.zip META-INF tmp

265
tmp/patch_dualsim.sh

@ -1,176 +1,159 @@
#!/sbin/sh
# If we have system-as-root the system is mounted at /system/system in twrp
system_path=/system
if [ -d ${system_path}/system ]
then
system_path=${system_path}/system
fi
device_variant=
default_network=
# Sanity check - was this patch already flashed?
if $vendor_on_system
then
if $(cat /system/vendor/etc/vintf/manifest.xml | grep slot2)
# If we have system-as-root the system is mounted at /system/system in twrp
function check_if_system_as_root() {
echo "Checking if system-as-root"
if [ -d ${system_path}/system ]
then
echo "Already patched"
exit 0
system_path=${system_path}/system
fi
else
if $(cat /vendor/etc/vintf/manifest.xml | grep slot2)
}
# Sanity check - was this patch already flashed?
function check_if_already_patched() {
echo "Checking if already patched"
if $(cat ${system_path}/vendor/etc/vintf/manifest.xml | grep slot2)
then
echo "Already patched"
exit 0
fi
fi
}
echo "Mounting LTALabel partition"
mkdir /lta-label
mount -t ext4 /dev/block/bootdevice/by-name/LTALabel /lta-label
# Detect the exact model from the LTALabel partition
# This looks something like:
# 1284-8432_5-elabel-D5303-row.html
# 1284-8432_5-elabel-F8332-row.html
# Output will be e.g. F8332
variant_lower=$(\
ls /lta-label/*.html | \
sed 's/.*-elabel-//' | \
sed 's/-.*.html//' | \
tr -d '\n\r' \
);
variant_upper=$(\
echo ${variant_lower} | \
tr '[a-z]' '[A-Z]' \
);
umount /lta-label
echo "Model variant is ${variant_upper}"
case ${variant_lower} in
# voyager, pioneer, discovery, kirin, mermaid
h4413|h4113|h4213|i4113|i4213)
default_network="9,0"
echo "Setting default_network to 9,0"
;;
# suzu, kagura, dora, keyaki, maple, poplar
f5122|f8332|f8132|g8232|g8142|g8342)
default_network="9,1"
echo "Setting default_network to 9,1"
;;
# apollo, akatsuki(2x), akari(2x)
h8324|h9436|h9493|h8266|h8296)
default_network="9,9"
echo "Setting default_network to 9,9"
;;
esac
rm -f /tmp/build.prop
echo "persist.vendor.radio.multisim.config=dsds" >> /tmp/build.prop
echo "ro.telephony.default_network=${default_network}" >> /tmp/build.prop
model=$(\
cat ${system_path}/build.prop ${system_path}/vendor/build.prop /vendor/build.prop | \
grep "ro.product.vendor.model" | \
head -n 1 \
)
model=$(echo ${model} | sed 's/(AOSP)/Dual (AOSP)/')
echo "$model" >> /tmp/build.prop
echo "Substituting props in ${system_path}/build.prop"
echo "Substituting props in ${system_path}/vendor/build.prop"
_ifs_backup="$IFS"
# Prevent prop names with spaces in them being split into multiple fields
IFS=$'\n'
for prop in `cat /tmp/build.prop`
do
propname=$(echo "$prop" | cut -d '=' -f 1)
sed -i "/$propname/d" ${system_path}/build.prop
echo "$prop" >> ${system_path}/build.prop
sed -i "/$propname/d" ${system_path}/vendor/build.prop
echo "$prop" >> ${system_path}/vendor/build.prop
done
IFS="$_ifs_backup"
function get_the_LTA_Label() {
echo "Mounting LTALabel partition"
mkdir /lta-label
mount -t ext4 /dev/block/bootdevice/by-name/LTALabel /lta-label
device_variant=$(\
ls /lta-label/*.html | \
sed 's/.*-elabel-//' | \
sed 's/-.*.html//' | \
tr -d '\n\r' \
);
umount /lta-label
rm /lta-label
echo "Device variant is ${device_variant}"
}
function get_the_default_network_from_device_variant() {
case ${device_variant} in
# voyager, pioneer, discovery, kirin, mermaid
h4413|h4113|h4213|i4113|i4213)
default_network="9,0"
;;
# suzu, kagura, dora, keyaki, maple, poplar
f5122|f8332|f8132|g8232|g8142|g8342)
default_network="9,1"
;;
# apollo, akatsuki(2x), akari(2x)
h8324|h9436|h9493|h8266|h8296)
default_network="9,9"
;;
esac
echo "Setting default_network to $default_network"
}
function set_the_build_prop_dual_sim_values() {
rm -f /tmp/build.prop
echo "persist.vendor.radio.multisim.config=dsds" >> /tmp/build.prop
echo "ro.telephony.default_network=$default_network" >> /tmp/build.prop
model=$(\
cat ${system_path}/build.prop ${system_path}/vendor/build.prop | \
grep "ro.product.vendor.model" | \
head -n 1 \
)
model=$(echo ${model} | sed 's/(AOSP)/Dual (AOSP)/')
echo "$model" >> /tmp/build.prop
echo "Substituting props in $system_path/build.prop"
echo "Substituting props in $system_path/vendor/build.prop"
# Prevent prop names with spaces in them being split into multiple fields
IFS=$'\n'
for prop in `cat /tmp/build.prop`
do
propname=$(echo "$prop" | cut -d '=' -f 1)
sed -i "/$propname/d" ${system_path}/build.prop
echo "$prop" >> ${system_path}/build.prop
sed -i "/$propname/d" ${system_path}/vendor/build.prop
echo "$prop" >> ${system_path}/vendor/build.prop
done
}
function set_the_build_prop_device_model_values() {
sed -i "s/$1/$2/g" ${system_path}/build.prop
sed -i "s/$1/$2/g" ${system_path}/vendor/build.prop
}
# VINTF manifest patching
# Add a second instance of every needed HAL
function patch_VINTF_manifest() {
echo "Patching VINTF manifest"
sed -i -r 's/( +<(fqname|instance)>[^<>]*(slot)[^<>]*)1(<\/[^<>]+>)/\11\4\n\12\4/i' ${system_path}/vendor/etc/vintf/manifest.xml
sed -i -r 's/( +<(fqname|instance)>[^<>]*(hook|radio|ril|uim)[^<>]*)0(<\/[^<>]+>)/\10\4\n\11\4/i' ${system_path}/vendor/etc/vintf/manifest.xml
}
check_if_system_as_root;
check_if_already_patched;
get_the_LTA_Label;
get_the_default_network_from_device_variant;
set_the_build_prop_dual_sim_values;
# kirin
sed -i "s/i3113/i4113/g" ${system_path}/build.prop
sed -i "s/I3113/I4113/g" ${system_path}/build.prop
sed -i "s/i3113/i4113/g" ${system_path}/vendor/build.prop
sed -i "s/I3113/I4113/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values i3113 i4113;
set_the_build_prop_device_model_values I3113 I4113;
# mermaid
sed -i "s/i3213/i4213/g" ${system_path}/build.prop
sed -i "s/I3213/I4213/g" ${system_path}/build.prop
sed -i "s/i3213/i4213/g" ${system_path}/vendor/build.prop
sed -i "s/I3213/I4213/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values i3213 i4213;
set_the_build_prop_device_model_values I3213 I4213;
# akari
sed -i "s/h8216/h8266/g" ${system_path}/build.prop
sed -i "s/H8216/H8266/g" ${system_path}/build.prop
sed -i "s/h8216/h8266/g" ${system_path}/vendor/build.prop
sed -i "s/H8216/H8266/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values h8216 h8266;
set_the_build_prop_device_model_values H8216 H8266;
# apollo
sed -i "s/h8314/h8324/g" ${system_path}/build.prop
sed -i "s/H8314/H8324/g" ${system_path}/build.prop
sed -i "s/h8314/h8324/g" ${system_path}/vendor/build.prop
sed -i "s/h8314/h8324/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values h8314 h8324;
set_the_build_prop_device_model_values H8314 H8324;
# akatsuki
sed -i "s/h8416/h9436/g" ${system_path}/build.prop
sed -i "s/H8416/H9436/g" ${system_path}/build.prop
sed -i "s/h8416/h9436/g" ${system_path}/vendor/build.prop
sed -i "s/h8416/h9436/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values h8416 h9436;
set_the_build_prop_device_model_values H8416 H9436;
# pioneer
sed -i "s/h3113/h4113/g" ${system_path}/build.prop
sed -i "s/H3113/H4113/g" ${system_path}/build.prop
sed -i "s/h3113/h4113/g" ${system_path}/vendor/build.prop
sed -i "s/H3113/H4113/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values h3113 h4113;
set_the_build_prop_device_model_values H3113 H4113;
# discovery
sed -i "s/h3213/h4213/g" ${system_path}/build.prop
sed -i "s/H3213/H4213/g" ${system_path}/build.prop
sed -i "s/h3213/h4213/g" ${system_path}/vendor/build.prop
sed -i "s/H3213/H4213/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values h3213 h4213;
set_the_build_prop_device_model_values H3213 H4213;
# voyager
sed -i "s/h3413/h4413/g" ${system_path}/build.prop
sed -i "s/H3413/H4413/g" ${system_path}/build.prop
sed -i "s/h3413/h4413/g" ${system_path}/vendor/build.prop
sed -i "s/H3413/H4413/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values h3413 h4413;
set_the_build_prop_device_model_values H3413 H4413;
# maple
sed -i "s/g8131/g8142/g" ${system_path}/build.prop
sed -i "s/G8131/G8142/g" ${system_path}/build.prop
sed -i "s/g8131/g8142/g" ${system_path}/vendor/build.prop
sed -i "s/G8131/G8142/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values g8131 g8142;
set_the_build_prop_device_model_values G8131 G8142;
# poplar
sed -i "s/g8341/g8342/g" ${system_path}/build.prop
sed -i "s/G8341/G8342/g" ${system_path}/build.prop
sed -i "s/g8341/g8342/g" ${system_path}/vendor/build.prop
sed -i "s/G8341/G8342/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values g8341 g8342;
set_the_build_prop_device_model_values G8341 G8342;
# dora
sed -i "s/f8131/f8132/g" ${system_path}/build.prop
sed -i "s/F8131/F8132/g" ${system_path}/build.prop
sed -i "s/f8131/f8132/g" ${system_path}/vendor/build.prop
sed -i "s/f8131/f8132/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values f8131 f8132;
set_the_build_prop_device_model_values F8131 F8132;
# kagura
sed -i "s/f8331/f8332/g" ${system_path}/build.prop
sed -i "s/F8331/F8332/g" ${system_path}/build.prop
sed -i "s/f8331/f8332/g" ${system_path}/vendor/build.prop
sed -i "s/F8331/F8332/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values f8331 f8332;
set_the_build_prop_device_model_values F8331 F8332;
# keyaki
sed -i "s/g8231/g8232/g" ${system_path}/build.prop
sed -i "s/G8231/G8232/g" ${system_path}/build.prop
sed -i "s/g8231/g8232/g" ${system_path}/vendor/build.prop
sed -i "s/G8231/G8232/g" ${system_path}/vendor/build.prop
set_the_build_prop_device_model_values g8231 g8232;
set_the_build_prop_device_model_values G8231 G8232;
# suzu
sed -i "s/f5121/f5122/g" ${system_path}/build.prop
sed -i "s/F5121/F5122/g" ${system_path}/build.prop
sed -i "s/f5121/f5122/g" ${system_path}/vendor/build.prop
sed -i "s/F5121/F5122/g" ${system_path}/vendor/build.prop
# VINTF manifest patching
# Add a second instance of every needed HAL
echo "Patching VINTF manifest"
sed -i -r 's/( +<(fqname|instance)>[^<>]*(slot)[^<>]*)1(<\/[^<>]+>)/\11\4\n\12\4/i' ${system_path}/vendor/etc/vintf/manifest.xml
sed -i -r 's/( +<(fqname|instance)>[^<>]*(hook|radio|ril|uim)[^<>]*)0(<\/[^<>]+>)/\10\4\n\11\4/i' ${system_path}/vendor/etc/vintf/manifest.xml
set_the_build_prop_device_model_values f5121 f5122;
set_the_build_prop_device_model_values F5121 F5122;
patch_VINTF_manifest;

Loading…
Cancel
Save