Hosts files are great

190 Views

If you have a computer, a hosts file is an absolute must. These handy files located where most system type files are kept can be used to prevent unwanted malware, ads, and other sites from attacking your computer.

The folks at https://github.com/StevenBlack/hosts have created a fine database source for maintaining and installing a hosts file for most operating systems. I strongly suggest checking it out.

On Linux, they created a python script for updating the hosts file. I in turn decided to create my own updating script using bash. Mainly as an exorcise in writing it. So here is my hosts file update script for Linux written in the bash shell.

#!/bin/bash
#---------------------------------
# hosts file updating script
# writen by bynw anlarye
# November 2016
#---------------------------------

# function to merge new hosts file into the system
mergehosts ()
{
mv /etc/hosts /etc/hosts.backup.$(date +"%Y%m%d")
mv hosts /etc/hosts
}

# script needs root access
if [[ $EUID -ne 0 ]]; then
echo "This script needs to be ran by root or with sudo"
exit 1
fi

# downloads latest version of main hosts file
while :
do
clear
echo "  Menu Options  "
echo ""
echo "[A] - The master hosts file"
echo "[B] - The master hosts file + gambling sites"
echo "[C] - The master hosts file + porn sites"
echo "[D] - The master hosts file + social media sites"
echo "[E] - The master hosts file + gambling & porn sites"
echo "[F] - The master hosts file + gambling & social media sites"
echo "[G] - The master hosts file + porn & social media sites"
echo "[H] - All hosts file sites"
echo "[X] - Exit Script"
echo ""
read -p "Please choose one of the above options [A-H or X] and press [ENTER]: " whichhosts
case $whichhosts in
a|A) wget -q --no-clobber https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
break ;;
b|B) wget -q --no-clobber https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling/hosts
break ;;
c|C) wget -q --no-clobber https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts
break ;;
d|D) wget -q --no-clobber https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/social/hosts
break ;;
e|E) wget -q --no-clobber https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-porn/hosts
break ;;
f|F) wget -q --no-clobber https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-social/hosts
break ;;
g|G) wget -q --no-clobber https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn-social/hosts
break ;;
h|H) wget -q --no-clobber https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-porn-social/hosts
break ;;
x|X) echo
echo "Host file will not be updated"
exit 1 ;;
*) sleep 1
clear
echo "Invalid responce."
echo "Please choose from [A-H or X]"
sleep 1 ;;
esac
done

# adds user defined custom hosts to file
sed -i '/Custom host records are listed here/r myhosts' hosts

# checks for existance of whitelist
if [ -f whitelist ]
then
grep -Fvxf whitelist hosts > hosts.tmp
mv hosts.tmp hosts
mergehosts
else
mergehosts
fi

echo
echo "Hosts file has been updated"
echo

exit 1

WordPress Script

181 Views

Hi all.

It’s been a busy time this summer so my posts have been very light as of late. But I thought I would go ahead and share with you a bash script for installing WordPress.

#!/bin/bash
#Created by Bynw Analrye
#Copyleft June 2013 AD

clear #clears screen for a fresh start

#Obtain Information for the WP Install
read -p "Linux User Account: " luan
read -p "Installation Path: " installdir
read -r -p "WP URL (mywebsite.com): " wpURL
read -p "MySQL Root Password: " -s msroot
echo ""
read -p "WP MySQL Username: " wpsqlun
read -p "WP MySQL Password: " -s wpsqlpw
echo ""
read -p "WP MySQL Database Name: " wpsqldbn

#Starting Install Proceedures
echo "Setting up the MySQL database"
echo "CREATE DATABASE $wpsqldbn;" | mysql -u root -p$msroot
echo "CREATE USER '$wpsqlun'@'localhost' IDENTIFIED BY '$wpsqlpw';" | mysql -u root -p$msroot
echo "GRANT ALL PRIVILEGES ON $wpsqldbn.* to '$wpsqlun'@'localhost';" | mysql -u root -p$msroot
echo "FLUSH PRIVILEGES;" | mysql -u root -p$msroot
echo "Successfully created $wpsqldbn MySQL database"

#Creating Apache Virtual Host
echo "

ServerName $wpURL

DocumentRoot $installdir

DirectoryIndex index.php
Options -Indexes FollowSymLinks
AllowOverride All

" > /etc/apache2/sites-available/$wpURL

#Creating the Directory, Download, Unpack & Install WordPress
echo "WP installation starting ... "
mkdir -p $installdir
wget -q "http://wordpress.org/latest.tar.gz" | tar --strip=1 -xzf latest.tar.gz -C $installdir
rm latest.tar.gz
echo "WP installation completed."

#Setting Permissions
usermod -a -G $luan www-data
chmod g+w $installdir
chmod -R g+w ${installdir}/wp-content

# Enable the site
a2ensite $wpURL
a2enmod rewrite
service apache2 restart
echo "Your WP site named $wpURL is now active"
echo "Please go to http://$wpURL or it's IP address and finish the installation"
echo "You will need the following information: "
echo "Your WordPress MySQL Database Name is: $wpsqldbn"
echo "Your WordPress MySQL Username is: $wpsqlun"
echo "Your WordPress MySQL Password is: $wpsqlpw"

#EOF