Skip to content

Instantly share code, notes, and snippets.

@rany2
rany2 / chromium-force-aaaa.sh
Last active May 9, 2021 15:59
Chromium/Chrome/Electron doesn't resolve internal IPv6 domains if IPv6 internet isn't available. This fixes that by creating a route to the IPv6 address used to probe for IPv6 internet. https://bugs.chromium.org/p/chromium/issues/detail?id=530482
#!/bin/sh
nmcli connection delete ipv6-cr-dummy1
nmcli connection add type dummy \
connection.id ipv6-cr-dummy1 \
connection.interface-name ipv6-cr-dummy1 \
ipv4.method disabled ipv6.method manual \
ipv6.addresses 100::2c93:c388:6f50:23c3/127 \
ipv6.routes '2001:4860:4860::8888 100::2c93:c388:6f50:23c2' \
ipv6.route-metric 4294967295 connection.autoconnect yes
@rany2
rany2 / flatpak-wrapper-from-commands.sh
Created July 11, 2021 15:07
Get command from every flatpak app and generate wrapper script for it
#!/usr/bin/env bash
set -ef
if [ -z "$1" ]
then
outdir="output"
else
outdir="$1"
fi
mkdir -p "$outdir"
@rany2
rany2 / install-material-design-icons.sh
Created July 17, 2021 13:47
Install Material Design Icons to user font directory on Linux
#!/bin/sh
set -uex
install_path="${XDG_DATA_HOME:-$HOME/.local/share}/fonts/material-design-icons"
url_prefix="https://raw.githubusercontent.com/google/material-design-icons/master/font"
fonts="MaterialIcons-Regular.ttf MaterialIconsOutlined-Regular.otf MaterialIconsRound-Regular.otf"
fonts="$fonts MaterialIconsSharp-Regular.otf MaterialIconsTwoTone-Regular.otf"
for font in $fonts
#!/bin/sh
# requires parted, losetup, and resize2fs
BOOT="$(sed -n -e "\|\s/boot\s.*$|{s///p;q}" /etc/mtab)"
DISK="${BOOT%%[0-9]*}"
PART="$((${BOOT##*[^0-9]}+1))"
printf "fix\n" | parted ---pretend-input-tty ${DISK} print
parted ${DISK} resizepart ${PART} 100%
@rany2
rany2 / openwrt-x86-kexec-reboot.sh
Last active December 9, 2022 17:48
Fast reboots for X86 OpenWRT machines
#!/bin/sh
unset TERM
export LC_ALL=C
if [ "$__KEXEC_REBOOT_NOHUP" != "1" ]
then
SCRIPTPATH=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
__KEXEC_REBOOT_NOHUP=1 nohup "$SCRIPTPATH/$(basename -- "$0")" "$@" > /dev/null 2>&1 </dev/null &
exit "$?"
@rany2
rany2 / mosh-server-upnp
Last active November 2, 2022 11:21
Start mosh-server, but first create a port redirection in the NAT router (with UPnP) and delete that redirection again just before mosh-server exits.
#!/usr/bin/env bash
#
# Start mosh-server, but first create a port redirection in the NAT
# router (with UPnP) and delete that redirection again just before
# mosh-server exits.
# die -- print error on stderr and exit
function die {
echo "$@" >&2
exit 1
@rany2
rany2 / eskom.py
Last active January 4, 2023 07:44
Eskom API
#!/usr/bin/env python3
import urllib.parse
from enum import Enum
from typing import List
import requests
BASE_URL = "https://loadshedding.eskom.co.za/LoadShedding/"
USER_AGENT = "ZA_LOADSHEDDING/1.0 (github.com/rany2)"
@rany2
rany2 / get_x86_bootloader.sh
Created April 10, 2023 14:02
Get bootloader type and (if available) the bootloader version. Only works on x86/x86-64 Linux.
#!/bin/bash
set -euf -o pipefail
# Copyright (C) rany <ranygh@riseup.net>. All rights reserved.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
@rany2
rany2 / 01-maxwlanmtu
Last active January 9, 2024 14:25
OpenWRT workaround for inability to set MTU for WLAN interfaces
#!/bin/sh
# Ensure that WLAN interface MTU is set to the maximum
# permitted value to prevent issues when attached to a
# bridge with jumbo MTU.
#
# Do not attempt to use standard UCI configuration
# in /etc/config/network and set the MTU with a config
# of type interface. It does not work consistently
# and in the best case works for the first WLAN
@rany2
rany2 / pppd@.service
Last active May 8, 2023 07:25
Hardened systemd service for PPP
[Unit]
Description=PPP connection for %I
Documentation=man:pppd(8)
StartLimitIntervalSec=0
Before=network.target
Wants=network.target
After=network-pre.target
[Service]