labsync/docker/entrypoint.sh
2018-03-18 17:59:47 +01:00

91 lines
1.7 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 "$PACKER_JSON"
mkdir -p build/rootfs
tar xf build/rootfs.tar -C build/rootfs
mv build/rootfs/artifacts/initramfs "/images/$INITRAMFS_FILE"
mv build/rootfs/artifacts/linux "/images/$LINUX_FILE"
rm -rf build/rootfs/artifacts
rm -- \
build/rootfs/.dockerenv \
build/rootfs/initrd.* \
build/rootfs/vmlinuz*
if [ -e "/images/$SQUASHFS_FILE" ]; then
rm "/images/$SQUASHFS_FILE"
fi
mksquashfs build/rootfs "/images/$SQUASHFS_FILE" \
-comp lzo \
-Xcompression-level 9
rm -rf build
if [ "$user" != "" ] && [ "$group" != "" ]; then
chown $user:$group \
"/images/$INITRAMFS_FILE" \
"/images/$LINUX_FILE" \
"/images/$SQUASHFS_FILE"
fi
}
NAME="$1"
if [ "$NAME" = "" ]; then
echo 'no name supplied, stopping.' >&2
exit 1
fi
export PACKER_JSON="$NAME.json"
export INITRAMFS_FILE="$NAME.initramfs"
export LINUX_FILE="$NAME.linux"
export SQUASHFS_FILE="$NAME.squashfs"
if [ -z "$TASK" ] || [ "$TASK" == "packer" ]; then
run_packer
fi
if [ -z "$TASK" ] || [ "$TASK" == "torrent" ]; then
make_torrent "$NAME.squashfs"
fi