Skip to content

Commit

Permalink
Initial structural mockup
Browse files Browse the repository at this point in the history
  • Loading branch information
programminghoch10 committed Aug 22, 2023
0 parents commit fdc17b3
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
magiskmodule/module.prop
magiskmodule/system
magiskmodule/README.md
hosts
*.zip
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// editor and files config
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.formatOnSave": true,
"editor.wordWrap": "off",
"editor.detectIndentation": false,
"editor.trimAutoWhitespace": true,
"editor.autoIndent": "full",
"editor.renderWhitespace": "trailing",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# MagicalProtection
Magisk-only completely systemless adblocking
35 changes: 35 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -e
set -u
set -o pipefail
IFS=$'\n'
renice -n 19 $$ &>/dev/null
cd "$(dirname "$(readlink -f "$0")")"

[ -n "$(git status --porcelain)" ] && CHANGES="+" || CHANGES="-"
VERSIONCODE=$(git rev-list --count HEAD)
COMMITHASH=$(git log -1 --pretty=%h)
VERSION=v$VERSIONCODE$CHANGES\($COMMITHASH\)
FILENAME=MagicalProtection-$VERSION

declare -x VERSION VERSIONCODE
envsubst < module.prop > magiskmodule/module.prop

cp -f README.md magiskmodule/README.md

./update.sh checkOutHosts

mkdir -p magiskmodule/system/etc
cat hosts/* \
| grep -v '^\s*#' \
| sed -e '/^$/d' \
| sort \
| uniq \
> magiskmodule/system/etc/hosts

./update.sh removeHosts

(
cd magiskmodule
zip -r -9 -q ../"$FILENAME" .
)
3 changes: 3 additions & 0 deletions lists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# adblocking hosts lists
# format: name,url
StevenBlack_hosts_unified,https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
33 changes: 33 additions & 0 deletions magiskmodule/META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/sbin/sh

#################
# Initialization
#################

umask 022

# echo before loading util_functions
ui_print() { echo "$1"; }

require_new_magisk() {
ui_print "*******************************"
ui_print " Please install Magisk v20.4+! "
ui_print "*******************************"
exit 1
}

#########################
# Load util_functions.sh
#########################

OUTFD=$2
ZIPFILE=$3

mount /data 2>/dev/null

[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk
. /data/adb/magisk/util_functions.sh
[ $MAGISK_VER_CODE -lt 20400 ] && require_new_magisk

install_module
exit 0
1 change: 1 addition & 0 deletions magiskmodule/META-INF/com/google/android/updater-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#MAGISK
7 changes: 7 additions & 0 deletions module.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id=MagicalProtection
name=MagicalProtection
version=$VERSION
versionCode=$VERSIONCODE
author=programminghoch10
description=Magisk-only completely systemless adblocking.
updateJson=https://raw.githubusercontent.com/programminghoch10/MagicalProtection/deploy/update.json
46 changes: 46 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
set -e -u
IFS=$'\n'

function checkOutHosts() {
! git branch | grep -q hosts && git fetch origin hosts:hosts
[ -d hosts ] && rm -rf hosts
mkdir hosts
git clone $(pwd) hosts
cd hosts
git fetch origin hosts:hosts
git checkout hosts
cd ..
}

function removeHosts() {
rm -rf hosts
}

case "${1-}" in
checkOutHosts)
checkOutHosts
exit
;;
removeHosts)
removeHosts
exit
;;
esac

$0 checkOutHosts

while read -r line; do
grep -q '^\s*#' <<< "$line" && continue
file=$(cut -d',' -f1 <<< "$line")
url=$(cut -d',' -f2 <<< "$line")
wget -O hosts/"$file" "$url"
done < lists.txt
(
cd hosts
git add .
git commit -m "Update lists"
git push
)

$0 removeHosts

0 comments on commit fdc17b3

Please sign in to comment.