# IT

# Bash Snippets

# Youtube-dl into Ffmpeg

Benötigt `youtube-dl`, `parallel` und `ffmpeg`.

Holt sich die direkte Video-URL via youtube-dl und piped die Video und Sound-Url direkt in ffmpeg.

Ermöglicht alles was ffmpeg kann, z.B. herauschneiden eines Clips:

```bash
URL=[url]
START=[start]
TIME=[time]
youtube-dl -g $URL | parallel -N 2 ffmpeg -ss $START -i {1} -i {2} -ss $START -map 0:v -map 1:a -t $TIME -c copy out.webm
#audio stream doesnt seem to allow input seeking (returns 403)
#so we need to do output seeking, which is... slow
#TODO: maybe find some way around that

```

# Archive Stream

```bash
STREAM=[URL]
OUTPUT=[PATH]
# as apache to write directly to webdir
sudo -u apache /usr/local/bin/streamlink -o $OUTPUT $STREAM best
# alternative: use at to run at specified time
echo "sudo -u apache /usr/local/bin/streamlink -o $OUTPUT $STREAM best" | at [TIMESPEC]

```

# DD with gzip

```bash
# create image
dd if=/dev/[DEVICE] | gzip > [IMAGE].gz
# apply image
gunzip -c [IMAGE].gz | dd of=/dev/[DEVICE]


```

# Filtered Chmod

```bash
find . [filters here] -exec chmod [MOD] -- {} +

#z.B. chmod nur Dateien
find . -type f -exec chmod 644 -- {} +


```

chmod kann bei execute-Rechten nativ Ordner und Dateien unterscheiden:

```bash
# setzt +x bei Ordnern, aber behält das execute-Flag bei Dateien unberührt
chmod -R +X [PFAD]

# geht natürlich mit dem vollen Syntax von chmod, z.B.:
chmod -R u=Xrw,g=r,o= [PFAD]

```

# Forge Install

```bash
java -jar forge-[version]-installer.jar --installServer

```

# Alacritty Terminfo

```bash
# on source
infocmp > alacritty.terminfo
# sftp transfer to target
# on target
tic -x alacritty.terminfo

```

# Telegraf Repo

Debian

```bash
curl -sL https://repos.influxdata.com/influxdb.key | apt-key add -
DISTRIB_ID=$(lsb_release -c -s)
echo "deb https://repos.influxdata.com/debian ${DISTRIB_ID} stable" | tee /etc/apt/sources.list.d/influxdb.list

```

# IP

### if up/down

```bash
ip link set dev <interface> up
ip link set dev <interface> down

```

# htpasswd

```bash
# create
htpasswd -c -B -b </path/to/users.htpasswd> <user_name> <password>
# add/change
htpasswd -B -b </path/to/users.htpasswd> <user_name> <password>

```

# Misc

```bash
# erkennt Größe der Blockdevice neu
echo 1 > /sys/class/block/sda/device/rescan

```

# Ansible ARA

## ARA Setup

Ara wird über Docker-Compose aufgesetzt:

###### ara.compose:

```yaml
version: "3"

services:
  server:
    image: recordsansible/ara-api
    container_name: ara-srv
    restart: always
    networks:
      - ara-srv
    volumes:
      - /srv/ara/:/opt/ara/
    ports:
      - "8001:8000"

networks:
    ara-srv:
        ipam:
            config:
                - subnet: 172.20.110.0/24

```

[ARA Settings](https://ara.readthedocs.io/en/latest/api-configuration.html)

###### /srv/ara/settings.yml:

```yaml
DATABASE_ENGINE: 'django.db.backends.mysql'
DATABASE_NAME: 'ara'
DATABASE_USER: 'ara'
DATABASE_PASSWORD: '[REDACTED]'
DATABASE_HOST: 192.168.2.70

default:
  ALLOWED_HOSTS:
    - 127.0.0.1
    - ::1
    - localhost
    - ara.krumel.moe

```

Reverse Proxy Setup:

###### /etc/nginx/sites-available/ara.conf:

```yaml
[..]
    auth_basic "";
    auth_basic_user_file /etc/nginx/htpasswd/htpasswd_ara;

    location / {
      proxy_pass http://localhost:8001/;
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Authorization "";
      proxy_set_header X-Forwarded-User $remote_user;
    }
[..]

```

## Ansible Setup

Initialsetup:

```bash
# im Homeverzeichnis von dediziertem Ansible-User
python3 -m venv venv
source venv/bin/activate
pip3 ansible ara
git clone git@gitea.krumel.moe:krumel/ansible.git
# von außen gitea.krumel.moe:4567

```

###### init.sh:

```bash
#!/bin/bash
source ~/venv/bin/activate

# Configure Ansible to know where ARA's callback plugin is located
export ANSIBLE_CALLBACK_PLUGINS=$(python3 -m ara.setup.callback_plugins)

# Set up the ARA callback to know where the API server is
export ARA_API_CLIENT=http
export ARA_API_SERVER="http://127.0.0.1:8001"
# Extern
#export ARA_API_SERVER="https://ara.krumel.moe"

# Extern mit Auth
#export ARA_API_USERNAME=user
#export ARA_APU_PASSWORD=password

```

Ara-Optionen können auch in `ansible.cfg` konfiguriert werden, aber da diese unterschiedlich von Host zu Host sind, macht es mehr Sinn diese in ENV zu definieren.

### Playbooks über Cron

###### crontab -e:

```cron
# zuerst init.sh ausführen, dann ansible-playbook *im* Ansible-Verzeichnis ausführen
# (damit ansible.cfg usw. gefunden wird)
# wenn die playbooks über ara aufgenommen werden, kann stdout auch nach /dev/null redirected werden
0 3 * * 5 ~/./init.sh && d ~/ansible && ansible-playbook playbooks/rpi_patches.yml

```

### Management

```bash
docker exec -it ara-srv /bin/bash
ara-manage [command]

```

# OpenSSL

## Certificate mit SANs

#### request.conf

```ini
[req]
distinguished_name = dn
prompt             = no
req_extensions     = req_ext

[dn]
C="DE"
ST="Germany"
L="."
O="ORG"
OU="ORG UNIT"
emailAddress="MAIL"
CN="COMMON NAME"

[req_ext]
subjectAltName = @alt_names

[alt_names]
DNS.1 = [Domain 1]
DNS.2 = [Domain 2]
DNS.3 = [Domain 3]

```

```bash
# create csr
openssl req -new -key private_key.key -out csr.csr -config request.conf
# check csr
openssl req -text -verify -in csr.csr
# alt.: self-sign
openssl req -new -key private_key.key -x509 -out cert.pem -config request.conf

```

## pkcs12/pfx

```bash
# create
openssl pkcs12 -export -out OUT.pfx -inkey KEY.key -in CERT.cer -in INTERMEDIATE.cer -in ROOT.cer
# export
openssl pkcs12 -in file.pfx -out file.withkey.pem -nodes

```

## keys

```bash
# rsa
openssl genrsa -out [KEY].key [encryption] [BITS]
# encryption can be omitted for unencrypted key or:
# -aes128, -aes192, -aes256, -aria128, -aria192, -aria256, -camellia128, -camellia192, -camellia256

# elliptic curve
# list available curves
openssl ecparam -list_curves
# secp384r1 or secp521r1 is a good curve
openssl ecparam -name [CURVE] -genkey -out [KEY].key

```

## get cert/key content

```bash
# cert
openssl x509 -in [CERT].crt -text
# key
openssl rsa -in [RSA-KEY] -text
openssl ec -in [EC-KEY] -text
# csr
openssl req -in [REQUEST] -text
# optionally add -check (keys) or -verify (csr) to check for consistency

# check match key and cert
openssl x509 -noout -modulus -in server.crt | openssl md5
openssl rsa -noout -modulus -in server.key | openssl md5

```

## self sign crt

```bash
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes -days 365

```

## connection testing

### https/smtps

```bash
openssl s_client -quiet -connect example.com:443
openssl s_client -quiet -connect mail.yourserver.tld:485

```

### smtp/imap starttls

```bash
openssl s_client -quiet -starttls smtp -connect mail.yourserver.tld:25
openssl s_client -quiet -starttls imap -connect mail.yourserver.tld:143

```

# IoT

# DeLock Tasmota Einrichtung

## Firmware Patches

Patches in folgender Reihenfolge anwenden

| Patch | URL |
| - | - |
| 7.2 (Hersteller) | http://www.delock.de/download/firmware/11826de.bin* |
| 8.5.1 | http://ota.tasmota.com/tasmota/release-8.5.1/tasmota.bin.gz |
| Newest | http://ota.tasmota.com/tasmota/tasmota.bin.gz |

*Adresse ist vorgegeben (für 11827 URL entsprechend anders)

Nach Patches in Console reset durchführen
```
reset 3
```

Falls Tasmote Gerät nicht automatisch erkennt, Template anwenden:
```
{"NAME":"DeLock 11826","GPIO":[32,0,0,0,0,0,0,0,224,576,0,0,0,0],"FLAG":0,"BASE":1}
ODER
{"NAME":"Delock 11827","GPIO":[0,0,0,32,2688,2656,0,0,2624,576,224,0,0,0],"FLAG":0,"BASE":53}
```

## Home Assistant Config

| Setting | Value |
| - | - |
| Host | home.krumel.moe |
| Port | 1883 (default) |
| Client | whatever, default ok |
| User | mqtt |
| Password | siehe Keepass |
| Topic | tasmota_%06X (an sich egal, hauptsache eindeutig) |

# Misc

#### Java OpenJDK11 with javaws iDRAC 8

Download and install https://adoptopenjdk.net/ Download and extract icedtea-web-1.8.win.bin.zip from https://icedtea.wildebeest.org/download/icedtea-web-binaries/1.8/windows/

edit `<java>\conf\security\java.security` and comment out

```
jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \
    DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
    include jdk.disabled.namedCurves

```

use bin/javaws.exe from icedtea-web package für iDRAC 8

# InfluxDB

**Pivot**

```flux
  |> pivot(rowKey: ["_time"], columnKey: ["host"], valueColumn: "_value")

```

**Align Timestamps**

```flux
  |> truncateTimeColumn(unit: 5m)

```

**Map**

```flux
  |> map(fn: (r) => ({_time: r._time, _value: something}))

```

# Stable Diffusion Prompts

### Styles

<table id="bkmrk-prompt-stil-by-ilya-"><thead><tr><th>Prompt</th><th>Stil</th></tr></thead><tbody><tr><td>by ilya kuvshinov</td><td>Anime-Style Portraits, neigt zu komischen Gesicherten</td></tr><tr><td>by serge marshennikov</td><td>Photographie von Frauen</td></tr><tr><td>by albert lynch</td><td>sehr gute Portraits von Frauen</td></tr><tr><td>by makoto shinkai</td><td>Landschaften, guter Anime-Stil</td></tr><tr><td>by michael whelan</td><td>tierische Körperteile (i.e. Tentakel-Haare), funktioniert manchmal (aber besser als der Rest)</td></tr></tbody></table>

### Full Prompts

<div id="bkmrk-image-prompt-stable-" style="font-family: monospace;  background-color: ghostwhite;"><table><thead><tr><th>Image</th><th>Prompt</th></tr></thead><tbody><tr><td>stable diffusion v1-4</td><td></td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662491876313.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662491876313.png)</td><td>prompt: young girl wielding tentacles, by peter mohrbacher, by studio ghibli seed:2100292404 width:512 height:512 steps:75cfg\_scale:9sampler:k\_lms model: stable-diffusion-v1-4</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662573796545.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662573796545.png)</td><td>portrait of a young girl with tentacles as hair, by ilya kuvshinov , by peter mohrbacher seed:4167947516 width:512 height:512 steps:50 cfg\_scale:8.5 sampler:k\_lms GFPGAN, GoBig</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662657333763.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662657333763.png)</td><td>portrait of a beautiful loli, lolita dress, big hat, by peter mohrbacher, by ilya kuvshinov seed:3318417621 width:512 height:512 steps:75 cfg\_scale:9 sampler:k\_lms GFPGAN, GoBig</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662661763333.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662661763333.png)</td><td>portrait of a loli dressed in tentacles, lolita dress, by peter mohrbacher, by ilya kuvshinov seed:2040376188 width:512 height:512 steps:75 cfg\_scale:9 sampler:k\_lms</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662663156167.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662663156167.png)</td><td>portrait of a loli, cat ears, frilled dress, cleavage, by peter mohrbacher, by ilya kuvshinov seed:1139153940 width:512 height:512 steps:75 cfg\_scale:9 sampler:k\_lms</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662742658072.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662742658072.png)</td><td>portrait of a loli, china dress, by seb mckinnon, by ilya kuvshinov seed:698148897 width:512 height:512 steps:50 cfg\_scale:7.5 sampler:k\_lms</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662749612944.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662749612944.png)</td><td>portrait of a loli, elaborate dress, sitting on a throne of tentacles, by peter mohrbacher, by ilya kuvshinov seed:2729380721 width:512 height:512 steps:75 cfg\_scale:10 sampler:k\_lms GFPGAN, GoBig</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662753732318.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662753732318.png)</td><td>portrait of a loli, dark dress made out of stars, looking down on the earth, by peter mohrbacher, by ilya kuvshinov seed:3317874600 width:512 height:512 steps:75 cfg\_scale:10 sampler:k\_lms GFPGAN, GoBig</td></tr><tr><td>[![ ](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662755399195.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662755399195.png)</td><td>portrait of a loli, dark dress made out of stars, walking on clouds, by peter mohrbacher, by ilya kuvshinov seed:2835881380 width:512 height:512 steps:75 cfg\_scale:10 sampler:k\_lms</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662760800390.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662760800390.png)</td><td>a loli from behind, short white dress, sitting on clouds, by ilya kuvshinov, by hiroshi yoshida, by jessica rossier seed:2891448257 width:512 height:512 steps:75 cfg\_scale:10 sampler:k\_lms</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662803511869.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662803511869.png)</td><td>octopus girl, dressed in flowers, by ilya kuvshinov, by peter mohrbacher seed:3650276312 width:512 height:512 steps:50 cfg\_scale:8.5 sampler:k\_lms</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662833025657.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662833025657.png)</td><td>a portrait of a young magical girl with shoulderlength hair, frilly colorful dress, tiara, by ilya kuvshinov, by albert lynch, by serge marshennikov, by makoto shinkai seed:2484999365 width:512 height:512 steps:50 cfg\_scale:10 sampler:k\_lms</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662846130978.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662846130978.png)</td><td>portrait of a young squid girl with tentacle hair, by albert lynch, by ilya kuvshinov, by peter mohrbacher seed:517007195 width:512 height:512 steps:75 cfg\_scale:7.5 sampler:k\_lms</td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1663524975767.jpg)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1663524975767.jpg)</td><td>portrait of a loli maid, close up, deep cleavage, by albert lynch, by peter mohrbacher, by ilya kuvshinov seed:2699117309 width:512 height:512 steps:75 cfg\_scale:9 sampler:k\_lms</td></tr><tr><td>stable diffusion v-1-5</td><td></td></tr><tr><td>[![](https://wiki.krumel.moe/uploads/images/gallery/2022-09/scaled-1680-/image-1662468423304.png)](https://wiki.krumel.moe/uploads/images/gallery/2022-09/image-1662468423304.png)</td><td>Prompt: green dumbo octopus, flowery, anime artstyle, happy, cute, by peter mohrbacher width: 512 height: 512 seed: 2279982767 cfgScale: 9 model: stable-diffusion-v1-5</td></tr><tr><td>waifu diffusion v-1-2</td><td></td></tr></tbody></table>

</div>

# Java GC-Tuning

### Java 11+

Nimm einfach shenandoah oder zgc. Üblicherweiße kein weiteres Tuning erforderlich.

### Java 8 (i.e. G1GC)

\# TODO: Parameter und Effekte erklären

```bash
 java -jar -Xms20G -Xmx20G -javaagent:jolokia-jvm-1.6.2-agent.jar\
        -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=100\
        -XX:+DisableExplicitGC -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50\
        -XX:G1MaxNewSizePercent=80 -XX:G1MixedGCLiveThresholdPercent=50\
        -XX:G1ReservePercent=20 -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4\
        -XX:InitiatingHeapOccupancyPercent=25\
        -XX:+AlwaysPreTouch -Xloggc:gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps\
        -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=1M forge-1.16.5-36.0.1.jar nogui

```

# Ansible

# Partitionierung

https://docs.ansible.com/ansible/latest/collections/community/general/parted_module.html

https://docs.ansible.com/ansible/latest/collections/community/general/filesystem_module.html

https://docs.ansible.com/ansible/latest/collections/ansible/posix/mount_module.html

##### Proxmox scsi Zuordnung

SCSI HDDs in Proxmox sind über den Hardware-Mountpoint identifizierbar:

```bash
#in Proxmox scsiN
lsscsi -b 0:0:0:N | grep -o -e '/dev/\w*'

#Zuordnung UUID
lsscsi -b | grep -o -e "/dev/sd\w*" | xargs lsblk -no +UUID {}
```