Bash Cleaning the Movie Folder

Here is another script to help clean up movie folders.  Until recently, I preferred having all of my movies in the same directory.  After switching to Plex Media Server, I soon realized that Plex downloads fanart and other related movie files.  The issue is that all of these additional files were also in the main movie directory.  The following script went through and created a sub-directory for each movie name and then the second half moved the files into their respective folder.

$ for i in `find . -maxdepth 1 -type f -printf '%f\n' |sed "s/^\(.*\)\..*$/\1/"`; do mkdir $i; done

and then

$ for i in `find . -maxdepth 1 -type f -printf '%f\n' |sed "s/^\(.*\)\..*$/\1/"`; do mv $i* $i; done

There is probably a more efficient way to tackle this issue, but this seemed to work perfectly fine for me!

Caddy 2 Web Server Configuration

I run a multitude of services from my network. Having the ability to configure a simple and secure web server is an absolute necessity. Until recently, I have always continually bounced between Lighttpd and Nginx. Nginx seemed more secure, but the configurations could be similar to setting up an apache server. Lighttpd had some issues using weird header information and the documentation was lacking. I had a lot of issues with Cockpit and Lighttpd, and the community seemed to be lacking when it came to user support.

I recently stumbled upon Caddy as a possibility (which worked out well). I was a bit skeptical about this one as it seemed to be one of the ‘new kids on the block’ in terms of web servers.

After installing, I realized that the documentation was fairly straight forward and the community was very willing to help out. One of the first things I needed to do was get the service file so that I could enable and launch Caddy at boot. Like any other service file, this one was pretty clean and easy:

/etc/systemd/system/caddy.service

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
User=http
Group=http
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512\
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

Caddy provided the service script on their GitHub.

Then it was off to the configuration file. After seeing the simplicity of the setup, I knew this was going to be perfect. As you can see from the service file, the configuration is stored in /etc/caddy/ in a file called Caddyfile.

WordPress Configuration:

Configuring a WordPress blog is really easy. Declare the root folder, make sure that you add the right location for PHP FastCGI (also, this might be work mentioning, but the link does include // instead of : after unix, this tripped me up the first time). Make sure to use the proper location for php-fpm.sock; in Arch Linux, this is the proper location. The last two options are required for proper handling. I noticed what when I didn’t add encode gzip, the login page for WordPress was missing a theme and the add post/page was blank.

thebytes.net {
    root * /var/http/site
    php_fastcgi unix//var/run/php-fpm/php-fpm.sock

    encode gzip
    file_server {
index index.php
hide .htaccess
}
}

Standard/Static HTML Website Configuration:

Like WordPress, configuring a standard HTML website with Caddy is a very simple process. The only difference is that you don’t need a FastCGI configuration.

thebytes.net {
    root * /var/http/site

    encode gzip
    file_server {
index index.html
}
}

Reverse Proxy:

This was another very easy module to setup. Simply add the subdomain name, and declare the reverse proxy location. I am not sure if there is a difference between using localhost or the loopback address (127.0.0.1). From my experience with firewall configuration, localhost seemed to be the better option.

place.thebytes.net {
reverse_proxy localhost:8123
}

One of the best features of Caddy is the automated SSL features and the security of the entire server. I had no issues with setting up a reverse proxy Cockpit and Home Assistant, out of the box, they just worked.

The best part is, just run all of these together and make one configuration file to host multiple sites/services. Ultimately, I think Caddy is now the best solution for simple web servers. Especially when it comes to at-home solutions.

CentOS 7 on Raspberry Pi 4

There are a lot of guides and walkthroughs on how to install CentOS on a Raspberry Pi 4, but once you get the OS up and running, it’s pretty useless until you get it set up and configured properly for the Pi. The CentOS 7 image is a pretty barebone image that doesn’t provide a lot in the way of Linux.

Getting the image is a pretty straight forward process; download the image here. One key thing to pay attention to is the version you are downloading. Make sure to download the minimal armv7hl version with “minimal-4” in the name as it is the only image that has the proper configurations Pi4.

Flash the image using Etcher or Raspberry Pi Imager. Make sure you flash to the right drive (the SD card and not your hard drive).

Once you have the image flashed, then boot up your Raspberry Pi. You can log into the Pi with the following credintials:

username: root
password: centos

(I recommend changing these soonest.. but for this, I will be using root the entire time)

Configure the Network

This process is a fairly easy process too. Use the preinstalled network management tool ‘nmtui‘ to configure your wired or wireless network. Since you have a Raspberry Pi 4 (at least I assume you do since you’re reading this), the wireless configuration process is very easy. Don’t skip this step because you will need internet access to get everything else working. While here, you can assign a hostname if you desire.

Expand the rootfs

One of the weird nuances with CentOS images for the Raspberry Pi is that the file system is fairly small. (you can check the size with ‘df -l‘. In my case, the image was around 2G. That is obviously not very large. There is a default command that you can run to resize the partition to the full size of the SD card you installed on. Run the following:

# rootfs-expand

and wait a few seconds. The screen will clear, then you will see a script output of two commands; growpart and resize2fs. Once completed, the partition and file system should match the right size of the SD card. (Again, you can check with ‘df -l’).

Disable the annoying kernel messages in console.

This is more of a personal preference over anything else. It becomes really annoying to see kernel messages flood the screen when trying to accomplish anything in a console-only build. If I want to see these messages, I can reenable them later or check dmesg. Echo the following line to disable the kernel messages. A reboot is required (the easiest way) for the changes to take effect.

# echo kernel.printk = 3 4 1 3 >> /etc/sysctl.conf

No more annoying messages. (if this is your thing, then by all means, keep the messages and… good luck).

Update the system (and enable the EPEL)

Now that the internet is working, the system size is properly set and you aren’t receiving annoying messages, we can now update the system and install some packages. First, update your system.

# yum update

If you want to install an editor like ‘nano’, now would be the time. If not, ‘vi’ is available be default.

Next, you will probably want the Extra Packages for Enterprise Linux (EPEL) installed and available for your CentOS Raspberry Pi build. You will need to add the repo before you can install it. (Not that it matters, but this is an unofficial repo as it is NOT officially supported by CentOS yet. Some things might be broken).

Add this to the repo folder:

# vi /etc/yum.repos.d/epel.repo

[epel]
name=Epel Repo
baseurl=https://armv7.dev.centos.org/repodir/epel-pass-1/
enabled=1
gpgcheck=0

Once you have the repo added, then you can update the system. I highly recommend updating the system with the ‘Continuous Release’ repo as well. This will help with keeping things up-to-date on the Pi. Especially if you want packages like gpio-rpi and snapd.

# yum --enablerepo=cr update
# yum install epel-release

(if you prefer dnf, then this would be the best time to install it).

Install and Enable Snapd

Now that everything is updated and you are running with extra repos, it’s time to install snapd. If you don’t know what snapd is, it’s a daemon for running snapcraft’s snaps on your system. More about snaps here.

# yum install snapd
# systemctl enable snapd

Install Extra Packages

For the final piece, I needed to install gpio-rpi. Snap was the best option. For snap, there are some options required before installing “less-than-secure” packages. Both edge and devmode are required.

# snap install --edge --devmode gpio-rpi