Skip to content

Instantly share code, notes, and snippets.

View mastier's full-sized avatar
🤯
exploding ideas

Bartosz "mastier" Woronicz mastier

🤯
exploding ideas
View GitHub Profile
# add to /var/snap/maas/current/preseeds/curtin_userdata
late_commands:
00_maas: [wget, '--no-proxy', {{node_disable_pxe_url|escape.json}}, '--post-data', {{node_disable_pxe_data|escape.json}}, '-O', '/dev/null']
10_adduser: ["curtin", "in-target", "--", "sh", "-c", "adduser --disabled-password --gecos '' maas"]
20_addpwd: ["curtin", "in-target", "--", "sh", "-c", "echo 'maas:maas' | chpasswd"]
30_addsudo: ["curtin", "in-target", "--", "sh", "-c", "usermod -aG sudo maas"]
@mastier
mastier / lxc-create-windows-vm.sh
Last active July 18, 2023 12:04
lxc-create-windows-vm.sh
#!/bin/bash
if [[ "$#" != "1" ]]; then
echo "Provide the original image ISO"
exit 1
fi
sudo snap install distrobuilder --classic
sudo apt install -y libguestfs-tools wimtools genisoimage
@mastier
mastier / Simple script for embedding OpenVPN certificates
Last active May 26, 2023 20:50
openvpn-embed-certificates.sh
#!/bin/bash
set +e
backup() {
if [[ -e "$1.backup" ]]; then
echo "Backup file already exists! Remove if necessary."
exit 10
fi
echo "Creating backup of $1 in $1.backup" >&2
if ! type vault >/dev/null 2>&1; then "Please install vault. $ snap install vault"; exit 1; fi
export VAULT_KEYS_PATH="vault-keys.txt"
vault_init() {
VAULT_UNIT_IP=$(juju run --unit vault/leader "network-get access --ingress-address=true");
export VAULT_ADDR="http://$VAULT_UNIT_IP:8200"
echo "=== Initializing Vault by $VAULT_UNIT_IP ==="
vault operator init -key-shares=5 -key-threshold=3 > ${VAULT_KEYS_PATH}
}
# create damn simple TFTP dasemon
IFACE='ens0p25'
sudo dnsmasq -i $IFACE --dhcp-range=192.168.69.100,192.168.69.150 --enable-tftp --tftp-root=/home/$USER/tftdir -d -u $USER -p0 -K --log-dhcp --bootp-dynamic
import argparse
def f(x):
print(x)
class Fusion:
"""
@mastier
mastier / land_register_pl.py
Created June 13, 2019 13:58
Generates land register codes in Poland for given court symbol
#!/usr/bin/env python3
"""
Generates land register codes in Poland for given court symbol
"""
from itertools import starmap
import operatortype command to continue
import argparse
@mastier
mastier / reassign_shards.sh
Created April 10, 2018 17:07
reassign unassigned shards in elastic
#!/usr/bin/env bash
read -e -p 'Give cluster IP:' -i "$( hostname )" IP
read -e -p 'Give cluster node:' -i "$( hostname )" NODE
read -e -p 'any node suffix?:' -i '_es-01' SUFFIX
IFS=$'\n'
for line in $(curl -s "$IP:9200/_cat/shards" | fgrep UNASSIGNED); do
INDEX=$(echo $line | (awk '{print $1}'))
SHARD=$(echo $line | (awk '{print $2}'))
echo "Reassigning $SHARD $INDEX"
#!/usr/bin/env python3
# very crude but works ;-)
import bs4
import base64
bs4.BeautifulSoup(open('sms.xml'), 'lxml-xml')
parts=bs.findAll('part')
for part in parts:
if part.parent.parent.findAll('addr', attrs={'address':'+48XXXXXXXXXX'}):
if part.attrs['ct'] not in ('text/plain', 'application/smil'):
@mastier
mastier / huawei_e3372_sms2txt.py
Created July 1, 2017 11:37
Calculates text response from Huawei E3372 modem SMS in text mode (AT+CMGF=1) to readable one
import sys
def huawei_sms2txt(bytes):
"""
Calculates text response from Huawei E3372 modem SMS in text mode (AT+CMGF=1)
to readable one
"""
return ''.join([
y for e,y in enumerate(chr(int(x,16))
for x in re.findall(r'\w{2}', bytes)) if e % 2 != 0])