Last active
March 7, 2017 03:16
-
-
Save SISheogorath/4e49af5bb594bc314ee986492d773255 to your computer and use it in GitHub Desktop.
Docker based version of the ruby twitter client "t"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Place this in the $TWITTER_DIR | |
FROM ruby:2.3 | |
RUN gem install t | |
ENTRYPOINT ["t"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
OPWD=`pwd` | |
# Place the Dockerfile in $TWITTER_DIR before run this script | |
TWITTER_DIR="$HOME/.twitter-cli" | |
TWITTER_RCFILE="$HOME/.trc" | |
TWITTER_IMAGETAG="twitter:local" | |
# Check that all we need exists | |
command_exists() { command -v $1 >/dev/null 2>&1 || { echo >&2 "I require $1 but it's not installed. Aborting."; exit 1; }; } | |
docker_installed() { command -v docker >/dev/null 2>&1 || { wget -O- http://get.docker.com | sh - ; }; command -v docker >/dev/null 2>&1 || { echo >&2 "I require docker but it's not installed and I can't install it myself. Aborting."; exit 1; }; } | |
docker_installed | |
# Use sudo if docker socket is not writeable | |
[ -w /var/run/docker.sock ] || SUDO=sudo | |
[ -e /etc/fedora-release ] && MOUNTOPTIONS=:z | |
# Check that the Dockerfile exists | |
[ ! -e "$TWITTER_DIR" ] && { echo >&2 "Missing my sources. Aborting."; exit 1; } | |
cd "$TWITTER_DIR" | |
# Check that there is a image. If not build a new one | |
if [ $($SUDO docker images --format "{{.Repository}}:{{.Tag}}" | grep $TWITTER_IMAGETAG | wc -l) -eq 0 ]; then | |
$SUDO docker build -t $TWITTER_IMAGETAG . | |
fi | |
# Load .trc only if exists | |
if [ ! -e "$TWITTER_RCFILE" ]; then | |
echo "Initialize .trc file" | |
touch "$TWITTER_RCFILE" | |
$SUDO docker run --rm -it -v "$TWITTER_RCFILE:/root/trc$MOUNTOPTIONS" --entrypoint "/bin/bash" $TWITTER_IMAGETAG -c "t authorize --display-uri && cp /root/.trc /root/trc" | |
fi | |
# Switch back to original directory | |
cd "$OPWD" | |
# Run t in container | |
$SUDO docker run --rm -it -v "$TWITTER_RCFILE:/root/.trc$MOUNTOPTIONS" --read-only $TWITTER_IMAGETAG "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment