the itjerk

my adventures with technology

Category Archives: Linux

dr14.tmeter

Wow, figured out how to install this nifty python program that calculates dynamic range on flac files. Ubuntu 20.04 ships with Python3. There’s some drama between python versions 2 and 3 (e.g. latter merely a release candidate), so the best way is to first get pip and use it to install the program DR14-T.meter:

sudo apt update
sudo apt install python3-pip

Now we can use pip3 to install the dependencies, and then dr14.tmeter

sudo -H pip3 install numpy scipy
sudo -H pip3 install DR14-T.meter

Alternatively, you can use pip3 to install just for a specific user (in ~/):
pip3 install DR14-T.meter --user

to calculate the dynamic range of an album, switch to the directory and run
dr14_tmeter ./

Scan Dir: /Music/Yes/1971_The_Yes_Album

02_Clap.flac: DR 15
01_Yours_Is_No_Disgrace.flac: DR 11
03_Starship_Trooper-_a._Life_Seeker_-_b._Disillusion_-_c._Würm.flac: DR 12
04_I’ve_Seen_All_Good_People-_a._Your_Move_-_b._All_Good_People.flac: DR 10
05_A_Venture.flac: DR 11
06_Perpetual_Change.flac: DR 11
DR = 12

– The full result has been written in the files: dr14.txt
– located in the directory:
/Music/Yes/1971_The_Yes_Album

Success!
Elapsed time: 5.60 sec

On the web:
DR14_T.meter

uncomplicated firewall (ufw)

RoonUFW
I run a Roon Server or “Core” on my Ubuntu box to supply music to various endpoints on my local subnet. Because the computer also has a window to the outside world, I run a firewall, ufw. Like its namesake, it’s easy to configure, you can get the basics here. Anyway, I need to open a few ports so Roon Server can be discovered on my subnet, by creating an application profile and then adding a rule to the firewall.

First, we’ll create a file “roon” in the following location:
$ cd /etc/ufw/applications.d/
$ sudo touch roon
$ sudo nano roon

Here’s what’s in the file:
[Roon]
title=Roon Server
description=Roon Labs Core Music Server
ports=9003/udp|9100:9200/tcp

Note the context of the ports entry: The pipe separates udp from tcp, and ranges are set with a colon (and individual ports with a comma). Once you create the file, you can quickly check syntax by running ufw status, and it will let you know if you made any errors, which is handy. Once that’s created, it’s easy enough to add the rule to ufw, and check status again to see it working:

$ sudo ufw allow from 192.168.1.0/24 to any app roon
$ sudo ufw status

Status: active
To Action From
— —— —-
Roon ALLOW 192.168.1.0/24

I should note that the reason I’m doing this is because Roon doesn’t document what ports need to be open, and I’m having an issue with one piece of hardware being recognized on reboot. There’s probably another series of ports that I need to open up, so having a profile is an easy way to trouble shoot; once I make changes, I can edit the profile then update ufw with the following command:

$ sudo ufw app update Roon

Since Roon uses randomized ports, my interim fix is to allow access to the server from the endpoint in question:

$ sudo ufw allow from [endpoint ip]

Nothing scary here folks, just some computer and network basics.

wireguard vpn

On my to-do list for my newly christened Ubuntu box was to install a VPN. I had previously used OpenVPN-AS (Access Server), which is a lite version (two user) of OpenVPN that uses a web interface for most configuration. I also considered using “regular” OpenVPN but to be honest, there’s a fair amount of work in setting up keys, and I didn’t want to use scripts downloaded from github. Enter WireGuard.

Here’s the pitch. “WireGuard® is an extremely simple yet fast and modern VPN that utilizes state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more useful than IPsec (and OpenVPN), while avoiding the massive headache. It intends to be considerably more performant than OpenVPN.” In short, it’s easy to configure, lightweight to use, and it’s already in the Ubuntu 20.04LTS repo.

To install WireGuard, we install the program, create keys, configure the virtual network device (wg0), and then configure the client (Android).

#install WireGuard
$ sudo -i
$ apt update && install wireguard

#generate server keys (these are stored in /etc/wireguard/)
$ umask 077; wg genkey | tee privatekey | wg pubkey > publickey
cat publickey

#configure the WireGuard interface wg0 (leaving peer empty for now)
$ cd /etc/wireguard
$ nano wg0.conf

[Interface]
Address = 192.168.6.1/24
SaveConfig = true
ListenPort = [port]
PrivateKey = [server privatekey]

[Peer]
PublicKey = [client publickey]
Allowed IPs = 192.168.6.2/32

#open port on firewall for WireGuard to listen
$ ufw allow [port]/udp

#enable and start Wireguard server
$ sudo systemctl enable wg-quick@wg0
$ sudo systemctl start wg-quick@wg0
$ sudo systemctl status wg-quick@wg0

#now that the service is started, let’s stop it, and configure our client.
#first we create client (keys we’re not going to save them)
$ sudo systemctl stop wg-quick@wg0
$ wg genkey | (
read privk
echo "android-private-key: $privk"
echo "android-public-key: $(echo "$privk" | wg pubkey)"
)

#edit wg0.conf and enter the publickey for your client, then restart WireGuard
$ sudo systemctl start wg-quick@wg0
$ sudo systemctl start wg-quick@wg0

#now let’s create a config_file for the client.
$ exit
$ cd ~/Desktop
$ nano config_file

[Interface]
#client
PrivateKey = [client privatekey]
Address = 192.168.6.2/24

[Peer]
#server
PublicKey = [server publickey]
AllowedIPs = 192.168.6.0/24
Endpoint = [ip or host name]:[port]
PersistentKeepalive = 15

#save the file and generate a qrcode to scan with your phone
$ qrencode -t utf8 < config_file

That’s it! I installed the WireGuard app on my Pixel phone, selected QR code for the connection and scanned the image, then the app asked me to name my new connection. All set, I connected and viola, I have my own VPN server.

Couple of notes. Pay attention to the IP addresses and masks; they must be exact. You can use whatever port you want for WireGuard to listen, and it works well with DuckDNS dynamic hostname. Multiple peers can be configured as well. The Android app could do a better job “hiding” both keys, but there you are.

On the web:
WireGuard

duplicate files

Finding duplicate files is big part of my Ubuntu data cleanup plan. Here’s some tips: Fdupes finds duplicate files via checksum; the first command will summarize what it finds in a recursive search, while the latter will delete the files (N means NO CONFIRMATION!). Warning: there’s no going back! The third command will change the date of pictures to what’s in the jpegs header, for easier sorting.

fdupes -rSm .
fdupes -rdN .
jhead -ft *

ubuntu 20.04 lts

Yes, the latest LTS distribution of Ubuntu, 20.04 aka Focal Fossa, has been released. I’m raring to upgrade my desktop but there’s always a bit of work involved. Of course, with the COVID-19 pandemic in full swing, I’ve got plenty of time on my hands. But a few other things first. Watch this space.

Here’s my thoughts:
1. I need my Ubuntu server to be dedicated to music (and video); that’s why I got into the Linux game in the first place, and I’m all-in with Roon. I’ll do a clean install of 20.04, get 99% of it setup in no time at all.
2. The local copy of my production website(s) needs to go to a virtual machine. Great solution to a small problem.
3. Backup for photos and documents. Why not pay for a cloud service? I don’t like the idea of having a few hard drives laying around, I’m too OCD for that. Get it organized, put it in the cloud.

Now that’s a plan.

farewell, dvd?

I have some DVDs. I don’t know what to do with them. Playing DVDs is passé, right? Everyone has at least a couple services they subscribe to (we have Netflix and Amazon Prime), and everything is on Youtube anyway. But I thought maybe I could rip them to my computer.

In order to rip them to disk, I first installed libdvd-pkg (which allows Ubuntu to decrypt and play DVDs), configured it, and finally installed Handbrake, which is the software that rips the DVDs. Easily done from the command line:
sudo apt-get update
sudo apt-get install libdvd-pkg
sudo dpkg-reconfigure libdvd-pkg
sudo apt-get install handbrake

Ripping DVDs takes a time – it’s pretty much in real time, a rather boring, cpu-intensive and disk-intensive chore. Then, what do I do with all these gigabytes on my drive? I’m not watching them on my computer, no, that’s passé too.
yessongs
Step in VLC media player. Under Playback>Renderer lo and behold I find my Vizio TV. Now I’m Chromecasting away… as long as port 8010 is open!

Another physical format bites the dust.

raspbian buster

Almost forgot about my Raspberry Pi 3B+ that sits connected behind my television – for maybe a few months. It’s one of those “because I can” things. I did about a zillion updates to Stretch, but after changing the sources lists to the next OS, Buster, I ran out of room on the SD card (because I had initially used N00bs to write the card). Anyway, after downloading 7Zip – mandatory for unzipping Raspbian’s Stretch package with Windows – and balenaEtcher to write the microSD card with a fresh Buster image, I was quickly back up and running with a brand new OS for my Raspberry Pi.

Once I restarted the Pi and answered a few questions (country, timezone, wifi, password, display prefs), I reboot again and proceeded with 125 more updates! I chose Raspbian Buster with Desktop, which includes a GUI, Chrome and a few apps, and is just what I need on my Pi; no need for all the “recommended” software. I must say, Buster runs like a champ and looks a lot better on my 1080p display than any previous version. Bravo Raspbian, I might even use it more often!

On the web:
Download Raspbian for Raspberry Pi

record terminal commands with script alias

Here’s an incredibly useful command that uses script  and alias to record what you’re doing on the terminal. Install something? Update something? Need to remember something? It’s easier than looking at bash_history.

To setup, add the below line to your ~/.bashrc file to create an alias “rec”. Then, the next time you want to remember your terminal commands, type “rec” first to activate script (and “exit” when you’re done), and you’ll have a timestamped file in your Documents directory of your terminal’s output.

 alias rec='script -aq ~/Documents/term.log-$(date "+%Y-%m-%d.%H:%M:%S")'

cd burning on ubuntu 18.04lts

It’s not often anymore that I have to burn a CD-R, mostly when I want a CD for the car, or perhaps to give to a friend. Anyway, I opened up Brasero, clicked New Audio Project, added my files and went to burn the CD-R. Failed. Log showed the following:

BraseroWodim stderr: wodim: Operation not permitted. Warning: Cannot raise RLIMIT_MEMLOCK limits.
BraseroWodim called brasero_job_get_flags
BraseroWodim stderr: wodim: Resource temporarily unavailable. Cannot get mmap for 16781312 Bytes on /dev/zero.
BraseroWodim called brasero_job_get_flags
BraseroWodim stdout: TOC Type: 0 = CD-DA
BraseroWodim stderr: HUP
BraseroWodim stdout: HUP
BraseroWodim process finished with status 11
BraseroWodim called brasero_job_error
BraseroWodim finished with an error
BraseroWodim asked to stop because of an error

 

Quick internet searched yield the following fix, giving “execute” rights to users, and that “4” means as root (setuid):

sudo chmod 4711 /usr/bin/wodim; sudo chmod 4711 /usr/bin/cdrdao

It’s not the first time I’ve had to “fix” something in Ubuntu to do a relatively mundane task, maybe not the last, either. Burn, baby burn!

backup

The data axiom is “always have at least two copies of anything you want to keep!”

Now that I’ve ripped my entire (well, almost entire) CD collection, I have to back it up. A RAID 1 drive is good protection from drive failures, but it doesn’t protect at all for accidental erasure, file corruption, etc. I’m going old school and bought a new 3TB disc, the same size as my RAID, and plugged it into a hard disc enclosure, the same model I have for my another backup drive; I only need to have the same wall-wart and USB cable handy. I formatted the disk with ext4, the same as the source drive, which prevents file-naming errors during backup. However, if you format your disk for use with Windows, you’ll need to install exfat-utils and exfat-fuse in Ubuntu. (I also recommend doing the initial format on a Windows machine.)

I am using Grsync software to make the backup, which is a graphical front-end for the rsync utility. I marked the –update and –delete options, as I want to make an identical copy of the source on the destination: copy what’s not there, replace (based on checksum) what’s changed and delete what was removed from the source. You can perform a dry-run first; be sure to empty the trash and skip the lost+found folder before you sync (the latter may give errors). Viola, backing up FTW!

When deciding on a backup method, it’s important to always remember what you’re backing up and why you’re backing it up – and what risk you can afford.

In this case, these are music files, most of which I have a CD copy of but would never want to put in the months of work in to rip again. The rest are downloads, paid or otherwise, some I may never have access to again. Now, I could probably use something different method (cloud, internal disk), something automated, something better, but this method works for me because I can assume the risk.

I have an initial backup (which I have tested) and a proven backup method, so it’s up to me to keep up the work.