Skip to content

Commit fdc17b3

Browse files
Initial structural mockup
0 parents  commit fdc17b3

File tree

9 files changed

+146
-0
lines changed

9 files changed

+146
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
magiskmodule/module.prop
2+
magiskmodule/system
3+
magiskmodule/README.md
4+
hosts
5+
*.zip

.vscode/settings.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// editor and files config
3+
"editor.tabSize": 2,
4+
"editor.insertSpaces": true,
5+
"editor.formatOnSave": true,
6+
"editor.wordWrap": "off",
7+
"editor.detectIndentation": false,
8+
"editor.trimAutoWhitespace": true,
9+
"editor.autoIndent": "full",
10+
"editor.renderWhitespace": "trailing",
11+
"files.insertFinalNewline": true,
12+
"files.trimFinalNewlines": true,
13+
"files.trimTrailingWhitespace": true
14+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# MagicalProtection
2+
Magisk-only completely systemless adblocking

compile.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -e
3+
set -u
4+
set -o pipefail
5+
IFS=$'\n'
6+
renice -n 19 $$ &>/dev/null
7+
cd "$(dirname "$(readlink -f "$0")")"
8+
9+
[ -n "$(git status --porcelain)" ] && CHANGES="+" || CHANGES="-"
10+
VERSIONCODE=$(git rev-list --count HEAD)
11+
COMMITHASH=$(git log -1 --pretty=%h)
12+
VERSION=v$VERSIONCODE$CHANGES\($COMMITHASH\)
13+
FILENAME=MagicalProtection-$VERSION
14+
15+
declare -x VERSION VERSIONCODE
16+
envsubst < module.prop > magiskmodule/module.prop
17+
18+
cp -f README.md magiskmodule/README.md
19+
20+
./update.sh checkOutHosts
21+
22+
mkdir -p magiskmodule/system/etc
23+
cat hosts/* \
24+
| grep -v '^\s*#' \
25+
| sed -e '/^$/d' \
26+
| sort \
27+
| uniq \
28+
> magiskmodule/system/etc/hosts
29+
30+
./update.sh removeHosts
31+
32+
(
33+
cd magiskmodule
34+
zip -r -9 -q ../"$FILENAME" .
35+
)

lists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# adblocking hosts lists
2+
# format: name,url
3+
StevenBlack_hosts_unified,https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/sbin/sh
2+
3+
#################
4+
# Initialization
5+
#################
6+
7+
umask 022
8+
9+
# echo before loading util_functions
10+
ui_print() { echo "$1"; }
11+
12+
require_new_magisk() {
13+
ui_print "*******************************"
14+
ui_print " Please install Magisk v20.4+! "
15+
ui_print "*******************************"
16+
exit 1
17+
}
18+
19+
#########################
20+
# Load util_functions.sh
21+
#########################
22+
23+
OUTFD=$2
24+
ZIPFILE=$3
25+
26+
mount /data 2>/dev/null
27+
28+
[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk
29+
. /data/adb/magisk/util_functions.sh
30+
[ $MAGISK_VER_CODE -lt 20400 ] && require_new_magisk
31+
32+
install_module
33+
exit 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#MAGISK

module.prop

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
id=MagicalProtection
2+
name=MagicalProtection
3+
version=$VERSION
4+
versionCode=$VERSIONCODE
5+
author=programminghoch10
6+
description=Magisk-only completely systemless adblocking.
7+
updateJson=https://raw.githubusercontent.com/programminghoch10/MagicalProtection/deploy/update.json

update.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -e -u
3+
IFS=$'\n'
4+
5+
function checkOutHosts() {
6+
! git branch | grep -q hosts && git fetch origin hosts:hosts
7+
[ -d hosts ] && rm -rf hosts
8+
mkdir hosts
9+
git clone $(pwd) hosts
10+
cd hosts
11+
git fetch origin hosts:hosts
12+
git checkout hosts
13+
cd ..
14+
}
15+
16+
function removeHosts() {
17+
rm -rf hosts
18+
}
19+
20+
case "${1-}" in
21+
checkOutHosts)
22+
checkOutHosts
23+
exit
24+
;;
25+
removeHosts)
26+
removeHosts
27+
exit
28+
;;
29+
esac
30+
31+
$0 checkOutHosts
32+
33+
while read -r line; do
34+
grep -q '^\s*#' <<< "$line" && continue
35+
file=$(cut -d',' -f1 <<< "$line")
36+
url=$(cut -d',' -f2 <<< "$line")
37+
wget -O hosts/"$file" "$url"
38+
done < lists.txt
39+
(
40+
cd hosts
41+
git add .
42+
git commit -m "Update lists"
43+
git push
44+
)
45+
46+
$0 removeHosts

0 commit comments

Comments
 (0)