Skip to content

Instantly share code, notes, and snippets.

IS_LOCKED=$(sudo lsof /var/lib/dpkg/lock | wc -l)
echo "Is Locked? $IS_LOCKED"
until [[ $IS_LOCKED -eq 0 ]]; do
echo "Is Locked? $IS_LOCKED"
echo "sleeping for 5"
sleep 5
IS_LOCKED=$(sudo lsof /var/lib/dpkg/lock | wc -l)
done
@alwalker
alwalker / yum_dep_finder.sh
Created May 14, 2018 14:44
Find yum repos that you're using based on actually installed packages
yum repolist | grep -Po "^[\w|-]+(?=\/)" | xargs yumdb search from_repo | grep -Po "=\K .+" | sort - | uniq - | sed -e 's/^[[:space:]]*//' | awk '{system("repoquery --repoid="$1" -a --location")}' | grep -oP "^.+\://\K[^/]+(?=/.+)" | sort - | uniq - | awk '{system( "echo && host "$1)}'
@alwalker
alwalker / certbot_cloudflare.sh
Created August 7, 2018 13:25
Flags needed to make dns challenge for letsencrypt work with cloudflare
sudo certbot renew --preferred-challenges dns --dns-cloudflare --dns-cloudflare-credentials ~/.secrets/cloudflare.ini --dry-run
@alwalker
alwalker / get_latest_blob.sh
Created February 19, 2019 14:57
Get Latest BLOB
NEWEST_BLOB=$(az storage blob list \
--account-key $STORAGE_KEY \
--account-name $STORAGE_ACCOUNT \
-c $CONTAINER \
--prefix $PREFIX \
--query "[*].{name: name, date: properties.lastModified } | sort_by([*], &date) | [-1].name")
NEWEST_BLOB=$(echo $NEWEST_BLOB | tr -d \")
@alwalker
alwalker / add_current_ip_to_fw.sh
Created October 2, 2020 15:23
One liner for adding your current IP to a Azure SQL Server firewall. Used in ADO.
MYIP=$(curl -s http://ipinfo.io/json | jq -r '.ip') && \
MATCH="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" && \
if [[ $MYIP =~ $MATCH ]]; then \
echo "Adding $MYIP to $(SERVER_NAME) firewall"; \
az sql server firewall-rule create -g $(RESOURCE_GROUP) -s $(SERVER_NAME) -n ALLOW_ADO --start-ip-address $MYIP --end-ip-address $MYIP; \
else \
echo "$MYIP is not a valid IP address."; \
exit 1; \
fi
@alwalker
alwalker / gitfinder.sh
Created January 11, 2021 14:51
Search current directory for git repos and generate script to recreate them.
set -e
echo "set -e" > gitbuilder.sh
dirs=()
readarray -d '' dirs < <(find . -name .git -type d -prune)
for dir in ${dirs[@]}; do
cleandir=$(echo $dir | sed 's/\.git//')
remote=$(git --git-dir=$dir remote -v | grep fetch | sed -r 's/origin\s+//' | sed -r 's/\s+\(fetch\)//')
@alwalker
alwalker / ado_merger_release_env_vars.sh
Created February 24, 2021 16:40
A script to merge the variables for two environments in an Azure DevOps release pipeline.
#!/usr/bin/env bash
set -e
#Check Arguments
if [ $# -lt 3 ]; then
echo "Insuffecient arguments supplied. Shoudl be: ado_copy_relase_vars.sh src dest RELEASE_ID"
exit 1
fi
SOURCE_ENV=$1
DEST_ENV=$2
@alwalker
alwalker / az_app_svc_manual_wh.sh
Created April 15, 2021 20:48
Script for hitting Azure App Services web hook for "continuous deployment" with containers.
if [[ "$#" -ne 6 ]]; then
echo -e "Incorrect number of arguments. You need to provide:\nImage Repository\nImage Tag\nRegistry FQDN\nWebhook URL\nWebhook User\nWebhook Password"
exit 1
fi
IMAGE_REPOSITORY=$1
IMAGE_TAG=$2
REGISTRY_FQDN=$3
HOOK_URL=$4
HOOK_USER=$5
stages:
- build
- deploy
docker-build:
image: docker:latest
stage: build
services:
- docker:dind
before_script:
export LC_ALL=C
FILE_NAME=$(date +%s).sar
for file in /var/log/sysstat/sa[0-9]*; do sar -A -f "$file" >> ~/$FILE_NAME; done