Skip to content

Instantly share code, notes, and snippets.

@Jamesits
Jamesits / build-openlava-4.sh
Last active September 18, 2021 09:16
OpenLava 4.0 compile script for vanilla Debian 11
#!/bin/bash
apt-get update -y
apt-get install -y build-essential libncurses-dev tcl-dev autoconf automake
patch --strip=1 --forward < lim.patch
aclocal
automake
./configure --prefix=/usr/local
make -j
make install
@Jamesits
Jamesits / docker-wrapper.sh
Created September 3, 2021 08:02
Run Docker in 2021 - supports Docker & Podman in root or rootless mode.
#!/bin/bash
set -Eeuo pipefail
DOCKER_IMAGE="${DOCKER_IMAGE:-hello-world}"
DOCKER_FLAGS="${DOCKER_FLAGS:-}"
function __docker() {
if command -v docker >/dev/null; then
docker "$@"
elif command -v podman >/dev/null; then
podman "$@"
@Jamesits
Jamesits / gitlab-runner-rootless.sh
Created August 3, 2021 02:48
Run GitLab CI runner from non-root user account without it complaining for the "user mode" thing
cat > /etc/systemd/system/gitlab-runner.service.d/override.conf <<EOF
[Service]
User=gitlab-runner
Group=gitlab-runner
ExecStartPre=+ln -sf /var/run/podman/podman.sock /var/run/docker.sock
ExecStart=
ExecStart=strace -e getuid,getgid -e inject=getuid:retval=0 -e inject=getgid:retval=0 -- /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --user gitlab-runner
EOF
@Jamesits
Jamesits / asa_request_cert.sh
Last active April 9, 2023 07:35
Let's Encrypt cert requesting and signing (using acme.sh) for Cisco ASA / AnyConnect
#!/bin/bash
set -Eeuo pipefail
# Automatic cert requesting and signing for Cisco ASA
#
# Requirements
# - Domain hosted in Aliyun DNS (for other DNS services, adjust the acme.sh arguments)
# - ASA with rest-agent enabled
# - Local computer: openssl, git, ca-certificates
#
@Jamesits
Jamesits / mtr_lineprotocol.sh
Last active September 4, 2023 07:32
Convert MTR CSV output to InfluxDB line protocol
#!/bin/bash
# Converts MTR result to InfluxDB line protocol.
# Intended to be run from telegraf like this:
#
# [[inputs.exec]]
# commands = ["/path/to/your/mtr_lineprotocol.sh"]
# interval = "120s"
# timeout = "120s"
# data_format = "influx"
@Jamesits
Jamesits / Sync-Microsoft365GroupMembershipFromAzureADGroupMembership.ps1
Last active December 1, 2020 09:06
Update Microsoft 365 group membership from AzureAD-synced Active Directory group membership for Teams
#!/usr/bin/env pwsh
$ErrorActionPreference = "Stop"
# Update Microsoft 365 group membership from AzureAD-synced Active Directory group membership
# Requirements:
# Install-Module -Name AzureAD
# No need to explain
$TenantId = "<uuid>"
# Filter for the source groups
@Jamesits
Jamesits / grafana-latency-loss-graph.md
Last active July 9, 2023 04:42
Latency/packet loss graph demo for InfluxDB 2 (Flux Query Language) + Grafana

Grafana dashboard setup:

  • Query options
    • Max data points: 600 if your data collection interval is 1min, adjust on your needs
  • Visualization: Graph
  • Display:
    • Bars: off
    • Lines: off
    • Points: off
  • Series overrides
@echo on
cd /d c:\temp
if not exist %windir%\system32\wbem goto TryInstall
cd /d %windir%\system32\wbem
net stop winmgmt
winmgmt /kill
if exist Rep_bak rd Rep_bak /s /q
rename Repository Rep_bak
for %%i in (*.dll) do RegSvr32 -s %%i
for %%i in (*.exe) do call :FixSrv %%i
@Jamesits
Jamesits / NPS-Config-Sync.ps1
Created December 21, 2019 14:00
Sync 2 Network Policy Servers' configuration
###Network Policy Server Synchronization Script
#This script copies the configuration from the NPS Master Server and imports it on the secondary server.
#The Account that this script runs under must have Local Administrator rights to the NPS Master.
#This was designed to be run as a scheduled task on the NPS Secondary Servers on an hourly,daily, or as-needed basis.
# Modified from https://deployhappiness.com/two-network-policy-server-tricks-subnets-and-syncing/
###Variables
#NPSMaster - Your Primary Network Policy Server you want to copy the config from.
$NPSMaster = "adds0.corp.contoso.com"
$NPSSecondary = "adds1.corp.contoso.com"
@Jamesits
Jamesits / douban-celebrity-photos-crawler.py
Created January 1, 2019 13:13
豆瓣名人图片爬虫
#!/usr/bin/env python3
import logging
import typing
import os
import shutil
import time
import requests
from bs4 import BeautifulSoup
# logging