GithubHelp home page GithubHelp logo

bin's Introduction

bin

This repository contains a collection of scripts and related files that I am using on my Arch Linux installation. There might be better ways to do some of the things I wrote these scripts for, or even already existing solutions I simply didn't know about; if you think you know of either one please let me know.

restart-plasmashell

Sometimes the KDE Plasma shell starts displaying my wallpaper strangely (i.e. not at all) towards the bottom of my screen. When that happens I simply run this script to quickly restart the shell.

vpn-whitelist-domain

I am using NetworkManager and the NetworkManager-OpenVPN plugin. When connecting to my VPN provider, NetworkManager creates a virtual tunnel-device through which all traffic is routed by setting the route metric lower than the metric of my default gateway.

Some sites and services unfortunately have simply blocked or banned my VPN's IP address, so for some domains it is useful to bypass the VPN tunnel entirely. That is what this script does: it finds the first default gateway that isn't a tunnel device, resolves the passed domain to all possible IPs and then adds explicit routes for each of them through the discovered gateway.

Usage:
    vpn-whitelist-domain [SWITCHES] domain

Meta-switches
    -h, --help         Prints this help message and quits
    --help-all         Print help messages of all subcommands and quit
    -v, --version      Prints the program's version and quits

Switches
    -r, --remove       Remove domain from whitelist

warm-up-dns-resolver

I am using Unbound with DNSSEC enabled. The resolving of an uncached domain takes quite a bit of time because of that, and most domains have a low TTL or even a TTL of 0 set which disables caching in Unbound completely. Naturally this is a bit annoying, so I wrote this script.

usage: warm-up-dns-resolver [-h] [--file path [path ...]] [--use-firefox]
                            [--days DAYS]
                            [domains]

positional arguments:
  domains

optional arguments:
  -h, --help            show this help message and exit
  --file path [path ...]
                        Paths to files containing domains
  --use-firefox         Use domains in Mozilla Firefox's history
  --days DAYS           Use domains of history up to n days before the last
                        made entry

It can also scrape domains directly from Mozilla Firefox's history. The matching systemd *.service and *.timer files execute this command: warm-up-dns-resolver --file ~/.warm-up-dns-resolver-domains --use-firefox. This allows me to place high-priority domains into a file in my home directory and also always quickly resolve domains that I visited in the last 7 days using Firefox. Additionally I adapted my unbound.conf a bit:

server:
  use-syslog: yes
  username: "unbound"
  directory: "/etc/unbound"
  trust-anchor-file: trusted-key.key
  root-hints: "/etc/unbound/root.hints"

  cache-min-ttl: 3600
  prefetch: yes
  prefetch-key: yes

cache-min-ttl: 3600 forces caching of resolved domains to at least one hour. Due to enabling prefetch, Unbound will start resolving cached domains as soon as their remaining TTL falls below 10% -- that's why I configured the systemd timer unit to run every 6 minutes. In theory this should keep every specified domain cached in Unbound.

systemd-octor

usage: systemd-octor [-h] [--output OUTPUT] [--compare COMPARE COMPARE]

optional arguments:
  -h, --help            show this help message and exit
  --output OUTPUT, -o OUTPUT
                        Change destination of output file
  --compare COMPARE COMPARE, -c COMPARE COMPARE
                        Compare first output to second output

This is used to compare the systemd service configuration between two systems. Useful for example in case some important units were disabled on system A and the exact changes made were forgotten. An easy way to fix the configuration then is to create a fresh Arch Linux installation (system B) in a systemd-nspawn container, or as a full virtual machine, and running this script to get a sane systemd service configuration which can then be compared using: systemd-octor --compare A.json B.json.

fix-openvpn

# systemctl enable fix-openvpn@<syslog-identifier>

usage: fix-openvpn [-h] syslog-identifier [gateway]

positional arguments:
  syslog-identifier  The syslog identifier of the journal to monitor
  gateway            Specify the gateway. If not set, the script will attempt
                     to determine the default gateway

optional arguments:
  -h, --help         show this help message and exit

Monitors the OpenVPN systemd log and automatically adds routes through the default gateway for remote link IPs that are attempted to be connected to. This is needed when the resolved IP address for a specified VPN domain changes, preventing automatic reconnects to the VPN server, because the traffic is routed through a broken connection.

Note: It seems that OpenVPN already attempts to do that on its own, but somehow fails. It might be using the old IP address after re-establishing the tunnel.

I really wanted to show my appreciation for the AUR packages that I am using, but am entirely too lazy to keep the list of voted-for packages up-to-date manually.

$ aur-auto-vote --help
usage: aur-auto-vote [-h] [--ignore IGNORE] [--unvote-all] [--delay DELAY]
                     username

positional arguments:
  username

optional arguments:
  -h, --help            show this help message and exit
  --ignore IGNORE, -i IGNORE
                        Regex for packages that should not be voted. Can be
                        passed multiple times.
  --unvote-all, -u      Unvote all voted-for packages, all other arguments are
                        ignored.
  --delay DELAY, -d DELAY
                        Delay between voting actions (seconds).

When voting already voted-for packages will be automatically skipped. Local PKGBUILDs I usually prefix with my nick, i.e. cryzed- so I pass in --ignore 'cryzed-.*'. If you feel that your voted-for packages are completely outdated, consider using --unvote-all to remove all votes beforehand. It might be a good idea to specify a --delay > 0 to prevent hammering the server.

backup-system

  • # systemctl start backup-system (to start the script via systemd. A systemd EnvironmentFile with a DIRECTORY key is needed at /etc/backup-system.conf)
  • # backup-system [DESTINATION] (to start the script manually, destination is optional)
  • # systemctl enable backup-system.timer (to enable the timer for daily backups)

This is a script that backups the most important parts of my Arch Linux installation, should it ever break in an unrecoverable fashion. It uses:

  • lostfiles to get a list of files in the system which are not part of any package, i.e. files I most likely created and added to the system without using a custom PKGBUILD.
  • pacman -Qii | awk '/^MODIFIED/ {print $2}' to get a list of modified backup files, i.e. modified configuration files of installed packages
  • pacman -Q --explicit to save the list of all explicitly installed packages
  • all systemd overrides located in /etc/systemd/system or /etc/systemd/user
  • systemd-octor (see above) to save the systemd service configuration
  • all /home directories
  • /root

and uses tar to compress all those files into an archive with the current date.

Note that I have symlinked all XDG directories, i.e. "Documents", "Downloads", "Music" etc. to a different HDD to prevent unnecessary writes on my system SSD -- so when backing up the /home directories, tar will only backup the dotfiles and not automatically follow the symlinks. The resulting backup file is usually around ~10-12 GB in size.

defaults

$ defaults --help
usage: defaults [-h] [--editor EDITOR] path

positional arguments:
  path

optional arguments:
  -h, --help       show this help message and exit
  --editor EDITOR

This is useful for me when editing (configuration/backup) files which are part of installed packages. Often they are filled with comments and various examples configurations, however after figuring out my configuration I rarely want to keep all these around.

Removing them to keep the file as clean as possible however, might be an issue when further modifications are needed at some later point in time -- all the reference examples are now missing, forcing you to either read the man page (even for trivial changes) or manually hunting down the package in your cache or online and checking out the original file.

This script aims to save you these steps: simply run it with a path to a file and the local, as well as the original file, should both be opened in your configured editor (EDITOR or VISUAL).

hotstrings

$ hotstrings --help
usage: hotstrings [-h] [path]

positional arguments:
  path        Path to JSON file containing hotstring definitions

optional arguments:
  -h, --help  show this help message and exit

This script is a much lighter version of AutoKey, specifically the AutoKey-py3 fork. Since there was a recent update to the official python-xlib which breaks compatibility with the fork, and the fork also doesn't seem to be actively maintained anymore, I wanted to preemptively find another solution before AutoKey-py3 eventually stops working entirely on my system.

This pretty much implements only the functionality I actually use: hotstrings; basically you type text and it is replaced with the actual content. Dependencies are Python 3 and the the official python-xlib or LiuLang's fork which is used by AutoKey-py3.

An example configuration file might look like this:

$ cat ~/.config/hotstrings.json 
{
    "first": "replacement 1",
    "second": "replacement 2"
}

bin's People

Contributors

cryzed avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.