Homelab notes
Homelab setup using a Raspberry Pi.
Setup
- DietPi
- PiHole
- Nginx
- Homer
- yt-dlp
- Navidrome
- Beets
Flashing a SD card
I used a custom script (source) to select the inserted card and write the .iso or .img file to it. In this case, I used Dietpi. (Note the script is made for personal use and might not be safe to use if you don’t know what you are doing)
I inserted the card in the rpi and connected it to my router using an RJ45 cable, then I booted it up and found its local IP from the router webpage (192.168.18.1 in my case, you may try 192.168.1.1).
You will need to log in for the first time as root for the initial installation using the Dietpi Launcher. Above is the software I have downloaded during this launch, that I use in other snippets here.
Configuring quick SSH access
cd ~/.ssh; shh-keygento create new key pair in your laptop.ssh-copy-id -i <public_key> <raspberrypi_ip>to- Create a
~/.ssh/configfile in your laptop and addHost homelab HostName <your_homelab_ip> User dietpi IdentityFile ~/.ssh/<private_key>
Now you can just ssh homelab directly into your rpi.
Synchronize local working directory with the server
rsync -avz --delete --exclude=".git" . homelab:<route_in_server>
Setting PiHole as a custom DNS Server on Manjaro:
I couldn’t set a custom DNS server on my router, so I had to manually configure it on my laptop.
sudo nano /etc/resolvconf.conf
And then add an entry like this:
name_servers=<raspberrypi_ip>
- Reference: https://wiki.manjaro.org/index.php/Networking
Giving the server a local domain name
Open the PiHole local service from a browser, go to the Settings > Local DNS and add an entry with your chosen domain name (homelab.lan, for example) pointing to the <raspberrypi_ip>.
Important: Don’t use the .local TLD (top level domain) because it can be problematic to resolve in some systems.
Creating self signed certificate and keys
It’s important that the Common Name matches your domain name.
- Reference: https://linuxconfig.org/how-to-generate-a-self-signed-ssl-certificate-on-linux
To Do: I need to understand how to use Let’s Encrypt for this. Self signed certificates are not trusted by any browser or client (like curl).
To Do: Include example of nginx configuration to use SSL
Adding a subdomain to the server
- Add a local DNS entry to the same IP
- Add a site to nginx sites-available and proxy redirect or set root
If you change this configuration after accesing some subdomain, you might need to delete the browser’s local storage to prevent caching issues. Quickly verify this changes in incognito mode to prevent cache issues.
Script to send messages as Telegram Bot
/usr/bin/telegram_send
/usr/bin/telegram_send
#!/usr/bin/bash
source /etc/telegram.conf
MESSAGE="$1"
case "$1" in
""|"-h"|"--help")
echo "Usage: $0 MESSAGE"
;;
*)
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_API_TOKEN/sendMessage" \
-d chat_id="$TELEGRAM_CHAT_ID" \
-d text="$MESSAGE" \
-d parse_mode="Markdown" \
> /dev/null
;;
esac
TODO: Explain how to get API_KEY and CHAT_ID.
A good security practice is to restrict the permissions over the configuration file, containing the API key:
sudo groupadd telegram
sudo chown root:telegram /etc/telegram.conf
sudo chmod 640 /etc/telegram.conf
sudo usermod -aG telegram dietpi
User pretty URLs
- Reference: https://serverfault.com/questions/189431/how-can-i-configure-nginx-to-use-pretty-urls-for-static-sites
Music server
Installation and configuration
Both Navidrome and Beets, installed via dietpi-software, store their data and config files in /mnt/dietpi_userdata/ and use by default the /mnt/dietpi_userdata/Music library.
Configure Beets in /mnt/dietpi_userdata/beets/config.yaml:
directory: /mnt/dietpi_userdata/Music
library: /mnt/dietpi_userdata/beets/library.db
plugins: fetchart embedart chroma
import:
write: yes
move: yes
Note: This prevents files from being copied during import to save space, but make sure to change it to suit your needs.
Install this dependencies before using beet:
pip install requests pyacoustid
Add new music
Instead of moving anything into the music library directly, use
beet -qa import <directory_with_music>
It will move (or copy if you changed your configuration) the files into the music library, after embedding the metadata extracted from the MusicBrainz database. This sometimes works directly, but sometimes you will see a Skipped message. This means you need to use:
beet import <directory_with_music>
To choose some options manually because Beets is not able to choose confidently.
yt-dlp playlist download script
Use this script only if you have the required rights.
Install yt-dlp with dietpi-software. This is a script that tries to optimize the download format to be imported with Beets.
url="$1"
dir="~/music_inbox"
mkdir -p "$dir"
/usr/local/bin/yt-dlp --yes-playlist -x \
--audio-format mp3 \
--embed-metadata \
--parse-metadata "%(title)s:%(artist)s - %(title)s" \
-o "$dir/%(uploader)s/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s" \
"$url"
/usr/bin/beet import -qa "$dir"
Remove music
Neither Navidrome or Beets provide a method to remove music from your library (not that I know), so you have to visit the directory manually and rm it. Afterwards, you must go to Navidrome Missing files menu and click Remove all.