summarylogtreecommitdiffstats
path: root/stevenblack
blob: 7c5fcf11c0265afdb9ba9a71f42cb9825e0d891f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash

# Downloads and updates hosts from Steven Black.

readonly hostsource="https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
readonly tmpfile=/tmp/hosts
readonly hostsfile=/etc/hosts

if ! [[ -w $hostsfile ]]; then
	echo "Can't write to $hostsfile. Check your permissions."
	exit 1
fi

rm -- "$tmpfile" 2>/dev/null

if ! curl --max-time 60 -sL --fail "$hostsource" -o "$tmpfile"; then
	echo "Couldn't download from $hostsource to $tmpfile. Check your internet connection."
	exit 1
fi

{
	echo "# NOTE: Written by $0 on $(date '+%c')"
	cat -- "$tmpfile"
} > "$hostsfile"

echo "$hostsfile has been updated successfully."

rm -- "$tmpfile"