Skip to content

Instantly share code, notes, and snippets.

@ansemjo
ansemjo / gradient.css
Created May 4, 2017 18:07
paint a paragraph with gradient
/* text with gradient color */
h2 {
background: linear-gradient(4deg, #5cb,#49e);
background-clip: text;
color: #0000;
}
@ansemjo
ansemjo / mirror-centos.sh
Created June 20, 2017 21:06
create a local centos mirror for pxebooting
#!/usr/bin/env sh
# transfer settings
sync() {
printf '\nSyncing: %s\nLocal: %s\n\n' "$1" "$2";
mkdir -p "$2";
rsync \
--archive --hard-links --delete \
--compress --no-motd --progress \
"$1" "$2";
@ansemjo
ansemjo / flocked.sh
Created September 4, 2017 15:03
simple bash script using flock from util-linux for locking
#!/usr/bin/env bash
lock=/tmp/lockfile
touch $lock
say() { echo "[$$] ($loop) $*"; }
locked() { say 'lock is still held ..'; }
work() {
@ansemjo
ansemjo / secureboot-rescue.sh
Created September 4, 2017 16:01
download archboot kernel + initramfs, then pack them into a signed efi executable with [andreyv/sbupdate](https://github.com/andreyv/sbupdate)
#!/usr/bin/env bash
# just fail on any error
set -e
# where to copy from (requires rsync)
mirror='ftp.halifax.rwth-aachen.de'
folder='archlinux/iso/archboot/latest/boot'
# download destination
@ansemjo
ansemjo / ssh-auth-sock.service
Last active February 19, 2024 03:00 — forked from xenithorb/ssh-auth-sock.service
systemd user unit to set SSH_AUTH_SOCK variable for X11/Wayland/GNOME and make it work with GnuPG agent
# Place this file in ~/.config/systemd/user/ssh-auth-sock.service
# $ systemctl --user daemon-reload
# $ systemctl --user enable --now ssh-auth-sock.service
# Add 'echo UPDATESTARTUPTTY | gpg-connect-agent >/dev/null' in your ~/.bashrc.
# Logout or reboot.
[Unit]
Description=Set SSH_AUTH_SOCK to GnuPG agent
[Service]
@ansemjo
ansemjo / charwidth.sh
Created September 29, 2017 23:14
Get printed char width in a Terminal .. for example to check if it supports UTF8.
#!/usr/bin/env bash
char='✗'
printf "${char}\e[6n"; read -sd'R' pos; pos=${pos##*;}; printf "\nWidth: $(( ${pos%%R} - 1 ))\n";
@ansemjo
ansemjo / ipa-sysaccount.py
Last active November 1, 2023 18:43
Add or update a sysaccount in a FreeIPA LDAP directory. These accounts can then be used to bind with other services that require LDAP authentication. Run `make install` to install script in `/usr/local/bin/`.
#!/usr/bin/env python
from argparse import ArgumentParser
from random import SystemRandom
from string import ascii_letters, digits
from subprocess import Popen as subprocess, PIPE
from shlex import split as sh
ap = ArgumentParser()
ap.add_argument('action', help='add, delete or change password', choices=('add', 'delete', 'passwd'))
@ansemjo
ansemjo / ipa-ldaptree
Last active June 25, 2018 17:26
display ldap objects in sorted reverse notation (basedn first)
#!/usr/bin/env bash
basedn=$(sed -n 's/^basedn = //p' /etc/ipa/default.conf)
searchbase="${1},${basedn}"
searchbase="${searchbase#,}"
#ldapsearch -x -D "${2:-cn=Directory Manager}" -W -o 'ldif-wrap=no' -b "${searchbase}" dn |\
ldapsearch -Y GSSAPI -o 'ldif-wrap=no' -b "${searchbase}" dn |\
sed -n 's/^dn: //p' |\
awk -v FS=, '{for (i=NF; i > 1; i--) printf("%s / ", $i); print $1; }' |\
@ansemjo
ansemjo / shards.md
Last active December 29, 2017 23:18
convert dsprenkels/sss-cli output to base64 and deduplicate data blob with zfec; see: https://github.com/dsprenkels/sss-cli/issues/8

Purpose

The output from secret-share-split duplicates encrypted data in every share and uses hexadecimal encoding. These scripts 'deduplicate' the data by using zfec with the same shares / threshold values and encode everything in Base64.

Applicable to and written for sss-cli@46fd393.

Size savings

#!/usr/bin/env bash
echo -e "$(cat <<TUX | sed \
-e 's/\([\/]\+\)/\\033[31m\1\\033[0m/g' \
-e 's/\([@#]\+\)/\\033[1m\1\\033[0m/g'
###################################
# #
# #
# #
# @@@@@ @@@@@ #