Skip to content

Instantly share code, notes, and snippets.

View chaddupuis's full-sized avatar

Chad Dupuis chaddupuis

View GitHub Profile
@chaddupuis
chaddupuis / deepdicomsort-dcm2-fsl.def
Created April 15, 2024 15:46
apptainer build for deepdicomsort-dcm2niix-fsl on rockylinux8
Bootstrap: docker
From: rockylinux:8.9
%post
dnf -y update
dnf -y install epel-release curl wget git file bzip2 which libmng libpng12 libSM gtk2 mesa-dri-drivers mesa-libGL-devel
dnf config-manager --set-enabled powertools
dnf -y install R
# R brings in openblas and dependencies
dnf -y install make cmake
@chaddupuis
chaddupuis / macos-ciscovpn-connect.sh
Last active November 30, 2023 23:04
macOS Cisco AnyConnect CLI Connect Without Password (using macOS keychain)
#!/bin/sh
VPNNUM=#you might not have a choice here, so possibly not needed
ADDRESS=vpn.com
USER=yourusername
PASS=$(security find-generic-password -a yourusername -l yourkeylistitem -w)
/usr/bin/expect -f - <<EOD
set timeout 20
@chaddupuis
chaddupuis / docker-fix-networking.sh
Created November 14, 2023 21:11
Docker - Allow Communication Between Two Bridged Networks On Same Host (via iptables)
#!/bin/bash
## If docker containers are running on two separate bridge networks,
## by default they cannot communicate
## To selectively allow this you can use iptables rules to allow communication.
## This script, connects an app ("webapp") to a database ("postgres") running on separate networks.
postgresip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' postgres)
webappip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' webapp)
@chaddupuis
chaddupuis / backup-borg-to-hetzner-storage.sh
Created December 21, 2022 18:58
Borg Backup Bash Script to Hetzner Storage Box
#!/bin/bash
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
## Backup websites and related files along with databases with borg to a storage box on hetzner.
## borg variables
## Must use borg >1.1 on deb 9 $ apt -t stretch-backports install borg-backup
export BORG_RSH="ssh -i /your/key"
export BORG_PASSPHRASE="yourpassphrase"
LOG="/var/log/borg/backup.log"
BACKUP_USER="hetzneruser"
@chaddupuis
chaddupuis / lstocsv.sh
Created August 7, 2023 14:37
linux - ls files into a csv (without dot files and without the created csv)
#!/bin/bash
find . -type f \( ! -iname ".*" ! -iname "mydir.csv" \) -exec basename {} \; | xargs | tr -s ' ' , > mydir.csv
@chaddupuis
chaddupuis / pipupdater.sh
Created August 2, 2023 20:35
Update outdated python packages in docker container and write out new requirements.txt
#!/usr/bin/env bash
#set -euo pipefail
# no set -e has diff results in non-zero
echo "Checking Inside of Container For Outdated Pip"
hostdatetime=$(date +"%d-%m-%y-%H-%M-%S")
docker exec -i yourcontainer /bin/sh -c 'python3 -m pip list --outdated'
@chaddupuis
chaddupuis / getdatafromqemu.md
Last active July 13, 2023 15:10
Recover Data From A Multipass Qemu VM Image That Won't Start on MacOS M1/M2 (using linux)

Multipass on MacOS m1/m2 machines has had some ongoing issues with VM's working for awhile then failing to start. Previously, through some combination of these steps, I could get multipass working again and access my previous builds. After losing some data a couple of times this way, I've decided to ditch multipass for now. Unfortunately, this one time I had some data from an unfinished build that I had to get off one of the vm images that I could no longer start.

I tried a few ways of doing this solely on the mac, but I ended up copying the image file over to a desktop running suse/tumbleweed (distro shouldn't matter for these) and accessing the files there. Here are the general steps:

  • Find your vm image (need sudo). On a mac these should be in /var/root/Library/Application\ Support/multipassd/qemu/vault/instances/ - then in a folder with the name of your vm, grab the .img file and copy it somewhere and chown it to your local account.

  • Copy the

@chaddupuis
chaddupuis / settings.py
Created December 21, 2022 19:26
Django Recaptcha fix for SSL:CERTIFICATE_VERIFY_FAILED unable to get local issuer
'''
There are likely a few fixes for this but you are likely to see this error
if your app needs to reach out to an https server (in this case https://google.com)
and it cannot verify the ssl certificate.
The certifi package ( https://pypi.org/project/certifi/ ) provides a
curated collection of Root Certificates that avoids this.
pip install certifi - then in your settings you just need to set
the environmental variable for REQUESTS_CA_BUNDLE and SSL_CERT_FILE.
@chaddupuis
chaddupuis / nginx-ansible-server.yaml
Created December 21, 2022 19:23
Ansible to build an nginx server with certbot
# post base server setup
# nginx, pulls confs from git repo
# certbot setup and general firewall conf
#
- hosts: nginxweb
become: yes
vars:
my_ip_range: x.x.x.x/24
my_jump_ip: x.x.x.x
@chaddupuis
chaddupuis / renew-certs.sh
Created December 21, 2022 19:21
Lego (acme go client) bash script for renewals (with SAN lists)
#!/bin/bash
# Likely in a cron job to handle cert renewals.
# The acme go client is here - https://github.com/go-acme/lego
lego_bin=/etc/goclient/lego/lego
lego_path=/etc/goclient/lego
lego_certs="$lego_path/certificates"
web_root=/var/www/html
our_kid=""