Skip to content

Instantly share code, notes, and snippets.

View cloud-init.tpl
#cloud-config
# Ensure that walinuxagent starts after cloud-init finished. That prevents the DevOps Agent starting before the Docker Daemon is ready and logged in to jfrog
bootcmd:
- mkdir -p /etc/systemd/system/walinuxagent.service.d
- echo "[Unit]\nAfter=cloud-final.service" > /etc/systemd/system/walinuxagent.service.d/override.conf
- sed "s/After=multi-user.target//g" /lib/systemd/system/cloud-final.service > /etc/systemd/system/cloud-final.service
- systemctl daemon-reload
groups:
@kgorskowski
kgorskowski / treesize.sh
Created Dec 16, 2020
treesize alternative for linux shell
View treesize.sh
#/bin/sh
du -k --max-depth=1 | sort -nr | awk '
BEGIN {
split("KB,MB,GB,TB", Units, ",");
}
{
u = 1;
while ($1 >= 1024) {
$1 = $1 / 1024;
u += 1
@kgorskowski
kgorskowski / template.sh
Created Dec 15, 2020
copy of minimal secure bash script layout
View template.sh
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
trap cleanup SIGINT SIGTERM ERR EXIT
usage() {
cat <<EOF
@kgorskowski
kgorskowski / packer-template.json
Last active Sep 26, 2018
template for my default packer/chef-solo workflow
View packer-template.json
{
"builders": [{
"ami_block_device_mappings": [{
"device_name": "/dev/sdb",
"no_device": "true"
},
{
"device_name": "/dev/sdc",
"no_device": "true"
}
View guetzli.sh
flist=(`aws s3 ls s3://karsten-lambda-test --region eu-central-1 | awk '{print $4}'`)
for i in $flist; do aws s3 cp s3://karsten-lambda-test/$i . --region eu-central-1; guetzli --quality 90 $i $i.jpeg; mv $i.jpeg $i; aws s3 cp $i s3://karsten-lambda-test/$i --region eu-central-1; aws s3api put-object-tagging --bucket karsten-lambda-test --key $i --tagging "TagSet=[{Key=guetzli,Value=true}]" --region eu-central-1; done
@kgorskowski
kgorskowski / create_deployment.sh
Last active Oct 31, 2018
recreate latest successful codedeploy deployment. needs awscli, jq and corresponding iam permissions
View create_deployment.sh
#!/bin/bash
#your variables here, you can set AWS credentials here as well
AWS_REGION=$YourAWSRegion
DEP_GROUP=$NameOfYourCodeDeployDeploymentGroup
APP_NAME=$NameOfYourCDApplication
# list successfull deployments only
STATUS=Succeeded
@kgorskowski
kgorskowski / associate_ip.sh
Created Jan 27, 2017
Reassociate AWS EIP (needs awscli, jq and the corresponding iam permissions)
View associate_ip.sh
#!/bin/bash
# Helper Functions
get_instance_region() {
if [ -z "$AWS_REGION" ]; then
AWS_REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document \
| grep -i region \
| awk -F\" '{print $4}')
fi
echo $AWS_REGION
View aws-assume-role.sh
#!/bin/bash
ADMIN_ACC_ID=$1
SESSION_NAME="adminsession"
case "$1" in
'Account1')
ADMIN_ACC_ID=1234567890
AWS_REGION=eu-central-1
;;
'Account2')
View bootstrap-consul
#!/bin/bash
hostname="consul-$(curl -s http://169.254.169.254/latest/meta-data/instance-id)"
CONF=/etc/consul/config/000-consul.json
TEMPLATE="/mnt/dashboard/consul-config/config.json"
x=0
rm -f $CONF
rm -f /tmp/instances $$ rm -f /tmp/*.json
restart consul
@kgorskowski
kgorskowski / Dockerfile
Created Jan 25, 2016
Dockerfile for SystemdMon on Alpine Linux (slack only)
View Dockerfile
FROM alpine
RUN apk add --update ruby ruby-dev curl ruby-rdoc ruby-irb && rm /var/cache/apk/*
RUN gem update --system && gem install systemd_mon slack-notifier --no-ri --no-rdoc
RUN curl -fsSL curl.haxx.se/ca/cacert.pem -o "$(ruby -ropenssl -e 'puts OpenSSL::X509::DEFAULT_CERT_FILE')"
CMD ["systemd_mon","/systemd_mon/systemd_mon.yml"]