Commit 17e5b8d3 authored by PhiBo's avatar PhiBo 🚀

git - Initial commit

parents
*.swp
cache/**
home/*
tasks-enabled/*
tasks-local/*
!**/.gitkeep
Changelog
=========
0.3.0 (master)
--------------
- first public release
This diff is collapsed.
Boxrun
======
Simplify the daily use of interactive docker containers.
Requirements
------------
- docker
- Shell command (sh, dash, ...) to run helper scripts
Install
-------
Checkout the files from the git repository.
```console
$ cd ~
$ git clone https://git.dinotools.org/tools/boxrun.git .boxrun
```
Add the following line to your ```.bashrc``` if you use Bash, ```.zshrc``` if you use ZSH or check out the documentation of your preferred shell to find the right place.
```
alias boxrun="~/.boxrun/boxrun.sh"
```
After adding the command you should open a new terminal to activate the alias in this shell.
Usage
-----
To start a debian:9 container run the following command.
```
boxrun debian:9
```
You can also try a different one like shown in the example belown.
```
boxrun centos:7
```
If you don't want to run an interactive shell you can also pass a command.
```
boxrun centos:7 top
```
Tasks
-----
Tasks a run during the container start.
By default boxrun ships with a few tasks/scripts located in the ```tasks-dist``` directory.
To enable a task create a symlink in the ```tasks-enabled``` directory.
```console
$ cd ~/.boxrun/tasks-enabled
$ ln -s ../tasks-dist/01_example.sh .
```
It is also possible to add custom start tasks/scripts.
Just create a new file in the ```tasks-local``` directory and create a symlink as shown in the example abofe.
Shipped Tasks
-------------
- 01_install_sudo.sh - This installs the sudo command
Lib
---
At the time of writing boxrun ships with one library located in the ```lib``` directory called ```core.sh```
**core.sh**
- ```install_with_apt <cache-name> <package 1> <package 2> ...```
- The command install the packages listed and uses a cache directory to keep the .deb files to speed up the next start
- ```install_with_yum <cache-name> <package 1> <package 2> ...```
- The command install the packages listed and uses a cache directory to keep the .rpm files to speed up the next start
Documentation
-------------
At the time of writing there is no additional documentation.
Please use this file as a reference.
Changelog
---------
Checkout the CHANGLOG.md file.
Resources
---------
- official git repository - https://git.dinotools.org/tools/boxrun
License
-------
The scripts included in this repository are released under the GPLv3+ license.
For more information have a look at the file LICENSE
#!/bin/sh
CACHE_DIR=$HOME/.boxrun/cache
test -d ${CACHE_DIR} || mkdir -p ${CACHE_DIR}
docker run --rm -it -v $(pwd):/ext -v $HOME/.boxrun:/.boxrun --entrypoint /.boxrun/entrypoint.sh --env EXT_UID=$(id -u) --env EXT_GID=$(id -g) --env EXT_USER="$(id -nu)" --env EXT_GROUP="$(id -ng)" --env EXT_HOME=$HOME $@
#!/bin/sh
HASH_TOOL=md5sum
CACHE_BASE_DIR=/.boxrun/cache
DEFAULT_SHELL_COMMAND=/bin/bash
CUSTOM_TASK_DIR=/.boxrun/tasks-enabled
TEMPLATE_HOME_DIR=/.boxrun/home
LIB_DIR=/.boxrun/lib
. ${LIB_DIR}/core.sh
echo -n "Preparing user ... "
groupadd --gid $EXT_GID $EXT_GROUP
useradd --uid $EXT_UID --gid $EXT_GID --home-dir $EXT_HOME $EXT_USER
echo "done"
test -e ${TEMPLATE_HOME_DIR} && cp -af ${TEMPLATE_HOME_DIR}/. /home/$EXT_USER
for TMP_CMD in $(test -d ${CUSTOM_TASK_DIR} && ls ${CUSTOM_TASK_DIR} | sort); do
(cd ${CUSTOM_TASK_DIR} && test -x $TMP_CMD && (echo "Running custom task '${TMP_CMD}' ..."; . ./$TMP_CMD))
done
COMMAND=$@
if [ $# -eq 0 ]; then
COMMAND=$DEFAULT_SHELL_COMMAND
test -x $COMMAND || COMMAND=/bin/sh
fi
cd /ext
runuser -u $EXT_USER -- $COMMAND
#!/bin/sh
download_with_apt()
{
CACHE_DIR=$1
shift
STEP=$1
shift
if [ "$STEP" -eq 0 ]; then
return
fi
TMP_PKGS=$(apt-cache depends -i $@ | sort | uniq | awk 'BEGIN{pkgs=""}/Depends:/ {pkgs=pkgs" "$2}END{print pkgs}')
TMP_PKGS_REQUIRED=""
for TMP_PKG in $TMP_PKGS; do
dpkg -l ${TMP_PKG} > /dev/null || TMP_PKGS_REQUIRED="${TMP_PKGS_REQUIRED} ${TMP_PKGS}"
done
if [ "$TMP_PKGS_REQUIRED" = "" ]; then
return
fi
(cd $CACHE_DIR && su -c "apt-get download $TMP_PKGS_REQUIRED" $EXT_USER)
download_with_apt $CACHE_DIR $(( $STEP - 1 )) $TMP_PKGS_REQUIRED
}
get_system_hash()
{
test -e /etc/os-release && ${HASH_TOOL} /etc/os-release | head -n 1 | cut -f1 -d' '; return
echo "no_hash"
}
install_with_apt()
{
type apt-get > /dev/null 2>&1 || return 1
TASK_NAME=$1
shift
CACHE_DIR="${CACHE_BASE_DIR}/$(get_system_hash)/${TASK_NAME}"
if [ ! -d $CACHE_DIR ]; then
echo "Downloading required packages into cache(${TASK_NAME}) ..."
apt-get update
su -c "mkdir -p $CACHE_DIR" $EXT_USER
(cd $CACHE_DIR && su -c "apt-get download $@" $EXT_USER)
download_with_apt $CACHE_DIR 4 $@
echo "done"
fi
echo "Installing packages(${TASK_NAME}) ..."
dpkg -i $CACHE_DIR/*.deb || apt-get -fy install
echo "done"
return 0
}
install_with_yum()
{
type yum > /dev/null 2>&1 || return 1
TASK_NAME=$1
shift
CACHE_DIR="${CACHE_BASE_DIR}/$(get_system_hash)/${TASK_NAME}"
if [ ! -d "$CACHE_DIR" ]; then
echo "Downloading required packages into cache(${TASK_NAME})..."
su -c "
mkdir -p $CACHE_DIR
" $EXT_USER
yum install --downloadonly --downloaddir=${CACHE_DIR} $@
su -c "
chown $EXT_UID:$EXT_GID $CACHE_DIR
" $EXT_USER
echo "done"
fi
echo "Installing packages(${TASK_NAME}) ..."
yum -y -C install $CACHE_DIR/*.rpm
echo "done"
return 0
}
#!/bin/sh
. $LIB_DIR/core.sh
install_with_apt sudo sudo
install_with_yum sudo sudo
echo "$EXT_USER ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment