Skip to content

Instantly share code, notes, and snippets.

@smoser
smoser / apt-go-fast
Last active January 15, 2020 22:12
apt-go-fast: streamline apt-get by removing things you don't want or need and using eatmydata
#!/bin/sh
# https://gist.github.com/smoser/5823699
set -e
[ "$(id -u)" = "0" ] && sudo="" || sudo="sudo"
[ -e "/usr/bin/apt-get.distrib" ] ||
$sudo dpkg-divert --local --rename --add /usr/bin/apt-get
$sudo tee /usr/bin/apt-get >/dev/null <<"EOF"
#!/bin/sh
@smoser
smoser / ubuntu-cloud-virtualbox.sh
Last active April 2, 2024 21:07
example of using Ubuntu cloud images with virtualbox
## Install necessary packages
$ sudo apt-get install virtualbox-ose qemu-utils genisoimage cloud-utils
## get kvm unloaded so virtualbox can load
$ sudo modprobe -r kvm_amd kvm_intel
$ sudo service virtualbox stop
$ sudo service virtualbox start
## URL to most recent cloud image of 12.04
$ img_url="http://cloud-images.ubuntu.com/server/releases/12.04/release"
@smoser
smoser / lxc-clone-readme.sh
Last active December 20, 2015 21:48
Demonstrate lxc clone via overlayfs and ubuntu-cloud clone hook supporting user-data.
###
### Fast cloning with overlayfs, and specifying user-data on clone
### blog post:
### http://ubuntu-smoser.blogspot.com/2013/08/lxc-with-fast-cloning-via-overlayfs-and.html
###
### Eventually, this should make it into 13.10 and the stable lxc ppa
### https://launchpad.net/~ubuntu-lxc/+archive/stable
### But right now you'll have to use the daily ppa.
@smoser
smoser / example_config.sh
Last active December 22, 2015 11:38
parse_shell_config: basically reads a "shell config" in python by running it with bash, and then reading the variables declared. It returns an dict with the variables found after running that code. the point of using this is that some software has "config" in shell format (ie, 'openrc' in openstack).
DISK_ID='1'
ETH0_DNS='10.0.0.1'
ETH0_GATEWAY='10.0.0.1'
ETH0_IP='10.0.0.72'
ETH0_MASK='255.255.255.0'
FILES_DS='/var/lib/one/datastores/2/9c92ad910c0b30a411ccdfc141bc7a25:'\''jfopet.sh'\'' '
FILES_URL='http://10.0.0.11/files/installer.tar.gz'
INIT_SCRIPTS='jfopet.sh'
MANIFEST='ubuntu-kvm1'
SSH_PUBLIC_KEY='ssh-dss AAAAB3NzaC1kc3MAAACBANprdUVFRaADZXZaAm2elpRaUGCMETLLuYYJCDUZPb0Dh/V7KeM2/a3rFIDA0s5sVK2XQNqLHyy0U8xA/0R8dplmg7BDckkAzhrDVpEGnQE1fk/xPd1t7u+yeVqpbrfyAmfmyE2P980mhBoWalbeV/f7SmHUP8RiQ2hlAWUxr7I5AAAAFQDLHhFndbcA7svGd/yfY6nU4ubodwAAAIAoXLKlckmZur1pc9TN4XoHa+Fl/6Qpu0XO7Ai/tu8dqHlN+FpVk8BQNnokwE+EZBARLIL0JCjHpT9b5aEvlpRz3TuDa6az8wvJRlScNufmVrf0ls1WCFDHujSLzd3aOkKct35Aamf1amP/NPE2aGne/tPS7HQ3TCf5E2MAQzYVJKSARwAAAIAaVqvU7LfGMEw0hEXr7fuJCMHh4FmPvejiOoSUz2GOU5bceasRitdulCQJbNiVtY6U0S+qQ0X8rvAnG934p4zS9TtgKIhplr146fkbYnNjCaAM0rNVvTh2SzEEKJiG2G1d3wyNuO8wpPhIiJ1OVZrGwkVyWwiNzC2sWXAXldQ9Hg== user1@host
@smoser
smoser / distro_info_dict
Created October 1, 2013 19:54
extract data from distro_info to a dict. Quite possibly this should just read from /usr/share/distro-info/ubuntu.csv instead of using distro_info library. However, this seems functional for what I needed.
#!/usr/bin/python
import distro_info
def get_ubuntu_info(date=None):
# this returns a sorted list of dicts
# each dict has information about an ubuntu release.
# Notably absent is any date information (release or eol)
# its harder than you'd like to get at data via the distro_info library
@smoser
smoser / upget
Last active December 29, 2015 08:59
upget: ubuntu pastebin getUbuntu pastebin requires login to download raw files. Thats annoying.This works around that. Only works for files pasted with 'plain' type (ie no syntax highlighting).
#!/usr/bin/python
# ubuntu pastebin getter [https://gist.github.com/smoser/7647304/]
# upget http://paste.ubuntu.com/8508062/ f.txt
# upget http://paste.ubuntu.com/8508062/ > f.txt
# wget http://sn.im/upget -O upget && chmod 755 upget
from __future__ import unicode_literals
import sys
import urllib3
try:
from html.parser import HTMLParser
@smoser
smoser / partition
Created December 11, 2013 19:34
partition: partition a disk with a single partition using either GPT or MBR partition table format. This is just a simple front end to 'sfdisk' or 'gpt' to put a partition on a image.
#!/bin/bash
VERBOSITY=0
error() { echo "$@" 1>&2; }
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
Usage() {
cat <<EOF
Usage: ${0##*/} [ options ] target-dev
@smoser
smoser / README.md
Last active February 7, 2018 06:19
Example ~/.euca directory contents for AWS (EC2, IAM ...). In euca2ools 3.0+, .eucarc is deprecated, replaced by ~/.euca directory.

Example contents of .euca directory for a user

This is example ~/.euca contents for a user. Documentation on this is found at upstream. See also example in source.

  • defaults.ini: default region and user config (default-*) configuration
  • myaws-user.ini: example user stanza (providing credentials). This should be readable only by you (chmod go-r myuser.ini).
  • generate-aws: script to generate the aws.ini file as it is repetitive.
  • aws.ini: example generated with generate-aws
@smoser
smoser / README.md
Last active March 17, 2016 00:03
script for dd-wrt to set up ipv6 using tunnelbroker.net. Originally found at http://www.dd-wrt.com/wiki/index.php/IPv6_setup_Hurricane_Electric_Tunnel_Broker
@smoser
smoser / test-image
Created March 13, 2014 20:18
test 2 different base images to compare behavior / performance
#!/bin/bash
## images were created with something like this:
## mv trusty-server-cloudimg-amd64-disk1.img img.dist
## qemu-img convert -O raw img.dist disk-patched.img
## qemu-img convert -O raw img.dist disk-unpatched.img
## sudo mount-image-callback -v disk-patched.img -- \
## sh -c 'cp debs/* $MOUNTPOINT/tmp &&
## LANG=C chroot $MOUNTPOINT sh -c "dpkg -i /tmp/*.deb" &&
## rm $MOUNTPOINT/tmp/*.deb'