Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #1

Merged
merged 7 commits into from
Dec 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 32 additions & 50 deletions pif.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,63 +1,45 @@
#!/bin/bash

# RSS Feed URL
url="https://sourceforge.net/projects/xiaomi-eu-multilang-miui-roms/rss?path=/xiaomi.eu/Xiaomi.eu-app"

# Fetch RSS feed and extract the last link
lastLink=$(curl -s "https://sourceforge.net/projects/xiaomi-eu-multilang-miui-roms/rss?path=/xiaomi.eu/Xiaomi.eu-app" | grep -oP '<link>\K[^<]+' | head -2 | tail -1)

# Output the last link
wget --user-agent="Wget" "$lastLink" -O xiaomi.apk

apktool d xiaomi.apk -o Extractedapk -f

# Function to set variable to "null" if empty
set_to_null() {
if [ -z "$1" ]; then
echo "null"
else
echo "$1"
fi
get_value() {
value="$(grep "$1" "${fields_file}" | sed 's/.*value="\([^"]*\)".*/\1/' | sed 's/" \/>//')"
echo "${value:-null}"
}

# Assign values to variables
var_MANUFACTURER=$(grep 'MANUFACTURER' Extractedapk/res/xml/inject_fields.xml | sed 's/.*value="\([^"]*\)".*/\1/' | sed 's/" \/>//')
var_BRAND=$(grep 'BRAND' Extractedapk/res/xml/inject_fields.xml | sed 's/.*value="\([^"]*\)".*/\1/' | sed 's/" \/>//')
var_DEVICE=$(grep 'DEVICE' Extractedapk/res/xml/inject_fields.xml | sed 's/.*value="\([^"]*\)".*/\1/' | sed 's/" \/>//')
var_PRODUCT=$(grep 'PRODUCT' Extractedapk/res/xml/inject_fields.xml | sed 's/.*value="\([^"]*\)".*/\1/' | sed 's/" \/>//')
var_MODEL=$(grep 'MODEL' Extractedapk/res/xml/inject_fields.xml | sed 's/.*value="\([^"]*\)".*/\1/' | sed 's/" \/>//')
var_FINGERPRINT=$(grep 'FINGERPRINT' Extractedapk/res/xml/inject_fields.xml | sed 's/.*value="\([^"]*\)".*/\1/' | sed 's/" \/>//')
var_SECURITY_PATCH=$(grep 'SECURITY_PATCH' Extractedapk/res/xml/inject_fields.xml | sed 's/.*value="\([^"]*\)".*/\1/' | sed 's/" \/>//')
var_FIRST_API_LEVEL=$(grep 'FIRST_API_LEVEL' Extractedapk/res/xml/inject_fields.xml | sed 's/.*value="\([^"]*\)".*/\1/' | sed 's/" \/>//')

# Set variables to "null" if empty
var_MANUFACTURER=$(set_to_null "$var_MANUFACTURER")
var_BRAND=$(set_to_null "$var_BRAND")
var_DEVICE=$(set_to_null "$var_DEVICE")
var_PRODUCT=$(set_to_null "$var_PRODUCT")
var_MODEL=$(set_to_null "$var_MODEL")
var_FINGERPRINT=$(set_to_null "$var_FINGERPRINT")
var_SECURITY_PATCH=$(set_to_null "$var_SECURITY_PATCH")
var_FIRST_API_LEVEL=$(set_to_null "$var_FIRST_API_LEVEL")

SERVICE_FILE="pif.json"

# Create the json file
create_json() {
cat << EOF > ${SERVICE_FILE}
cat <<EOF >"${service_file}"
{
"PRODUCT": "${var_PRODUCT}",
"DEVICE": "${var_DEVICE}",
"MANUFACTURER": "${var_MANUFACTURER}",
"BRAND": "${var_BRAND}",
"MODEL": "${var_MODEL}",
"FINGERPRINT": "${var_FINGERPRINT}",
"SECURITY_PATCH": "${var_SECURITY_PATCH}",
"FIRST_API_LEVEL": "${var_FIRST_API_LEVEL}"
"PRODUCT": "$(get_value PRODUCT)",
"DEVICE": "$(get_value DEVICE)",
"MANUFACTURER": "$(get_value MANUFACTURER)",
"BRAND": "$(get_value BRAND)",
"MODEL": "$(get_value MODEL)",
"FINGERPRINT": "$(get_value FINGERPRINT)",
"SECURITY_PATCH": "$(get_value SECURITY_PATCH)",
"FIRST_API_LEVEL": "$(get_value FIRST_API_LEVEL)"
}
EOF
}

# RSS Feed URL
url="https://sourceforge.net/projects/xiaomi-eu-multilang-miui-roms/rss?path=/xiaomi.eu/Xiaomi.eu-app"

tmp_dir="$(mktemp -d)"
apk_file="${tmp_dir}/xiaomi.apk"
extracted_apk="${tmp_dir}/Extractedapk"
service_file="pif.json"
fields_file="${extracted_apk}/res/xml/inject_fields.xml"

trap 'rm -rf "${tmp_dir}"' EXIT

# Fetch RSS feed and extract the last link
lastLink=$(curl --silent --show-error "${url}" | grep -oP '<link>\K[^<]+' | head -2 | tail -1)

# Output the last link
curl --silent --show-error --location --output "${apk_file}" "${lastLink}"

apktool d "${apk_file}" -o "${extracted_apk}" -f

create_json

cat pif.json
cat "${service_file}"