Shell Tools

Shell tools
Login

Shell tools

This repository contains assorted shell scripts for personal use.

Installation

Clone the repository somewhere and place symbolic links to scripts of interest into a directory on your $PATH.

Contents

merge-config.py

Manage Linux system configuration file updates on Arch-Linux based systems. Merges configuration file changes from updated packages with local configuration file changes.

merge-config.py offers 4 subcommands to manage a changed configuration file:

The merge logic uses gaspra as the merge algorithm, which must be installed via pip.

Workflow

When updating packages, pacman creates .pacnew files for locally edited configuration files. For each config with an associated .pacnew file,

dl-nyaa.xsh

Xonsh script to download torrents from nyaa.si using aria2c. Takes any number of numerical torrent ids (or URLs containing them), and fetches them in order.

network_webcam.sh

Bash script to connect a network camera streaming video via SRT and use it as a standard webcam, as if it were a USB camera.

Uses v4l2_loopback as the driver backend, and ffmpeg to run a filter chain for de-noising the input to make it easily compressible.

The goal is to have a static image without any noise when nothing moves in front of the camera.
Use case is streaming a low movement environment in high resolution over a bandwidth-starved connection.
For example, online playing a TCG with physical cards, by having a camera filming the play area from above. There is low movement, but card texts require high resolution images to have them legible.

fix_srt_timestamps.py

Fixes invalid timestamps in SRT subtitle files. Ensures that all milliseconds in timestamps are properly zero-padded to three digits.

scan_flatbed.xsh

Xonsh script to scan documents via a flatbed scanner. It uses

It can output as a series of PNG images or a single PDF document. Image post-processing is run asynchronously in the background, and processes images in parallel up to the number of CPU cores in the system. It starts as soon as the first image scan is finished to minimize the runtime.

Default values for optional parameters are read from a configuration file in $XDG_CONFIG_HOME/ShellTools/scan_flatbed.ini
(The file is created and populated with the default values, if it does not exist.)

scan_adf.xsh

Xonsh script to scan (duplex) documents via a (simplex) ADF scanner. It uses

In duplex mode, it asks for confirmation when one side is done, so that mistakes can be corrected, for example when the scanner pulls multiple pages at once or pulls overlapping pages.

Default values for optional parameters are read from a configuration file in $XDG_CONFIG_HOME/ShellTools/scan_adf.ini
(The file is created and populated with the default values, if it does not exist.)

backup_paperless

Backup tooling for a paperless-installation.

Dependencies

Overview

Consists of a backup script to be placed in $PATH, a backup sync script, and systemd units to control the behavior:

The paperless installation runs on a Raspberry Pi, with the data on an SSD. The local backup resides on a dedicated partition on the MicroSD card and is only mounted during the backup process to protect the data from a potential stray rm -rf /*. The remote is a plain USB flash drive attached to an all-in-one router device running in the LAN, and shared via SFTP. It is also only mounted during the backup sync process. The remote file system is not required to perform a snapshot, and if unavailable, the sync script skips syncing the local backup with the remote.

paperless_leaflet_bot

A bot that manages shop leaflets in paperless. Consists of two scripts run via systemd services and triggered via timers:

The paperless instance is configured to put leaflets into a separate storage path, which is excluded from backups via the paperless backup script.

rpi_load_logger

Logs some system stats in regular intervals into an SQLite database. Meant to run as a systemd service on a Raspberry Pi.
Logs:

run-in-gui

Automatically run a GUI application on (USB) device plugin. Uses udev rules and systemd user services.

Currently provided is a service for launching Yubico Authenticator when plugging in any Yubikey FIDO2/TOTP hardware token (with USB vendor id 0x1050)

License

This applies to all scripts found here:

Copyright (C) 2023-2024 Thomas Hess <thomas.hess@udo.edu>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.