2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								#!/usr/bin/env bash
 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-07 12:15:22 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-01 13:37:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# Copyright (c) 2021-2025 tteck 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-07 12:15:22 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# Author: tteck (tteckster) 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-04 17:54:20 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE 
							 
						 
					
						
							
								
									
										
										
										
											2025-09-10 14:41:25 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# Source: https://0xerr0r.github.io/blocky 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-07 12:15:22 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 14:20:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								source  /dev/stdin <<< " $FUNCTIONS_FILE_PATH " 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-22 20:48:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								color
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								verb_ip6
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								catch_errors
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								setting_up_container
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								network_check
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								update_os
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-23 06:59:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								fetch_and_deploy_gh_release "blocky"  "0xERR0R/blocky"  "prebuild"  "latest"  "/opt/blocky"  "blocky_*_Linux_x86_64.tar.gz" 
							 
						 
					
						
							
								
									
										
										
										
											2025-09-10 14:41:25 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								msg_info "Configuring Blocky" 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 14:20:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  systemctl is-active systemd-resolved >/dev/null 2>& 1;  then 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-13 13:07:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  systemctl disable -q --now systemd-resolved
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								cat <<EOF >/opt/blocky/config.yml
							 
						 
					
						
							
								
									
										
										
										
											2025-01-02 20:28:50 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# configuration documentation: https://0xerr0r.github.io/blocky/latest/configuration/ 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-02 20:28:50 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								upstreams:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  groups:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # these external DNS resolvers will be used. Blocky picks 2 random resolvers from the list for each query 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # format for resolver: [net:]host:[port][/path]. net could be empty (default, shortcut for tcp+udp), tcp+udp, tcp, udp, tcp-tls or https (DoH). If port is empty, default port will be used (53 for udp and tcp, 853 for tcp-tls, 443 for https (Doh)) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # this configuration is mandatory, please define at least one external DNS resolver 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    default:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      # Cloudflare 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      - 1.1.1.1
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      # Quad9 DNS-over-TLS server (DoT) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      - tcp-tls:dns.quad9.net
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-02 20:28:50 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# optional: use allow/denylists to block queries (for example ads, trackers, adult pages etc.) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								blocking:
							 
						 
					
						
							
								
									
										
										
										
											2025-01-02 20:28:50 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  # definition of denylist groups. Can be external link (http/https) or local file 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  denylists:
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    ads:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      - https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  # definition: which groups should be applied for which client 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  clientGroupsBlock:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # default will be used, if no special definition for a client name exists 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    default:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      - ads
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# optional: write query information (question, answer, client, duration etc.) to daily csv file 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								queryLog:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  # optional one of: mysql, postgresql, csv, csv-client. If empty, log to console 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-02 20:28:50 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  type:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# optional: use these DNS servers to resolve denylist urls and upstream DNS servers. It is useful if no system DNS resolver is configured, and/or to encrypt the bootstrap queries. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								bootstrapDns:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  - upstream: tcp-tls:one.one.one.one
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ips:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      - 1.1.1.1
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# optional: logging configuration 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								log:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  # optional: Log level (one from trace, debug, info, warn, error). Default: info 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  level: info
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								EOF
							 
						 
					
						
							
								
									
										
										
										
											2025-09-10 14:41:25 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								msg_ok "Configured Blocky" 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								msg_info "Creating Service" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								cat <<EOF >/etc/systemd/system/blocky.service
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								[ Unit] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Description = Blocky
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								After = network.target
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								[ Service] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								User = root
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								WorkingDirectory = /opt/blocky
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								ExecStart = /opt/blocky/./blocky --config config.yml
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								[ Install] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								WantedBy = multi-user.target
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								EOF
							 
						 
					
						
							
								
									
										
										
										
											2025-09-10 14:41:25 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$STD  systemctl enable  -q --now blocky
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								msg_ok "Created Service" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-22 20:48:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								motd_ssh
							 
						 
					
						
							
								
									
										
										
										
											2023-05-15 07:39:30 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								customize
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								msg_info "Cleaning up" 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-02 13:26:16 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$STD  apt-get -y autoremove
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								$STD  apt-get -y autoclean
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 11:29:14 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								msg_ok "Cleaned"