Skip to content

Instantly share code, notes, and snippets.

View szampardi's full-sized avatar

Silvano Zampardi szampardi

View GitHub Profile
@szampardi
szampardi / openvpn_statuslog_json.sh
Last active September 24, 2024 12:18
openvpn status.log routing table to json
#!/usr/bin/env bash
ovpn_statuslog_json() {
local _status_log=${1:-"/var/log/openvpn/status.log"}
local _grep_routing_table='^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
local _sed_csv_lines_to_array='s/^/["/g;s/,/","/g;s/$/"]/g'
local _jq_template='{
"virtual_address": .[0],
"common_name": .[1],
"real_address": (.[2]|split(":")[0]),
#!/bin/bash -e
GOVERNOR=${2:-conservative}
n=0
case "${1}" in
s | set)
for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
printf 'CPU%d\t[ %s -> %s ]\n' ${n} $(<"/sys/devices/system/cpu/cpu${n}/cpufreq/scaling_governor") "${GOVERNOR}"
echo "${GOVERNOR}" >/sys/devices/system/cpu/cpu${n}/cpufreq/scaling_governor
n=$((n+1))
@szampardi
szampardi / renamer.go
Last active February 29, 2024 00:25
cleanup file and dir names in a given path
package main
import (
"flag"
"fmt"
"os"
"path"
"regexp"
"strings"
"unicode"
#!/usr/bin/env bash
_lang=nato
while getopts ":l:" opt; do
case "${opt}" in
l) _lang="${OPTARG}" ;;
esac
done
shift $((OPTIND - 1))
FROM alpine
RUN apk update; \
apk --no-cache upgrade; \
apk add --no-cache bash
SHELL ["/bin/bash", "-o", "pipefail", "-xec"]
RUN apk add --no-cache autoconf automake file gcc git libcap-static libcap-ng libcap-ng-dev libcap-ng-static libnsl-static libltdl-static libtool linux-headers lz4-dev lz4-static make musl-dev openssl1.1-compat-dev openssl1.1-compat-libs-static pkgconfig
WORKDIR /usr/local/src/openvpn
RUN git clone --branch=v2.5.8 --depth=1 https://github.com/OpenVPN/openvpn $(pwd)
RUN autoreconf -i -v -f; \
./configure --enable-static --enable-iproute2 --disable-shared --disable-plugins --disable-selinux-build --disable-tap --disable-lzo; \
@szampardi
szampardi / phonetrack-gpsd.sh
Created January 2, 2023 10:32
Nextcloud PhoneTrack gpsd curl
#!/bin/bash
PHONETRACK_URL="https://cloud.example.com/apps/phonetrack/logGet"
PHONETRACK_SESSION=
PHONETRACK_DEVICE=
MINIMUM_SPEED=0
while getopts ":m:" opt; do
case "${opt}" in
m) MINIMUM_SPEED="${OPTARG}" ;;
#!/bin/bash -ex
_gpio="${1}"
_direction="${2:-out}"
if [[ ! -d /sys/class/gpio/gpio"${_gpio}" ]]; then
echo "${_gpio}" >/sys/class/gpio/export
fi
echo "${_direction}" >/sys/class/gpio/gpio"${_gpio}"/direction
@szampardi
szampardi / github_to_gitea.go
Last active April 22, 2022 20:14
migrate user/org repos to gitea user/org
package main
import (
"bufio"
"context"
"encoding/json"
"flag"
"fmt"
"os"
"strconv"
@szampardi
szampardi / cortex.sh
Last active September 21, 2023 17:33
use a json file for shell vars
#!/usr/bin/env bash
CORTEX_CRYPTO="aes-256-cbc"
_cortex_logger() { printf '{%s}[%s](%s):%s\t%s\n' "$(date -u '+%FT%TZ')" "${1}" "$(caller)" "${2}" "${@:3}" 1>&2; }
_cortex_io() {
case "${CORTEX_FILE}" in
"") _cortex_logger "$(caller)" ERR "CORTEX_FILE environment variable is empty/unset" && return 127 ;;
*)
@szampardi
szampardi / cip.go
Last active October 28, 2021 23:36
package main
import (
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"net"
"os"
"os/signal"