Skip to content

Instantly share code, notes, and snippets.

@mlgrm
mlgrm / cros_docker.sh
Last active January 7, 2019 11:46
create a container running docker on a powerwashed chromebook. to be run from termina.
#!/bin/bash
# to use, run: curl -sL bit.ly/mlgrm-cros_docker_sh | bash
set -e
set -x
# download a big image
lxc launch ubuntu:16.04 docker
# make a copy of the default profile
@mlgrm
mlgrm / docker_tidyverse.sh
Last active January 7, 2019 11:40
pull and run tidyverse container on chrom(e|ium) os (lxd) container docker
#!/bin/bash
set -e
set -x
# first make sure you have the docker container running:
# https://gist.github.com/mlgrm/6d8af41fb40640355d4bdb2d8bb597d4
# to run from termina:
# curl -sL bit.ly/mlgrm-docker_tidyverse_sh | lxc exec docker -- sudo -u ubuntu --login bash
# to run directly from a docker host:
@mlgrm
mlgrm / google-api.sh
Last active February 19, 2019 14:58
make calls to the google api using oauth2
#!/bin/bash
# google-auth [options] [[http[s]://]api-server]endpoint [key=value ...]
#
# ###########
# # options #
# ###########
#
# all options can be set as environment variables, i.e.:
# > google-api --option-name "option-value" ...
# is equivalent to
@mlgrm
mlgrm / borgify.sh
Last active January 27, 2019 09:53
google cloud snapshot to borg backup migration script
#!/bin/bash
###############################################################################
# borgify.sh - google cloud snapshot to borg backup migration script #
###############################################################################
#
# for every snapshot of SOURCE_DISK,
# 1. create a disk from it
# 2. mount it on a server
# 3. back up TARGET_DIR to RSYNC_LOGIN/~/REPO
# 4. unmount and delete the disk
#!/bin/bash
# roll out a gcp compute instance running container-optimized os or ubuntu 18.04
# you need to have gcloud configured with a project and region/zone
# usage: curl -sL bit.ly/mlgrm-gcp-docker | bash
DAYS=${DAYS:-36500}
HOST=${HOST:-cosima}
LOGIN=chronos@$HOST
IP_NAME=${IP_NAME:-$HOST}
BOOT_DISK_SIZE=${BOOT_DISK_SIZE:-10GB}
#cloud-config
#
# run docker with tls for remote management
packages:
- dmsetup
- libdevmapper1.02.1
- libparted2
- parted
write_files:
- path: /etc/docker/daemon.json
@mlgrm
mlgrm / chromeos-rstudio
Last active March 5, 2019 10:04
run mlgrm/tidyverse on a docker.io host running in an lxc container called docker on your chromebook (from termina)
#/bin/bash
# usage: curl -sL bit.ly/mlgrm-rstudio | DOCKER_HOST=docker DOCKER_USER=ubuntu USER=rstudio bash
DOCKER_HOST=${DOCKER_HOST:-"docker"}
DOCKER_USER=${DOCKER_USER:-"ubuntu"}
USER=${USER:-"rstudio"}
lxc exec $DOCKER_HOST -- sudo su - $DOCKER_USER -c "\
docker run -d \
--name rstudio \
@mlgrm
mlgrm / chrome-os-docker-host.sh
Last active February 27, 2019 11:18
set up an lxc container running ubuntu 18.04 and docker.io on chromeos
#!/bin/bash
# usage:
# curl -sL bit.ly/mlgrm-docker | HOST_NAME=name bash
# all flags can be replaced by env vars with the usual keymapping
trap clean_up ERR SIGTERM SIGINT
clean_up () {
lxc rm --force $HOST_NAME
lxc profile delete $HOST_NAME
@mlgrm
mlgrm / new-penguin.sh
Last active March 5, 2019 13:17
replace chrome os's default penguin lxc container with ubuntu 18.06 running docker.io and a few extras.
#!/bin/bash
# usage: curl -sL bit.ly/mlgrm-penguin | [ KEY=value [...] ] bash
# keys:
# USER_NAME google user name.
# RCLONE_TOKEN (optional) valid token generated by rclone on the user's drive
# if provided, the home directory will be recovered from penguin/home/$USER_NAME
# and backups scheduled hourly
@mlgrm
mlgrm / install_cros_guest.sh
Last active March 4, 2019 13:44
add guest packages to ubuntu 18.04 so we can use it as penguin
#!/bin/bash
# usage curl -sL bit.ly/mlgrm-cros-guest | lxc exec penguin -- bash
set -e
# adapted from:
# http://joshua.blogspot.com/2018/08/introduction-to-crostini-part-3-using.html
# (which used to be public...)
apt-get update