Skip to content

Instantly share code, notes, and snippets.

View jeremiehuchet's full-sized avatar

Jérémie Huchet jeremiehuchet

View GitHub Profile
@jeremiehuchet
jeremiehuchet / README.md
Created August 19, 2024 21:16
Reduce a mounted filesystem on an LVM partition

This note explain how to reduce a mounted filesystem on an LVM partition. It requires a reboot but most of the operations can be done online and the system can be used during the operations.

  1. Remount filesystem read-only
sudo mount -f -o remount,ro /home
  1. Snapshot the volume hosting the filesystem
sudo lvcreate -s data/home -L 30G -n home_resize
sudo lvdisplay data/home_resize                 
@jeremiehuchet
jeremiehuchet / README.md
Last active August 23, 2024 16:41
Shelly modules MQTT announcement for Home-Assistant
@jeremiehuchet
jeremiehuchet / jwt.sh
Last active June 13, 2022 15:32
generate JWT token
#!/usr/bin/env bash
set -e
# see https://techdocs.akamai.com/iot-token-access-control/reference/generate-jwt-rsa-keys
PRIVATE_KEY_PEM="$1"
b64encode() {
echo -n "$*" | base64 -w 0 | sed s/\+/-/ | sed -E s/=+$//
}
@jeremiehuchet
jeremiehuchet / setup.sh
Last active February 25, 2022 12:33
Nixos 20.03 base install (legacy boot, encrypted root, lvm)
#!/bin/bash
# setup wifi
wpa_supplicant -B -i interface -c <(wpa_passphrase 'SSID' 'key')
# partition disks
# sda1 /boot
# sda2 LVM PV
# - vg hdd
# - lv root
@jeremiehuchet
jeremiehuchet / fetchDocker.nix
Created April 25, 2020 21:40
nix function to fetch docker image content
{ pkgs }:
{
# fetch docker image content and return path in nix store
# inspired from https://github.com/NixOS/nixpkgs/blob/6dab1b50a63fa6e9dfb9bd9eddd3f5d5c7b055ef/pkgs/build-support/docker/default.nix#L264
fetchDocker = coordinates:
let
name = "${coordinates.finalImageName}-${coordinates.finalImageTag}";
result = pkgs.dockerTools.runWithOverlay {
name = "docker-exporter-${name}";
@jeremiehuchet
jeremiehuchet / README.md
Created February 12, 2020 14:41
Setup HP DeskJet Pro 9600 printer on nixos

HP DeskJet Pro 9600

In /etc/nixos/configuration.nix:

services.printing.enable = true;
services.printing.drivers = [ pkgs.hplip ];
services.printing.startWhenNeeded = true; # optional

users.users..extraGroups = [ ... "lp" ... ];
@jeremiehuchet
jeremiehuchet / gpg-secret-key-backup.sh
Last active February 12, 2020 14:28
Backup GPG key
#!/bin/sh -e
if [[ $# -ne 1 ]] ; then
cat - <<HELP
usage: $0 <gpg secret key id>
Generates a printable PDF file <gpg secret key id>-backup.pdf for the given key id.
HELP
exit 1
fi
@jeremiehuchet
jeremiehuchet / get_original_dst.go
Created September 22, 2017 15:27 — forked from fangdingjun/get_original_dst.go
golang: get the original destination for the socket when redirect by linux iptables
// get the original destination for the socket when redirect by linux iptables
// refer to https://raw.githubusercontent.com/missdeer/avege/master/src/inbound/redir/redir_iptables.go
//
const (
SO_ORIGINAL_DST = 80
IP6T_SO_ORIGINAL_DST = 80
)
func getOriginalDst(clientConn *net.TCPConn) (rawaddr []byte, host string, newTCPConn *net.TCPConn, err error) {
if clientConn == nil {