Save 4 lines, thanks @SkUrRiEr

This commit is contained in:
Peter Wilmott 2015-07-24 16:46:25 +00:00
parent 036d2b6ffc
commit caf4a38b9a

8
bocker
View File

@ -2,11 +2,7 @@
set -o errexit -o nounset -o pipefail; shopt -s nullglob set -o errexit -o nounset -o pipefail; shopt -s nullglob
btrfs_path='/var/bocker'; btrfs_path='/var/bocker';
function bocker_check() { function bocker_check() {
if btrfs subvolume list "$btrfs_path" | grep -qw "$1"; then btrfs subvolume list "$btrfs_path" | grep -qw "$1" && echo 0 || echo 1
echo 0
else
echo 1
fi
} }
function bocker_init() { #HELP Create an image:\nBOCKER init <image_directory> function bocker_init() { #HELP Create an image:\nBOCKER init <image_directory>
uuid="img_$(shuf -i 42002-42254 -n 1)" uuid="img_$(shuf -i 42002-42254 -n 1)"
@ -38,7 +34,7 @@ for ps in "$btrfs_path"/ps_*; do
done done
} }
function bocker_run() { #HELP Create a container:\nBOCKER run <image_id> <command function bocker_run() { #HELP Create a container:\nBOCKER run <image_id> <command
uuid="ps_$(shuf -i 42002-42254 -n 1)"; uuid="ps_$(shuf -i 42002-42254 -n 1)"
[[ "$(bocker_check "$1")" == 1 ]] && echo "No image named '$1' exists" && exit 1 [[ "$(bocker_check "$1")" == 1 ]] && echo "No image named '$1' exists" && exit 1
[[ "$(bocker_check "$uuid")" == 0 ]] && echo "UUID conflict, retrying..." && bocker_run "$@" && return [[ "$(bocker_check "$uuid")" == 0 ]] && echo "UUID conflict, retrying..." && bocker_run "$@" && return
cmd=${@:2} && ip="$(echo "${uuid: -3}" | sed 's/0//g')" && mac="${uuid: -3:1}:${uuid: -2}" cmd=${@:2} && ip="$(echo "${uuid: -3}" | sed 's/0//g')" && mac="${uuid: -3:1}:${uuid: -2}"