Skip to content

Instantly share code, notes, and snippets.

@alecs
alecs / dyndns-mikrotik-ros7.rsc
Last active March 25, 2024 22:31
dyndns-mikrotik-ros7.rsc
:global ddnsuser "xxx"
:global ddnspass "yyy"
:global theinterface "pppoexxx"
:global ddnshost chosen.name.here
:global ipddns [:resolve $ddnshost];
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
:log info ("no-ip.ro: No ip address on $theinterface .")
} else={
:for i from=( [:len $ipfresh] - 1) to=0 do={
@alecs
alecs / gist:a9df14fd5d290207440b408ff17ab1a8
Created March 29, 2023 11:05
change-http-88-disable-ssl-ubiquiti-xm.sh
sed -i 's%httpd.port=.*%httpd.port=88%g;s%httpd.https.status=.*%httpd.https.status=disabled%g;' /tmp/system.cfg && cfgmtd -w -f /tmp/system.cfg && reboot
@alecs
alecs / getvzres.sh
Created January 16, 2023 15:48
extract resources per OpenVZ running container
#!/bin/bash
if [[ -f "/usr/sbin/vzlist" ]]; then
vzlist -a | awk '/^\s+[0-9]/ { print $1" "$5 }' | while read ct_id ct_host; do
echo -ne "${ct_host}\t";
vzctl runscript ${ct_id} $0
done
else
CPU=$(awk '/processor/ { cpu+=1 }; END { print cpu }' /proc/cpuinfo);
MEM=$(awk '/^MemTotal:/ { print $2/(1024*1024) }' /proc/meminfo);
DISK=$(df -k | awk '!/^tmp/ && !/^Filesystem/ {mp[$1"-"$2"-"$3]=$3 }; END {for (key in mp){ size+=mp[key]}; print size/(1024*1024)}');
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
ls = log --color --graph --pretty=format:'%Cred%h%Creset [%ad] -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue) <%an>%Creset' --abbrev-commit --date=short
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
lnc = log --pretty=format:"%h\\ %s\\ [%cn]"
lds = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
ld = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative
le = log --oneline --decorate
fl = log -u
dl = "!git ll -1"
@alecs
alecs / add_jaileduser.sh
Created October 25, 2022 11:59
jailkit base setup
#!/bin/bash
#
# This script adds a jailed user and prompts admin to add the pubkey for that user
#
# Alex Negulescu <alecs@sysops.ro>
#
#
[ $# -ge "4" ] || { echo "Usage : $0 -j JAILROOT -u USER1[,USER2,USERx]" [-k IF PUBKEY IS ASKED FOR]; exit 1; }
OPTIONS=$(getopt -o j:u:k --long jaildir:,users:,key -n "$0" -- "$@")
@alecs
alecs / ssl_scanner.awk
Created October 5, 2022 13:35
ssl scanner
#!/usr/bin/awk -f
#
# Print validty of a cert from a nmap scan report
#
# Alex Negulescu
#
BEGIN {
nd=0
start=0
has_ssl=0
@alecs
alecs / portainer-only.yml
Created September 28, 2022 12:00
traefik v28 + portainer 2.15 docker-compose
#
# mkdir -p /shared/portainer/data/
# docker-compose -f portainer-only.yml -p portainer up -d
#
version: '3.7'
services:
portainer:
image: portainer/portainer-ce:latest
container_name: 'portainer'
@alecs
alecs / sqlite3.sh
Last active July 22, 2022 11:10
add-sqlite3-to-grafana-var-lib
#!/bin/bash
cd /var/lib/grafana/; mkdir sqtemp; apk fetch sqlite; tar -C sqtemp/ -xzf sqlite-*.apk ; mv sqtemp/usr/bin/sqlite3 sqlite3; rm -rf sqtemp sqlite-*.apk
@alecs
alecs / system-sleep-xhci.sh
Last active February 23, 2022 09:16 — forked from ioggstream/system-sleep-xhci.sh
Disable broken xhci device before suspend and avoid freeze.
#!/bin/sh
#
# This script should prevent the following suspend errors
# which freezes the Dell Inspiron laptop.
#
# Put it in /usr/lib/systemd/system-sleep/xhci.sh
#
# The PCI 00:14.0 device is the usb xhci controller.
#
# kernel: [67445.560610] pci_pm_suspend(): hcd_pci_suspend+0x0/0x30 returns -16
@alecs
alecs / gist:606ec763ddf3fcaf675f3a682c11d623
Created November 19, 2021 17:11
mongodb entrypoint.sh
#!/bin/sh
# short circuit if first arg is not 'mongod'
[ "$1" = "mongod" ] || exec "$@" || exit $?
: ${MONGO_USERNAME}
: ${MONGO_PASSWORD}
# Database owned by mongodb
[ "$(stat -c %U /data/db)" = mongodb ] || chown -R mongodb /data/db