dotfiles/.dockerfunc

199 lines
4.7 KiB
Bash

#!/bin/bash
# Bash wrappers for docker run commands
# inspired by https://github.com/jfrazelle/dotfiles/ <3
#
# Helper Functions
#
dcleanup() {
docker rm -v $(docker ps --filter status=exited -q 2>/dev/null) 2>/dev/null
docker rmi $(docker images --filter dangling=true -q 2>/dev/null) 2>/dev/null
}
del_stopped() {
local name=$1
local state=$(docker inspect --format "{{.State.Running}}" $name 2>/dev/null)
if [[ "$state" == "false" ]]; then
docker rm $name
fi
}
relies_on() {
local containers=$@
for container in $containers; do
local state=$(docker inspect --format "{{.State.Running}}" $container 2>/dev/null)
if [[ "$state" == "false" ]] || [[ "$state" == "" ]]; then
echo "$container is not running, starting it for you."
$container
fi
done
}
# Applications...
bro() {
docker run -it --rm \
fschl/bropages \
bro "$@"
}
chrome() {
# add flags for proxy if passed
local proxy=
local map=
local args=$@
del_stopped chrome
# one day remove /etc/hosts bind mount when effing
# overlay support inotify, such bullshit
docker run -d \
--memory 2gb \
--net host \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
-v $HOME/Downloads:/root/Downloads \
-v $HOME/Pictures:/root/Pictures \
-v $HOME/Torrents:/root/Torrents \
-v $HOME/.chrome:/data \
-v /dev/shm:/dev/shm \
-v /etc/hosts:/etc/hosts \
--device /dev/snd \
--device /dev/dri \
--device /dev/video0 \
--device /dev/usb \
--device /dev/bus/usb \
--group-add audio \
--group-add video \
--name chrome \
fschl/chrome --user-data-dir=/data --force-device-scale-factor=1 \
--proxy-server="$proxy" --host-resolver-rules="$map" "$args"
}
eclipse() {
del_stopped eclipse
docker run -it --rm \
--net host \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
-v $HOME/projects/java/workspace:/root/workspace \
-v $HOME/.eclipse/plugins:/opt/eclipse/plugins \
-v $HOME/.eclipse/configuration:/opt/eclipse/configuration \
--name eclipse \
fschl/eclipse-jdk7:latest
}
go() {
docker run -it --rm \
-e GO15VENDOREXPERIMENT=1 \
-v "$PWD":/usr/src/myapp \
-w /usr/src/myapp \
golang:1.5 go "$@"
}
icedove() {
del_stopped icedove
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v $HOME/Downloads/:/root/Downloads \
-v $HOME/.thunderbird/:/root/.icedove \
-v $HOME/.gnupg/:/root/.gnupg \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
--name icedove \
fschl/icedove
}
latex() {
del_stopped latex
docker run -it --rm \
--net host \
-v $(pwd):/usr/src/latex \
--workdir="/usr/src/latex" \
fschl/latex "$@"
}
libreoffice(){
del_stopped libreoffice
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
-v $HOME/Documents:/root/Documents \
-e GDK_SCALE \
-e GDK_DPI_SCALE \
--name libreoffice \
fschl/libreoffice
}
pulseaudio() {
del_stopped pulseaudio
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
--device /dev/snd \
-p 4713:4713 \
--restart always \
--name pulseaudio \
fschl/pulseaudio
}
# pulseaudio() {
# del_stopped pulseaudio
# docker run -d \
# -v /etc/localtime:/etc/localtime:ro \
# --device /dev/snd \
# -p 4713:4713 \
# --restart always \
# -v /var/run/dbus:/var/run/dbus \
# -v /etc/machine-id:/etc/machine-id \
# --name pulseaudio \
# fschl/pulseaudio
# }
skype() {
del_stopped skype
docker run -d \
-v $HOME/Downloads:/root/skype/Downloads \
-v /run/user/1000/pulse:/run/user/1000/pulse \
-v /var/lib/dbus:/var/lib/dbus \
-v ~/.pulse:/root/.pulse \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
--device /dev/video0 \
--device /dev/snd \
--name skype \
--net host \
fschl/skype
}
torbrowser() {
del_stopped torbrowser
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
-e GDK_SCALE \
-e GDK_DPI_SCALE \
--device /dev/snd \
--name torbrowser \
fschl/tor-browser
# exit current shell
exit 0
}