Notes about Computers, Computing, Computations, Etc.
Critical Software for Good Computing
Stable Diffusion
Programming
Cache Clean-up
Video and Audio Stuff
Change video container from Matroska (mkv) to mp4 (assuming the video codec is supported by mp4):
ffmpeg -i name_of_input_file.mkv -codec copy output_file.mp4 # If there's issues with the audio codec: ffmpeg -i name_of_input_file.mkv -c:v copy -c:a aac output_file.mp4
Extract AAC audio from a directory of MP4 files and put them in a folder named audio:
for f in *.MP4; do ffmpeg -i "$f" -vn -c:a copy "audio/$f.m4a"; done
Download a Youtube playlist, keeping only the audio in AAC (.m4a) format:
yt-dlp -f 140 -o "%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s" "https://www.youtube.com/playlist?list=PLaro_mvk6VEkTqkmTcUIvr4MnUzfh434-"
Download a Youtube video in a h264 video and AAC audio:
yt-dlp -f 22+140 https://www.youtube.com/watch?v=cnDJa_HZVP0
Photo / Image Stuff
To fix photo dates when people email you photos and you need to import them into your photo manager and your photo manager shows all the photos as taken today even though you know they were taken weeks ago but people are so bad at sending photos….
# Inspect the original timestamp exiftool -r -DateTimeOriginal path_to_picture_folder # Inspect the modification timestamp exiftool -r -FileModifyDate path_to_picture_folder # If FileModifyDate doesn't match what you need, you can set it to the original timestamp # Note: The double quotes are important so that the shell doesn't think you're redirecting I/O from a file. exiftool -r "-FileModifyDate<DateTimeOriginal" path_to_picture_folder
Tiling a Small Image into a Bigger One
Windows lock screen backgrounds don't support tiling so I use ImageMagick to create a large image made of my tiles:
convert -size 2560x1080 tile:image_to_tile.png tiled_img.jpg
Windows
Linux
Misc command lines
Repack 7zip files as ZIP, requires ``atool`` package to be installed.
arepack -e -F zip *.7z
Jellyfin Setup
# Install it apt install jellyfin # create symlink because apparently the ubuntu 22.04 package of jellyfin 10.9 is looking at the wrong folder and I don't feel like editing config files. ln -s /usr/share/jellyfin/web/ /usr/lib/jellyfin/bin/jellyfin-web setfacl -m g:users:rwX Movies Music MusicVideos YouTube TV\ Shows Audiobooks Workouts Podcasts Rifftrax Books setfacl -d -m g:users:rwX Movies Music MusicVideos YouTube TV\ Shows Audiobooks Workouts Podcasts Rifftrax Books
Fedora Setup
Installed LXQt spin of Fedora 41. Some notes and commands:
- I hate Red Hat's installer. It's laid out like some Gnome app and has a terrible workflow.
- Pick the custom partition option (second option, not the Blivet option)
- Set it to LVM, make sure partitions are ext4.
- Enable LUKS encryption
- After boot, update with dnf and reboot.
# We don't want ZRAM swap dnf remove zram-generator-defaults # Use lsblk to figure out what disk has our encrypted LUKS data lsblk # in my case it was /dev/sda3 # Enroll a FIDO2 key: systemd-cryptenroll --fido2-device auto /dev/sda3 --fido2-with-user-presence=true --fido2-with-client-pin=true # you will be asked the LUKS passphrase, and then the FIDO2 key's PIN, and then finally asked to touch the key to confirm presence. # Create a file /etc/dracut.conf.d/fido2.conf with the contents: add_dracutmodules+=" fido2 " # the spaces are important - their can't be a space after the += and there should be spaces around fido2 # Update with dracut dracut -f -v # -v is optional, turns on verbose output. # reboot and see if the FIDO2 key works.
Then install Nvidia driver support
sudo dnf install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm sudo dnf config-manager setopt fedora-cisco-openh264.enabled=1 sudo dnf install akmod-nvidia xorg-x11-drv-nvidia-cuda
Reboot. You may have to add “nomodeset” to the end of the kernel command line if you get a black screen. Need to research if a different parameter is more appropriate.
Run nvidia-smi to make sure your GPU was detected.
Set up old-fashioned swap:
# 32GB swapfile. We use dd because on file systems like ext4 and xfs, fallocate won't work well. dd if=/dev/zero of=/swapfile bs=1M count=32768 status=progress # Restrict permissions to root chmod 600 /swapfile # Initialize swap mkswap /swapfile # Turn on swap swapon /swapfile
To automatically enable swap on boot, add this line to your /etc/fstab
/swapfile none swap sw 0 0
Install packages you might need.
dnf install fuse fuse-libs git libxcrypt-compat gperftools
EndeavourOS
I chose EndeavourOS as my Linux distro to use 100% at home. I have lots of notes at EndeavourOS Setup, some of which may apply to Arch and perhaps even to other distros.
Fail2Ban
Show bans
fail2ban-client banned
Unban a particular IP
fail2ban-client set apache unbanip 100.19.53.46
Upgrading NextCloud
mv nextcloud nc-old mkdir -p ~/nc/29/extracted cd extracted unzip ../nextcloud-XX.0.0.zip mv nextcloud /var/www cp ncold/config/config.php nextcloud/config/config.php cd /var/www chown -R www-data:www-data nextcloud find nextcloud/ -type d -exec chmod 750 {} \; find nextcloud/ -type f -exec chmod 640 {} \; sudo -u www-data php occ upgrade
nVidia Drivers
sudo apt install ubuntu-drivers-common sudo ubuntu-drivers list --gpgpu sudo ubuntu-drivers install --gpgpu
Blocking Certain Applications from Network
Condensed from this ServerFault post:
# Make group for no-net access, add user to group groupadd no-net usermod -a -G no-net USERNAME groups USERNAME # Rules to allow local network access iptables -A OUTPUT -m owner --gid-owner no-net -d 192.168.1.0/24 -j ACCEPT iptables -A OUTPUT -m owner --gid-owner no-net -d 127.0.0.0/8 -j ACCEPT # Rule to block other network access iptables -A OUTPUT -m owner --gid-owner no-net -j DROP # Rule to block outbound IPv6 ip6tables -A OUTPUT -m owner --gid-owner no-net -j DROP # Create a script called ''no-net'' containing the following two lines: #!/bin/bash sg no-net "$@"
Add GUI to Ubuntu 22.04 Server
There are a couple ways to install Xfce, I prefer the first option:
apt install xubuntu-core
- perfect; includes whisker-menu for a good application launcher.apt install –no-install-recommends xubuntu-core
- boots to GUI, very barebones (not even xfce4-terminal).apt install xfce4
- gives basic installation, still boots to console, so start GUI with startx.
Don't bother with apt install xfce4 –no-install-recommends
because apparently installing xorg is just a recommendation, so startx/startxfce will fail :D
Some Standard Configs for Ubuntu Server 22.04
# Get rid of cloud init apt purge -y cloud-init # Disable IPv6 in the kernel by modifying the CMDLINE options in /etc/default/grub: GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1" GRUB_CMDLINE_LINUX="ipv6.disable=1" update-grub # Edit /etc/default/keyboard to include: XKBOPTIONS="ctrl:nocaps"
Enable Newer Kernel on Ubuntu Server 22.04
sudo apt install linux-generic-hwe-22.04
Synology ABB on a Linux
Looking Good
Settings for a good-looking Xfce4 installation:
- Style: Greybird
- Icons: Elementary Xfce dark
- Window Theme: Arc-dark
On Debian these are installed with: sudo apt install greybird-gtk-theme elementary-xfce-icon-theme arc-theme
Setting up Django / PostgreSQL / Nginx on Ubuntu 20.04
Here are some extensive notes on setting this up. I also have a version for CentOS 8 (RIP) but don't maintain/update it.
Setting up Kanboard on Ubuntu 20.04
Notes on setting up Kanboard on Ubuntu.
Writing a Systemd Service file
Sometimes you have to make a program start automatically at boot. Here's how I do it with systemd.
Disable Automounting for Xfce
This came up because I was messing with partition layouts for a project and Xfce kept automatically mounting the drives while I was working on them.
# Don't automount drives xfconf-query -c thunar-volman -p /automount-drives/enabled -s false # Don't automount media (CDs?) xfconf-query -c thunar-volman -p /automount-media/enabled -s false
Backup and Restore a Raspberry Pi
# backup dd bs=4M if=/dev/mmcblk0 | gzip > /mnt/recovery-usb/backupbot-20210715.img.gz # restore gunzip --stdout backupbot-20210715.img.gz | sudo dd bs=4M of=/dev/{whatever the device is}
Postgresql basic commands
Add a user: createuser someusername -P
Create a database: CREATE DATABASE somedb OWNER someusername TEMPLATE template0 ENCODING 'UTF8';
GRANT CREATE ON SCHEMA public TO username;
Postgresql - Upgrade 11 to 13
/usr/share/doc/postgresql-common/README.md
Text and File Manipulation
Add a newline to the start of a file
# In particular, an LRC lyric file. sed '1 s/^/\n/' */*.lrc -i
Or realize you made a mistake and don't want newlines at the start of every file.
sed -z -i 's/^\n//' */*.lrc
Find file names with non-ASCII characters
LC_ALL=C find . -name '*[! -~]*'
Find lyric files with a BOM
From https://www.yiiframework.com/wiki/570/remove-byte-order-mark-bom-from-files-recursively
# Make a list of the files grep -rl $'\xEF\xBB\xBF' . | grep .lrc > file_with_boms.txt # Remove the BOM while read l; do sed -i '1 s/^\xef\xbb\xbf//' "$l"; done < file_with_boms.txt