Skip to content

Instantly share code, notes, and snippets.

@PhoenixAceVFX
Last active April 15, 2025 02:03
Show Gist options
  • Save PhoenixAceVFX/51a245af5abb247b86a50d3d6a75cd86 to your computer and use it in GitHub Desktop.
Save PhoenixAceVFX/51a245af5abb247b86a50d3d6a75cd86 to your computer and use it in GitHub Desktop.
Arch Linux Pihole Script
#!/bin/bash
# Pi-hole installation script for Arch Linux
# This script must be run as root
# Check if script is run as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root" >&2
exit 1
fi
# Function to check command status
check_status() {
if [ $? -eq 0 ]; then
echo "[✓] $1"
else
echo "[✗] $1 failed"
exit 1
fi
}
# Update system first
echo "Updating system..."
pacman -Syu --noconfirm
check_status "System update"
# Install required dependencies
echo "Installing dependencies..."
pacman -S --needed --noconfirm \
curl \
wget \
git \
base-devel \
lighttpd \
php \
php-sqlite \
php-cgi \
php-fpm \
sqlite \
dnsmasq \
sudo \
netcat \
iproute2 \
psmisc \
which \
cronie \
logrotate \
bind
check_status "Dependencies installation"
# Configure PHP
echo "Configuring PHP..."
sed -i 's/;extension=pdo_sqlite/extension=pdo_sqlite/' /etc/php/php.ini
sed -i 's/;extension=sqlite3/extension=sqlite3/' /etc/php/php.ini
sed -i 's/;extension=bcmath/extension=bcmath/' /etc/php/php.ini
sed -i 's/;extension=curl/extension=curl/' /etc/php/php.ini
sed -i 's/;extension=openssl/extension=openssl/' /etc/php/php.ini
check_status "PHP configuration"
# Configure lighttpd
echo "Configuring lighttpd..."
cat > /etc/lighttpd/conf.d/fastcgi.conf << 'EOF'
fastcgi.server = (
".php" => ((
"socket" => "/run/php-fpm/php-fpm.sock",
"broken-scriptfilename" => "enable"
))
)
EOF
# Enable required modules in lighttpd
sed -i 's/"mod_fastcgi"/"mod_fastcgi","mod_rewrite"/' /etc/lighttpd/modules.conf
check_status "Lighttpd configuration"
# Start and enable services
echo "Starting services..."
systemctl enable --now php-fpm
systemctl enable --now lighttpd
systemctl enable --now cronie
check_status "Services startup"
# Create necessary directories
echo "Creating directories..."
mkdir -p /etc/pihole
mkdir -p /var/www/html
chmod 755 /var/www/html
check_status "Directory creation"
# Clone Pi-hole repository
echo "Cloning Pi-hole repositories..."
cd /tmp
git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole
git clone --depth 1 https://github.com/pi-hole/AdminLTE.git pi-hole/AdminLTE
check_status "Repository cloning"
# Set up Pi-hole
echo "Setting up Pi-hole..."
cd Pi-hole/automated\\ install/
# Create setupVars.conf with default values
cat > /etc/pihole/setupVars.conf << 'EOF'
PIHOLE_INTERFACE=eth0
IPV4_ADDRESS=127.0.0.1
IPV6_ADDRESS=::1
PIHOLE_DNS_1=8.8.8.8
PIHOLE_DNS_2=8.8.4.4
DNS_FQDN_REQUIRED=true
DNS_BOGUS_PRIV=true
DNSMASQ_LISTENING=local
BLOCKINGMODE=NULL
INSTALL_WEB_SERVER=true
INSTALL_WEB_INTERFACE=true
LIGHTPD_ENABLED=true
WEBTHEME=default-darker
EOF
# Run basic-install.sh with ARCH=1 to skip package installation
ARCH=1 bash basic-install.sh --unattended
check_status "Pi-hole installation"
# Configure dnsmasq
echo "Configuring dnsmasq..."
systemctl stop dnsmasq
systemctl disable dnsmasq
systemctl enable pihole-FTL
systemctl start pihole-FTL
check_status "DNS configuration"
echo ""
echo "Pi-hole installation completed!"
echo "You can access the admin interface at http://localhost/admin"
echo "To set an admin password, run: pihole -a -p"
echo "Note: You may need to configure your network settings to use Pi-hole as your DNS server"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment