Skip to content

Commit d648af7

Browse files
committed
Action.sh + Redid Scripts
1 parent 566187f commit d648af7

File tree

8 files changed

+241
-33
lines changed

8 files changed

+241
-33
lines changed

action.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/system/bin/sh
2+
3+
echo " "
4+
echo " "
5+
echo " lll kk "
6+
echo "mm mm mmmm aa aa lll ww ww aa aa cccc kk kk "
7+
echo "mmm mm mm aa aaa lll ww ww aa aaa cc kkkkk "
8+
echo "mmm mm mm aa aaa lll ww ww ww aa aaa cc kk kk "
9+
echo "mmm mm mm aaa aa lll ww ww aaa aa ccccc kk kk "
10+
echo " "
11+
echo " By Person0z"
12+
echo " "
13+
14+
# === Define Paths ===
15+
MODDIR=${0%/*}
16+
HOSTS_FILE="$MODDIR/system/etc/hosts"
17+
TMP_DIR="/data/local/tmp"
18+
LOG_FILE="/data/adb/malwack.log"
19+
MERGED_HOSTS="/data/local/tmp/hosts"
20+
URLS_FILE="$MODDIR/urls.txt"
21+
22+
# === Logging Function ===
23+
log() {
24+
echo "[$(date '+%m-%d %H:%M')] $1" | tee -a "$LOG_FILE"
25+
}
26+
27+
# === Abort Function for Errors ===
28+
abort() {
29+
log "Error: $1"
30+
exit 1
31+
}
32+
33+
# === Download Hosts Files from `urls.txt` ===
34+
download_hosts() {
35+
log "Starting hosts download from $URLS_FILE..."
36+
if [ ! -f "$URLS_FILE" ]; then
37+
abort "URLs file not found at $URLS_FILE"
38+
fi
39+
40+
index=1
41+
while IFS= read -r url || [ -n "$url" ]; do
42+
# Skip empty lines and comments
43+
[[ "$url" =~ ^[[:space:]]*# ]] && continue
44+
[[ -z "$url" ]] && continue
45+
46+
target="$TMP_DIR/hosts$index"
47+
log "Downloading hosts file from $url..."
48+
curl -s "$url" -o "$target" || {
49+
log "Failed to download $url"
50+
continue
51+
}
52+
log "Downloaded hosts$index successfully."
53+
index=$((index + 1))
54+
done < "$URLS_FILE"
55+
}
56+
57+
# === Merge Hosts Files ===
58+
merge_hosts() {
59+
log "Merging downloaded hosts files..."
60+
cat "$TMP_DIR"/hosts* | grep -vE '^[[:space:]]*#' | grep -vE '^[[:space:]]*$' | sort | uniq > "$MERGED_HOSTS" || {
61+
log "Failed to merge hosts files"
62+
exit 1
63+
}
64+
log "Hosts files merged successfully."
65+
}
66+
67+
# === Apply Hosts File via Magisk Overlay ===
68+
apply_hosts_magisk() {
69+
log "Applying merged hosts file via Magisk overlay..."
70+
mkdir -p "$(dirname "$HOSTS_FILE")"
71+
cp "$MERGED_HOSTS" "$HOSTS_FILE" || {
72+
log "Failed to copy merged hosts file to $HOSTS_FILE"
73+
exit 1
74+
}
75+
chmod 644 "$HOSTS_FILE"
76+
chown root:root "$HOSTS_FILE"
77+
log "Merged hosts file applied successfully."
78+
}
79+
80+
# === Restart DNS Services ===
81+
restart_dns() {
82+
log "Restarting DNS services to apply the new hosts file..."
83+
setprop net.dns1 8.8.8.8
84+
setprop net.dns2 8.8.4.4
85+
log "DNS services restarted."
86+
}
87+
88+
# === Cleanup Temporary Files ===
89+
cleanup() {
90+
log "Cleaning up temporary files..."
91+
rm -f "$TMP_DIR"/hosts* "$MERGED_HOSTS"
92+
log "Temporary files cleaned successfully."
93+
}
94+
95+
# === Update Module Description ===
96+
update_module_prop() {
97+
MODULE_PROP="$MODDIR/module.prop"
98+
log "Updating module.prop with current date..."
99+
string="description=(Updated: $(date)) Ever wanted to get rid of those annoying ads that pop every 2 seconds in mobile games you're playing or websites you are visiting? Well, look no further with Malwack, your defense against ads!"
100+
sed -i "s/^description=.*/$string/g" "$MODULE_PROP"
101+
log "module.prop updated successfully."
102+
}
103+
104+
# === Main Logic ===
105+
log "Starting dynamic hosts update..."
106+
107+
# Download, Merge, and Apply Hosts
108+
download_hosts
109+
merge_hosts
110+
apply_hosts_magisk
111+
restart_dns
112+
cleanup
113+
update_module_prop
114+
115+
log "Dynamic hosts update completed successfully!"
116+
117+
echo ""
118+
echo "Hosts file updated successfully!"
119+
echo ""

changelog.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
1+
## v5.0.1
2+
- added action.sh
3+
- added urls.txt which will allow you to define your own custom files to download
4+
---
15
## v5.0.0
26
- Auto update every 24 hours applies after reboot
37
- Added service.sh to setup cron
48
- Added logging
59
- Updated hosts file
610
- Removed added commands using built-in BusyBox
7-
11+
---
812
## v4.2.8
913
- Updated hosts file
10-
14+
---
1115
## v4.2.7
1216
- Updated hosts file
13-
17+
---
1418
## v4.2.6
1519
- Updated hosts file
16-
20+
---
1721
## v4.2.5
1822
- Updated hosts file
19-
23+
---
2024
## v4.2.4
2125
- Updated hosts file
22-
26+
---
2327
## v4.2.3
2428
- Updated hosts file
25-
29+
---
2630
## v4.2.2
2731
- Updated hosts file
32+
---
2833
## v4.2.1
2934
- Fixed the help command adding the ``whitelist`` command on it.
35+
---
3036
## v4.2
3137
- Updated Hosts file and added a new hosts link
3238
---

customize.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set_permissions() {
33
set_perm $MODPATH/system/etc/hosts root root 0777 # -rwxrwxrwx
44
set_perm $MODPATH/system/bin/malwack root root 0777 # -rwxrwxrwx
55
set_perm $MODPATH/system/bin/au root root 0777 # -rwxrwxrwx
6+
set_perm $MODPATH/action.sh root root 0777 # -rwxrwxrwx
67
}
78

89
# Allow all the scripts to be executable

install.zip

14.1 KB
Binary file not shown.

module.prop

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
id=Malwack
22
name=Malwack | Anti-Malware & Ad Blocker
3-
version=v5.0.0
4-
versionCode=26
3+
version=v5.0.1
4+
versionCode=27
55
author=Person0z
6-
description=Say goodbye to unwanted digital pests and send malware running with Malwack, your virtual fly swatter for the cyber world. It's like having a bouncer for your device – no entry for malware, bugs, or party crashers!
6+
description=Ever wanted to get rid of those annoying ads that pop every 2 seconds in mobile games you're playing or websites you are visiting? Well, look no further with Malwack, your defense against ads!
77
updateJson=https://raw.githubusercontent.com/Magisk-Modules-Alt-Repo/Malwack/main/update.json

system/bin/au

Lines changed: 100 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,108 @@
11
#!/system/bin/sh
22

3-
# Define paths
4-
hosts_file="/data/adb/modules/Malwack/system/etc/hosts"
5-
tmp_dir="/data/local/tmp"
6-
log_file="/data/adb/malwack.log"
7-
merged_hosts="/data/local/tmp/hosts"
3+
# === Define Paths ===
4+
HOSTS_FILE="$MODDIR/system/etc/hosts"
5+
TMP_DIR="/data/local/tmp"
6+
LOG_FILE="/data/adb/malwack.log"
7+
MERGED_HOSTS="/data/local/tmp/hosts"
8+
URLS_FILE="/data/adb/modules/Malwack/urls.txt"
89

9-
# External Hosts URLs
10-
URL1="https://hosts.ubuntu101.co.za/hosts"
11-
URL2="https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
12-
URL3="https://www.github.developerdan.com/hosts/lists/ads-and-tracking-extended.txt"
10+
# === Logging Function ===
11+
log() {
12+
echo "[$(date '+%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
13+
}
1314

14-
# Download and combine hosts files
15-
echo "Downloading and merging hosts files..." >> "$log_file"
16-
curl -s "$URL1" > "$tmp_dir/hosts1" || { echo "Failed to download URL1" >> "$log_file"; exit 1; }
17-
curl -s "$URL2" > "$tmp_dir/hosts2" || { echo "Failed to download URL2" >> "$log_file"; exit 1; }
18-
curl -s "$URL3" > "$tmp_dir/hosts3" || { echo "Failed to download URL3" >> "$log_file"; exit 1; }
15+
# === Abort Function for Critical Errors ===
16+
abort() {
17+
log "Error: $1"
18+
exit 1
19+
}
1920

20-
# Merge hosts files into a temporary file
21-
cat "$tmp_dir/hosts1" "$tmp_dir/hosts2" "$tmp_dir/hosts3" >> hosts
21+
# === Download Hosts Files from `urls.txt` ===
22+
download_hosts() {
23+
log "Starting hosts download from $URLS_FILE..."
24+
25+
if [ ! -f "$URLS_FILE" ]; then
26+
abort "URLs file not found at $URLS_FILE"
27+
fi
28+
29+
index=1
30+
while IFS= read -r url || [ -n "$url" ]; do
31+
# Skip empty lines and comments
32+
case "$url" in
33+
\#* | "") continue ;; # Skip lines starting with '#' or empty lines
34+
esac
35+
36+
target="$TMP_DIR/hosts$index"
37+
log "Downloading hosts file from $url..."
38+
curl -s "$url" -o "$target" || {
39+
log "Failed to download $url"
40+
continue
41+
}
42+
log "Downloaded hosts$index successfully."
43+
index=$((index + 1))
44+
done < "$URLS_FILE"
45+
46+
if [ $index -eq 1 ]; then
47+
abort "No valid URLs found in $URLS_FILE"
48+
fi
49+
}
2250

23-
cat $tmp_dir/hosts >> $hosts_file
51+
# === Merge Hosts Files ===
52+
merge_hosts() {
53+
log "Merging downloaded hosts files..."
54+
cat "$TMP_DIR"/hosts* | grep -vE '^[[:space:]]*#' | grep -vE '^[[:space:]]*$' | sort | uniq > "$MERGED_HOSTS" || {
55+
log "Failed to merge hosts files"
56+
exit 1
57+
}
58+
log "Hosts files merged successfully."
59+
}
2460

25-
# Clean up temporary files
26-
rm "$tmp_dir/hosts1" "$tmp_dir/hosts2" "$tmp_dir/hosts3"
61+
# === Apply Merged Hosts File via Magisk Overlay ===
62+
apply_hosts_magisk() {
63+
log "Applying merged hosts file via Magisk overlay..."
64+
mkdir -p "$(dirname "$HOSTS_FILE")"
65+
cp "$MERGED_HOSTS" "$HOSTS_FILE" || {
66+
log "Failed to copy merged hosts file to $HOSTS_FILE"
67+
exit 1
68+
}
69+
chmod 644 "$HOSTS_FILE"
70+
chown root:root "$HOSTS_FILE"
71+
log "Merged hosts file applied successfully."
72+
}
2773

28-
# Final log message
29-
echo "Hosts file updated successfully with permissions!" >> "$log_file"
74+
# === Cleanup Temporary Files ===
75+
cleanup() {
76+
log "Cleaning up temporary files..."
77+
rm -f "$TMP_DIR"/hosts* "$MERGED_HOSTS"
78+
log "Temporary files cleaned successfully."
79+
}
80+
81+
# === Update Module Description ===
82+
update_module_prop() {
83+
MODULE_PROP="$MODDIR/module.prop"
84+
log "Updating module.prop with current date..."
85+
string="description=(Updated: $(date)) Ever wanted to get rid of those annoying ads that pop every 2 seconds in mobile games you're playing or websites you are visiting? Well, look no further with Malwack, your defense against ads!"
86+
sed -i "s/^description=.*/$string/g" "$MODULE_PROP"
87+
log "module.prop updated successfully."
88+
}
89+
90+
# === Main Logic ===
91+
log "Starting dynamic hosts update..."
92+
93+
# Ensure Root Permissions
94+
if [ "$(id -u)" -ne 0 ]; then
95+
abort "Root access is required to run this script."
96+
fi
97+
98+
# Download, Merge, and Apply Hosts
99+
download_hosts
100+
merge_hosts
101+
apply_hosts_magisk
102+
cleanup
103+
update_module_prop
104+
105+
log "Dynamic hosts update completed successfully!"
106+
echo ""
107+
echo "Hosts file updated successfully!"
108+
echo ""

update.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"version": "v5.0.0",
3-
"versionCode": 26,
2+
"version": "v5.0.1",
3+
"versionCode": 27,
44
"zipUrl": "https://github.com/Person0z/Malwack/raw/main/install.zip",
55
"changelog": "https://raw.githubusercontent.com/Person0z/Malwack/main/changelog.md"
66
}

urls.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://hosts.ubuntu101.co.za/hosts
2+
https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
3+
https://www.github.developerdan.com/hosts/lists/ads-and-tracking-extended.txt

0 commit comments

Comments
 (0)