-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdohCloudflared.sh
120 lines (105 loc) · 3.58 KB
/
dohCloudflared.sh
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash -e
echo
echo "=== azadrah.org ==="
echo "=== https://github.com/azadrahorg ==="
echo "=== DOH Installer (Cloudflared Installer) ==="
echo
sleep 3
function exit_badly {
echo "$1"
exit 1
}
error() {
echo -e " \n $red Something Bad Happen $none \n "
}
DISTRO="$(awk -F= '/^NAME/{print tolower($2)}' /etc/os-release|awk 'gsub(/[" ]/,x) + 1')"
DISTROVER="$(awk -F= '/^VERSION_ID/{print tolower($2)}' /etc/os-release|awk 'gsub(/[" ]/,x) + 1')"
valid_os()
{
case "$DISTRO" in
"debiangnu/linux"|"ubuntu"|"centosstream")
return 0;;
*)
echo "OS $DISTRO is not supported"
return 1;;
esac
}
if ! valid_os "$DISTRO"; then
echo "Bye."
exit 1
else
[[ $(id -u) -eq 0 ]] || exit_badly "Please re-run as root (e.g. sudo ./path/to/this/script)"
fi
echo
echo "=== Update System ==="
echo
sleep 1
if [[ $DISTRO == "ubuntu" ]] || [[ $DISTRO == "debiangnu/linux" ]]; then
apt-get -o Acquire::ForceIPv4=true update
apt-get -o Acquire::ForceIPv4=true install -y software-properties-common
add-apt-repository --yes universe
add-apt-repository --yes restricted
add-apt-repository --yes multiverse
apt-get -o Acquire::ForceIPv4=true upgrade
apt-get -o Acquire::ForceIPv4=true install -y moreutils dnsutils tmux screen nano wget curl socat
else
dnf -y upgrade --refresh
dnf -y install epel-release
dnf -y install bind-utils tmux screen nano wget curl socat
fi
echo
echo "=== Configure Cloudflared ==="
echo
sleep 1
function deb_base {
mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
}
if [[ $DISTRO == "ubuntu" ]] && [[ $DISTROVER == "22.04" ]]; then
deb_base
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared jammy main' | tee /etc/apt/sources.list.d/cloudflared.list
apt-get update && apt-get install cloudflared
elif [[ $DISTRO == "ubuntu" ]] && [[ $DISTROVER == "20.04" ]]; then
deb_base
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared focal main' | tee /etc/apt/sources.list.d/cloudflared.list
apt-get update && apt-get install cloudflared
elif [[ $DISTRO == "debiangnu/linux" ]] && [[ $DISTROVER == "10" ]]; then
deb_base
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared buster main' | tee /etc/apt/sources.list.d/cloudflared.list
apt-get update && apt-get install cloudflared
elif [[ $DISTRO == "debiangnu/linux" ]] && [[ $DISTROVER == "11" ]]; then
deb_base
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared bullseye main' | tee /etc/apt/sources.list.d/cloudflared.list
apt-get update && apt-get install cloudflared
elif [[ $DISTRO == "centosstream" ]]; then
dnf config-manager --add-repo https://pkg.cloudflare.com/cloudflared-ascii.repo -y
dnf -y install cloudflared
else
error
fi
tee /etc/systemd/system/cloudflared-proxy-dns.service >/dev/null <<EOF
[Unit]
Description=DNS over HTTPS (DoH) proxy client
Wants=network-online.target nss-lookup.target
Before=nss-lookup.target
[Service]
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
DynamicUser=yes
ExecStart=/usr/local/bin/cloudflared proxy-dns
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now cloudflared-proxy-dns
rm -f /etc/resolv.conf
grep -Fq 'azadrah-org' /etc/resolv.conf || echo '
# https://github.com/azadrahorg
nameserver 127.0.0.1
nameserver 1.1.1.1
nameserver 2606:4700:4700::1111
' >> /etc/resolv.conf
echo
echo "=== Finished ==="
echo
sleep 1