Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 142 lines (109 sloc) 4.02 KB
#!/bin/bash -e
# Copyright (c) 2011-2018 TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of buildtasks.
#
# Buildtasks is free software; you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
fatal() { echo "FATAL [$(basename $0)]: $@" 1>&2; exit 1; }
warning() { echo "WARNING [$(basename $0)]: $@"; }
info() { echo "INFO [$(basename $0)]: $@"; }
usage() {
cat<<EOF
Syntax: $(basename $0) [--publish] appname-version
Converts appliance appname-version to vmdk and ovf
Arguments::
appname-version - e.g., core-14.2-jessie-amd64
Options::
--publish - if set, images and meta files will be published
Environment::
BT_DEBUG - turn on debugging
EOF
exit 1
}
while [ "$1" != "" ]; do
case $1 in
--help|-h ) usage;;
--publish) publish="yes";;
*) if [ -n "$appver" ]; then usage; else appver=$1; fi ;;
esac
shift
done
[ -n "$appver" ] || usage
[ -n "$BT_DEBUG" ] && set -x
export BT=$(dirname $(readlink -f $0))
export BT_CONFIG=$BT/config
. $BT_CONFIG/common.cfg
O=$BT_BUILDS/vm
mkdir -p $O
if [ "$publish" == "yes" ]; then
[ -n "$BT_PUBLISH_IMGS" ] || fatal "BT_PUBLISH_IMGS not set"
[ -n "$BT_PUBLISH_META" ] || fatal "BT_PUBLISH_META not set"
else
warning "--publish was not specified"
fi
if [ ! -e /root/vm-setup.done ]; then
$BT/bin/vm-setup
touch /root/vm-setup.done
fi
parsed_appname_version=$($BT/bin/parse-appname-version $appver)
read appname appversion codename arch <<< "$parsed_appname_version"
export BT_VERSION=${appversion}-${codename}-${arch}
export VM_URL="https://www.turnkeylinux.org/$appname"
export VM_FULLNAME="TURNKEY $(echo $appname | tr [a-z] [A-Z] | sed s'/-/ /g')"
case "$appname" in
canvas) export VM_MEMORY=1024 ;;
gitlab) export VM_MEMORY=1024 ;;
jenkins) export VM_MEMORY=1024 ;;
odoo) export VM_MEMORY=1024 ;;
openvas) export VM_MEMORY=1024 ;;
tkldev) export VM_MEMORY=768 ;;
moodle) export VM_MEMORY=768 ;;
tomcat-apache) export VM_MEMORY=768 ;;
*) export VM_MEMORY=512 ;;
esac
case "${codename}-${arch}" in
squeeze-i386) export VM_GUESTOS="debian6" ;;
wheezy-i386) export VM_GUESTOS="debian7" ;;
jessie-i386) export VM_GUESTOS="debian8" ;;
stretch-i386) export VM_GUESTOS="debian9" ;;
squeeze-amd64) export VM_GUESTOS="debian6-64" ;;
wheezy-amd64) export VM_GUESTOS="debian7-64" ;;
jessie-amd64) export VM_GUESTOS="debian8-64" ;;
stretch-amd64) export VM_GUESTOS="debian9-64" ;;
*) fatal "vm_guestos could not be determined" ;;
esac
isofile=turnkey-${appname}-${BT_VERSION}.iso
name=turnkey-${appname}-${BT_VERSION}
rootfs=$name.rootfs
cdroot=$name.cdroot
$BT/bin/iso-download $BT_ISOS $BT_VERSION $appname
$BT/bin/iso-verify $BT_ISOS $BT_VERSION $appname
cd $O
tklpatch-extract-iso $BT_ISOS/$isofile
tklpatch-apply $rootfs $BT/patches/vm
$BT/bin/rootfs-cleanup $rootfs
$BT/bin/aptconf-tag $rootfs vm
$BT/bin/build-tag $rootfs vm
$BT/bin/vm-bundle $O/$rootfs
$BT/bin/generate-signature $O/$name-vmdk.zip
$BT/bin/generate-signature $O/$name.ova
$BT/bin/generate-buildenv vm $BT_ISOS/$isofile.hash > $O/$name-vmdk.zip.buildenv
$BT/bin/generate-buildenv vm $BT_ISOS/$isofile.hash > $O/$name.ova.buildenv
# publish if specified
if [ "$publish" == "yes" ]; then
export PUBLISH_DEST=${BT_PUBLISH_IMGS}/vmdk/
$BT/bin/publish-files $O/$name-vmdk.zip
export PUBLISH_DEST=${BT_PUBLISH_IMGS}/ova/
$BT/bin/publish-files $O/$name.ova
export PUBLISH_DEST=${BT_PUBLISH_META}/
$BT/bin/publish-files $O/$name-vmdk.{zip.hash,zip.buildenv}
$BT/bin/publish-files $O/$name.{ova.hash,ova.buildenv}
fi
if [ -z "$BT_DEBUG" ] && ! (mount | grep -q $(basename $rootfs)); then
rm -rf $rootfs
rm -rf $cdroot
[ "$publish" == "yes" ] && $BT/bin/clean vm $appver
fi
You can’t perform that action at this time.