labsync/docker/entrypoint.sh

66 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
set -e
make_torrent() {
(cd /images
if [ "$NAME" = "" ]; then
# remove file extension
NAME="$(echo "$1" | sed 's/\.[^.]*//')"
fi
if [ "$WEBSEED" = "" ]; then
echo '$WEBSEED not provided' >&2
exit 1
fi
if [ "$ANNOUNCE" = "" ]; then
echo '$ANNOUNCE not provided' >&2
exit 1
fi
TORRENT_FILE="$NAME.torrent"
WEBSEED_URL="$WEBSEED/$1"
if [ -e "$TORRENT_FILE" ]; then rm "$TORRENT_FILE"; fi
mktorrent-borg \
-n "$NAME" \
-a "$ANNOUNCE" \
-o "$TORRENT_FILE" \
-l 22 \
-w "$WEBSEED_URL" \
"$1"
if [ "$user" != "" ] && [ "$group" != "" ]; then
chown "$user:$group" "$TORRENT_FILE"
fi
)
}
run_packer() {
packer build "$NAME.json"
if [ "$user" != "" ] && [ "$group" != "" ]; then
chown $user:$group "/images/${NAME}."*
fi
}
NAME="$1"
if [ "$NAME" = "" ]; then
echo 'no name supplied, stopping.' >&2
exit 1
fi
export NAME
if [ -z "$TASK" ] || [ "$TASK" == "packer" ]; then
run_packer
fi
if [ -z "$TASK" ] || [ "$TASK" == "torrent" ]; then
make_torrent "$NAME.squashfs"
fi
if [ "$TASK" == "ansible" ]; then
cd /ansible
/usr/bin/ansible-playbook "$@"
fi