Skip to content

Commit

Permalink
feat: add server libvirt install script for debian servers
Browse files Browse the repository at this point in the history
  • Loading branch information
NichArchA82 authored Dec 15, 2024
1 parent af24cd4 commit 31d94eb
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions install-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
set -e

echo -e "\n\nEverything is now getting setup. This process will take a few minutes...\n\n"

sudo apt update && sudo apt install gpg jq -y && sudo apt clean

#remove unattended upgrades
sudo apt-get remove --purge unattended-upgrades || true

#Install tailscale
curl -fsSL https://tailscale.com/install.sh | sh

#Install nix package manager
sh <(curl -L https://nixos.org/nix/install) --daemon --yes

# Load the Nix environment
. /etc/profile.d/nix.sh

# Install packages from a pinned version of Nixpkgs
nix-env -iA \
-f https://github.com/NixOS/nixpkgs/archive/53f3c92b4d1f5f297258954c5026e39c45afd180.tar.gz \
libvirt qemu bridge-utils virt-manager dnsmasq

# Find the Nix-installed dnsmasq binary
DNSMASQ_BIN=$(which dnsmasq)
LIBVIRTD_BIN=$(which libvirtd)


if [[ -z "$DNSMASQ_BIN" || -z "$LIBVIRTD_BIN" ]]; then
echo "Error: One or both binaries (dnsmasq, libvirtd) not found after installation!"
exit 1
fi

# Create a systemd service for dnsmasq
echo "Creating systemd service for dnsmasq..."
sudo bash -c "cat > /etc/systemd/system/dnsmasq-nix.service" <<EOF
[Unit]
Description=DNS caching server (via Nix)
After=network.target
[Service]
ExecStart=$DNSMASQ_BIN --no-daemon
Restart=always
[Install]
WantedBy=multi-user.target
EOF

# Create a systemd service for libvirtd
echo "Creating systemd service for libvirtd..."
sudo bash -c "cat > /etc/systemd/system/libvirtd-nix.service" <<EOF
[Unit]
Description=Virtualization daemon (via Nix)
After=network.target
[Service]
ExecStart=$LIBVIRTD_BIN
Restart=always
[Install]
WantedBy=multi-user.target
EOF

# Reload systemd, enable, and start the service
echo "Enabling and starting dnsmasq service..."
sudo systemctl daemon-reload
sudo systemctl enable dnsmasq-nix libvirtd-nix
sudo systemctl start dnsmasq-nix libvirtd-nix

# Verify the service is running
echo "Checking dnsmasq service status..."
sudo systemctl status dnsmasq-nix --no-pager

echo "Checking libvirtd service status..."
sudo systemctl status libvirtd-nix --no-page

0 comments on commit 31d94eb

Please sign in to comment.