Kawaii Ninja

Shell Scripting To Save Time

Bash, a shell which most of the Linux users use everyday. I have been using Linux since 2017, but never made an attempt to learn and write a shell script of my own. I learned to create shell scripts from my classes, where we had to create small programs taking user inputs. Since then, I been writing shell scripts to do small things here and there, which saved some of my time.

Now coming to major task, I have a Magisk module which blocks advertisements, using combination of various hosts files found on the internet. At first I started off with manually editing and adding new content to the host file, which was a time consuming process. My module’s project repository, started getting stared quickly, but I wasn’t updating it in a timely manner, due the fact that it was taking a lot of time of mine.

But, one day I got this sudden idea while watching Bugswriter latest video, that I could use shell scripting to save my time and update my module on weekly manner, and it worked. After spending 2 hours and lot of ducking (I use duckduckgo, so ducking instead of googling) I finally managed to create a script which creates a module zip file in less than 30 seconds, which is insane.

My shell script

#!/bin/bash
echo "Creating host file"
wget https://hosts.oisd.nl/
mv index.html hosts
wget https://block.energized.pro/porn/formats/hosts
sed '1,78d' hosts.1 >> hosts
rm hosts.1
echo "Host file created"
cp -u hosts ZIP/system/etc/
cd ZIP
read -p "What is version number? " version_no
echo "id=SH_Blocker
name=BlockADs
version=v$version_no
versionCode=7
author=Kninja
description=Say Goodbye To Ads Forever" > module.prop
zip -r BlockAds-v$version_no.zip *
mv BlockAds-v$version_no.zip /home/joel/blockads/
cd ..
cp -u hosts /home/joel/repos/Magisk-Ad-Blocking-Module
rm hosts
echo "Magisk Build Done"

So, that’s it for now. If you use Magisk on your phone, consider using the my module, it’s not something new, but hey, it works after installing.

#100DaysToOffload #Linux