mirror of
https://github.com/tanrax/maza-ad-blocking.git
synced 2024-11-22 15:15:41 +01:00
Fixbug OSX old sed
This commit is contained in:
parent
3792a97c53
commit
30c7cedd29
51
maza
51
maza
@ -4,6 +4,8 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# VARIABLES
|
# VARIABLES
|
||||||
|
NAME_OSX="Darwin"
|
||||||
|
THIS_OS=$(uname -mrs)
|
||||||
PROGNAME=$(basename $0)
|
PROGNAME=$(basename $0)
|
||||||
CONFIG=($HOME/.maza/)
|
CONFIG=($HOME/.maza/)
|
||||||
HOST_FILE=(/etc/hosts)
|
HOST_FILE=(/etc/hosts)
|
||||||
@ -17,6 +19,25 @@ PROJECT="### https://github.com/tanrax/maza-ad-blocking"
|
|||||||
AUTHOR="### Created by Andros Fenollosa (https://programadorwebvalencia.com/)"
|
AUTHOR="### Created by Andros Fenollosa (https://programadorwebvalencia.com/)"
|
||||||
END_TAG="## END MAZA"
|
END_TAG="## END MAZA"
|
||||||
|
|
||||||
|
|
||||||
|
# Create sed cross system
|
||||||
|
sed() {
|
||||||
|
if [[ $THIS_OS = *$NAME_OSX* ]]; then
|
||||||
|
# Check if OSX and install GSED
|
||||||
|
if [ -x "$(command -v gsed)" ]; then
|
||||||
|
gsed "$@"
|
||||||
|
else
|
||||||
|
echo "${COLOR_RED}ERROR. You must install gsed if you are using OSX${COLOR_RESET}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Linux
|
||||||
|
sed "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f sed
|
||||||
|
|
||||||
|
|
||||||
# FUNCTIONS
|
# FUNCTIONS
|
||||||
|
|
||||||
## HELP
|
## HELP
|
||||||
@ -50,31 +71,31 @@ status() {
|
|||||||
|
|
||||||
update() {
|
update() {
|
||||||
# Make conf folder
|
# Make conf folder
|
||||||
rm -f $CONFIG/$LIST
|
rm -f $CONFIG$LIST
|
||||||
rm -f $CONFIG/$LIST_DNSMASQ
|
rm -f $CONFIG$LIST_DNSMASQ
|
||||||
mkdir -p $CONFIG
|
mkdir -p $CONFIG
|
||||||
# Download DNS list
|
# Download DNS list
|
||||||
curl -L -s "https://pgl.yoyo.org/adservers/serverlist.php?showintro=0&mimetype=plaintext" -o "$CONFIG/$LIST"
|
curl -L -s "https://pgl.yoyo.org/adservers/serverlist.php?showintro=0&mimetype=plaintext" -o "$CONFIG$LIST"
|
||||||
# Clear list
|
# Clear list
|
||||||
## Remove comments
|
## Remove comments
|
||||||
sed -i.bak '/^#/ d' "$CONFIG/$LIST"
|
sed -i.bak '/^#/ d' "$CONFIG$LIST"
|
||||||
# Make dnsmasq format
|
# Make dnsmasq format
|
||||||
## 127.0.0.1 doubleclick.net to address=/doubleclick.net/127.0.0.1
|
## 127.0.0.1 doubleclick.net to address=/doubleclick.net/127.0.0.1
|
||||||
cp "$CONFIG/$LIST" "$CONFIG/$LIST_DNSMASQ"
|
cp "$CONFIG$LIST" "$CONFIG$LIST_DNSMASQ"
|
||||||
sed -i.bak 's/127.0.0.1 /address=\//g' "$CONFIG/$LIST_DNSMASQ"
|
sed -i.bak 's/127.0.0.1 /address=\//g' "$CONFIG$LIST_DNSMASQ"
|
||||||
sed -i.bak 's/$/\/127.0.0.1/g' "$CONFIG/$LIST_DNSMASQ"
|
sed -i.bak 's/$/\/127.0.0.1/g' "$CONFIG$LIST_DNSMASQ"
|
||||||
## Add start tag DNS list in first line
|
## Add start tag DNS list in first line
|
||||||
sed -i.bak "1i\\$AUTHOR" "$CONFIG/$LIST"
|
sed -i.bak "1i\\$AUTHOR" "$CONFIG$LIST"
|
||||||
sed -i.bak "1i\\$PROJECT" "$CONFIG/$LIST"
|
sed -i.bak "1i\\$PROJECT" "$CONFIG$LIST"
|
||||||
sed -i.bak "1i\\$START_TAG" "$CONFIG/$LIST"
|
sed -i.bak "1i\\$START_TAG" "$CONFIG$LIST"
|
||||||
## Add end tag DNS list in first line
|
## Add end tag DNS list in first line
|
||||||
echo $END_TAG >> "$CONFIG/$LIST"
|
echo $END_TAG >> "$CONFIG/$LIST"
|
||||||
## Add start tag DNS dnsmasq in first line
|
## Add start tag DNS dnsmasq in first line
|
||||||
sed -i.bak "1i\\$AUTHOR" "$CONFIG/$LIST_DNSMASQ"
|
sed -i.bak "1i\\$AUTHOR" "$CONFIG$LIST_DNSMASQ"
|
||||||
sed -i.bak "1i\\$PROJECT" "$CONFIG/$LIST_DNSMASQ"
|
sed -i.bak "1i\\$PROJECT" "$CONFIG$LIST_DNSMASQ"
|
||||||
sed -i.bak "1i\\$START_TAG" "$CONFIG/$LIST_DNSMASQ"
|
sed -i.bak "1i\\$START_TAG" "$CONFIG$LIST_DNSMASQ"
|
||||||
## Add end tag DNS DNSMASQ in first line
|
## Add end tag DNS DNSMASQ in first line
|
||||||
echo $END_TAG >> "$CONFIG/$LIST_DNSMASQ"
|
echo $END_TAG >> "$CONFIG$LIST_DNSMASQ"
|
||||||
# Remove temp file
|
# Remove temp file
|
||||||
rm "$CONFIG$LIST.bak"
|
rm "$CONFIG$LIST.bak"
|
||||||
rm "$CONFIG$LIST_DNSMASQ.bak"
|
rm "$CONFIG$LIST_DNSMASQ.bak"
|
||||||
@ -95,7 +116,7 @@ stop() {
|
|||||||
sudo sed -i -n "/$START_TAG/,/$END_TAG/d" "$HOST_FILE"
|
sudo sed -i -n "/$START_TAG/,/$END_TAG/d" "$HOST_FILE"
|
||||||
|
|
||||||
# Remove DNSMASQ
|
# Remove DNSMASQ
|
||||||
cat /dev/null > $CONFIG/$LIST_DNSMASQ
|
cat /dev/null > $CONFIG$LIST_DNSMASQ
|
||||||
|
|
||||||
# Notify user
|
# Notify user
|
||||||
echo "${COLOR_GREEN}DISABLED!${COLOR_RESET}"
|
echo "${COLOR_GREEN}DISABLED!${COLOR_RESET}"
|
||||||
|
Loading…
Reference in New Issue
Block a user