Skip to content

Commit

Permalink
scripts/action: optimize sed routine
Browse files Browse the repository at this point in the history
  • Loading branch information
backslashxx committed Dec 1, 2024
1 parent f71157f commit 7092085
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions module/action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ adblock() {
# how do i do this better?
for i in $(grep -v "#" $PERSISTENT_DIR/whitelist.txt); do echo "0.0.0.0 $i" ; done > $folder/tempwhitelist
# optimization thanks to Earnestly from #bash on libera, TIL something
# sed strip out everything with #, double space to single space, replace all 127.0.0.1 to 0.0.0.0
# sed strip out everything with #, double space to single space, replace all 127.0.0.1 to 0.0.0.0, remove \r (dos2unix)
# then sort uniq, then grep out whitelist.txt from it
sed '/#/d; s/ / /g; /^$/d; s/127.0.0.1/0.0.0.0/' $folder/temphosts | sort -u | grep -Fxvf $folder/tempwhitelist | busybox dos2unix >> $target_hostsfile
sed '/#/d; s/ / /g; /^$/d; s/127.0.0.1/0.0.0.0/; s|\r||' $folder/temphosts | sort -u | grep -Fxvf $folder/tempwhitelist >> $target_hostsfile
# mark it, will be read by service.sh to deduce
echo "# bindhosts v$versionCode" >> $target_hostsfile
}
Expand Down

0 comments on commit 7092085

Please sign in to comment.