Skip to content

Instantly share code, notes, and snippets.

Avatar

Amit Bakshi ambakshi

View GitHub Profile
View secure-aes-gen.sh
#!/bin/bash
#
# Create a variable `$key` for use in powershell as a AES encyrption key
# constant with (ConvertFrom-SecureString)[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/convertfrom-securestring?view=powershell-7.2)]
#
# param: $1 secret key (optional, default: secret)
# param: $2 cipher (optional, default: aes-256-cbc)
# output: An byte array (in decimals), the size of the encryption key (AES256 = 32 bytes)
genkey() {
@ambakshi
ambakshi / g++-5.sh
Created Apr 1, 2016
Install g++ 5.x on Ubuntu Trusty (14.04)
View g++-5.sh
#!/bin/bash
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common
add-apt-repository ppa:ubuntu-toolchain-r/test
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y g++-5 gcc-5
@ambakshi
ambakshi / bash_aliases
Last active Oct 27, 2021
Bootstrap vim and tmux
View bash_aliases
#!/bin/bash
# shellcheck disable=SC1073,SC1007,SC1072,SC1090,SC1091,SC2015
if [[ $UID -ne 0 ]]; then
if ! type -t __git_ps1 >/dev/null 2>&1 && test -e /usr/share/git-core/contrib/completion/git-prompt.sh; then
. /usr/share/git-core/contrib/completion/git-prompt.sh
fi
if type -t __git_ps1 >/dev/null 2>&1; then
PS1='[\[\033[32m\]\u@\h\[\033[00m\] \[\033[36m\]\W\[\033[31m\]$(__git_ps1)\[\033[00m\]] \$ '
@ambakshi
ambakshi / iam-assume-role.sh
Last active Oct 25, 2021
Assume an IAM role. An interesting way of doing IAM roles is to give the instance permissions to assume another role, but no actual permissions by default. I got this idea while setting up security monkey: http://securitymonkey.readthedocs.org/en/latest/quickstart1.html#setup-iam-roles.
View iam-assume-role.sh
#!/bin/bash
#
# Assume the given role, and print out a set of environment variables
# for use with aws cli.
#
# To use:
#
# $ eval $(./iam-assume-role.sh)
#
@ambakshi
ambakshi / route53-asg-rrdns.sh
Last active Jul 25, 2021
Add all instances in an autoscaling group to an equivalently named dns entry.
View route53-asg-rrdns.sh
#!/bin/bash
#
# Get all IPs from an autoscale group and update set the local ip as
# equal weight A entries (round robin dns). Takes autoscale group as
# parameter.
#
# Amit Bakshi
# 10/21/2014
#
@ambakshi
ambakshi / docker-direct-lvm.sh
Last active Jan 14, 2021
docker-direct-lvm
View docker-direct-lvm.sh
#!/bin/bash
set -e
## striping seems to break docker
#STRIPE="-i2 -I64"
#DEVS="/dev/xvdf /dev/xvdg"
DEVS="$1"
if [ -z "$DEVS" ]; then
echo >&2 "Specify which block devices to use"
exit 1
@ambakshi
ambakshi / parse-opts.sh
Last active Jan 10, 2021
parse-opts.sh
View parse-opts.sh
#!/usr/bin/env bash
#
# MIT Licensensed
# Amit Bakshi Jan 2021
# Generic option parser.
# Usage:
# parse_opts --valid-args 'foo bar link' -- --with-foo=yes --bar=fizz --no-link
#
# Yields:
@ambakshi
ambakshi / cloud-init.sh
Last active Dec 11, 2020
Amazon Linux cloud-init script
View cloud-init.sh
#!/bin/bash
#
# Amazon Linux cloud-init script
#
# Amit Bakshi
# 10/2014
#
if [ `id -u` -ne 0 ]; then
sudo exec /bin/bash -x "$0" "$@"
fi
@ambakshi
ambakshi / ssh-keygen.service
Last active Aug 6, 2020 — forked from TimJDFletcher/ssh-keygen.service
Systemd unit to generate missing ssh keys on boot
View ssh-keygen.service
[Unit]
Description=Generate sshd keys
Before=ssh.service
ConditionPathExists=!/etc/ssh/ssh_host_rsa_key
[Service]
Type=oneshot
ExecStart=/usr/bin/ssh-keygen -A
RemainAfterExit=true
StandardOutput=journal
View Autounattend.xml
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SetupUILanguage>
<UILanguage>en-US</UILanguage>
</SetupUILanguage>
<InputLocale>en-US</InputLocale>
<SystemLocale>en-US</SystemLocale>
<UILanguage>en-US</UILanguage>