Skip to content

Instantly share code, notes, and snippets.

@lmlsna
lmlsna / count-frames.sh
Last active February 19, 2024 09:33
Return the number of frames in a video file using ffprobe (ffmpeg)
#!/bin/bash
# Print the number of video frames in $1
ffprobe -count_frames -v error -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 ${1}
@lmlsna
lmlsna / install-nvidia-cuda-repo-verbose.sh
Last active August 8, 2023 17:12
Automatically configure nvidia's deb repo for CUDA, and update with apt.
#!/bin/bash
# An nvidia and cuda installer for Ubuntu
# Set env DEBUG_MODE=1 (up to 4) for more verbosity
if [[ "$DEBUG_MODE" == "" ]] || [ $DEBUG_MODE ! -gt 0 ]; then export DEBUG_MODE=0; fi
# Set env ASSUME_YES=-y for less interactivity
if [[ "$ASSUME_YES" != "" ]]; then export ASSUME_YES="-y"; else export ASSUME_YES=''; fi
## Pretty Print
@lmlsna
lmlsna / wg-setup
Last active December 17, 2022 14:50
Setup wireguard interface over ssh and return public key
#!/bin/bash
apt-get update &>/dev/null
if [[ "$(lsmod | grep wireguard)" -n ]]; then
export HAS_WG_MODULE=1
else
apt-get install wireguard wireguard-tools -y &>/dev/null
modprobe wireguard
fi
@lmlsna
lmlsna / example.keybase.env
Last active November 12, 2022 12:42
All keybase/client environmental variables (and a script to retrieve them)
#KEYBASE_ALLOW_PTRACE=
#KEYBASE_ALLOW_ROOT=
#KEYBASE_API_DUMP=
#KEYBASE_API_TIMEOUT=
#KEYBASE_APP_TYPE=
#KEYBASE_ATTACHMENT_DISABLE_MULTI=
#KEYBASE_ATTACHMENT_HTTP_START=
#KEYBASE_AUTO_FORK=
#KEYBASE_AUTOSTART=
#KEYBASE_AVATAR_SOURCE=
@lmlsna
lmlsna / setup-unpriv-lxc-gui.sh
Created December 14, 2017 10:04
Setup unprivileged LXC containers with GUI
#!/bin/bash
# Sets up the directory tree and necessary files for unpriv LXC GUI containers.
# Expects the default LXC setup (lxcbr0) to be functioning
# Need to install desktop environment inside each container.
UNAME="ubuntu"
UHOME="/home/$UNAME"
mkdir -p "$UHOME/.config/lxc" # /etc/lxc
touch "$UHOME/.config/lxc/lxc.conf" # /etc/lxc/lxc.conf
@lmlsna
lmlsna / gui-profile.yaml
Last active July 10, 2022 00:53
LXD gui container profile
# Adapted from https://blog.simos.info/how-to-easily-run-graphics-accelerated-gui-apps-in-lxd-containers-on-your-ubuntu-desktop/
#
config:
environment.DISPLAY: :0
raw.idmap: both 1000 1000
user.user-data: |
#cloud-config
runcmd:
- 'sed -i "s/; enable-shm = yes/enable-shm = no/g" /etc/pulse/client.conf'
- 'echo export PULSE_SERVER=unix:/tmp/.pulse-native | tee --append /home/ubuntu/.profile'
@lmlsna
lmlsna / force-release-upgrade.sh
Last active March 23, 2022 07:18
Upgrade EOL version of Ubuntu
#!/bin/bash
# This script will perform the same function as `do-release-upgrade` when that tool is giving
# an error for an EOL verison of Ubuntu, or some other "cannot upgrade from <current> to <next>".
# It does this safely by downloading the release-upgrade meta-pacakge from your target distribution.
#
# See https://help.ubuntu.com/community/EOLUpgrades/ for more information.
# Make sure a release is given as argument
if [[ "$1" == "" ]]; then
@lmlsna
lmlsna / ultrawide.sh
Created February 21, 2022 03:33
Setup weird resolution for ultrawide monitor on Ubuntu
#!/bin/bash
#
# Set a nonstandard resolution (ultrawide) interactively
#
###
# Define default resolution (and monitor ID if multiple monitors)
# Will be overridden is passed to script as arguments
#
#
@lmlsna
lmlsna / ps1_color
Last active February 6, 2022 23:37
Source BASH one liner to change prompt color
#!/bin/bash
#
# Source this file with an to change the current prompt color
# No arguments for normal (green) and red (root) defaults
# Include an integer 0 - 255 after for an x256term color prompt
#
# You can also paste into .bashrc with $1 replace with an integer or variable
#
# Examples:
#
@lmlsna
lmlsna / dl-and-parse.sh
Last active January 21, 2022 20:19
Download a PGP key and parse key, fingerprint, and email into variables in BASH
#!/bin/bash
# First argument passed to script is pgp key url
# Download key to memory with curl or wget (fallback)
key="$(curl -sSL "$1" 2>/dev/null || wget --quiet -O - "$1" 2>/dev/null)"
# Parse just the fingerprint and email, then separate into their own variables
both="$(gpg --show-keys --keyid-format=long --list-options show-only-fpr-mbox=yes <<< "$key")"
fingerprint="$(echo "$both" | cut -d' ' -f1)"
email="$(echo "$both" | cut -d' ' -f2)"