[Midnightbsd-cvs] src [11836] trunk/release/scripts: add some scripts
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Thu Jul 12 20:29:54 EDT 2018
Revision: 11836
http://svnweb.midnightbsd.org/src/?rev=11836
Author: laffer1
Date: 2018-07-12 20:29:53 -0400 (Thu, 12 Jul 2018)
Log Message:
-----------
add some scripts
Added Paths:
-----------
trunk/release/scripts/atlas-upload.sh
trunk/release/scripts/box.ovf
trunk/release/scripts/mk-vmimage.sh
Added: trunk/release/scripts/atlas-upload.sh
===================================================================
--- trunk/release/scripts/atlas-upload.sh (rev 0)
+++ trunk/release/scripts/atlas-upload.sh 2018-07-13 00:29:53 UTC (rev 11836)
@@ -0,0 +1,159 @@
+#!/bin/sh
+#-
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# Upload a Vagrant image to Hashicorp's Atlas service
+#
+# $MidnightBSD$
+#
+
+ATLAS_API_URL=''
+ATLAS_UPLOAD_URL='https://app.vagrantup.com'
+DESCRIPTION="MidnightBSD Snapshot Build"
+
+usage() {
+ echo "${0} usage:"
+ echo "-b box-name -d 'box description' -f box-to-upload -k api-key -p provider -u user -v version"
+ return 1
+}
+
+main () {
+ while getopts "b:d:f:k:p:u:v:" arg; do
+ case "${arg}" in
+ b)
+ BOX="${OPTARG}"
+ ;;
+ d)
+ DESCRIPTION="${OPTARG}"
+ ;;
+ f)
+ FILE="${OPTARG}"
+ ;;
+ k)
+ KEY="${OPTARG}"
+ ;;
+ p)
+ PROVIDER="${OPTARG}"
+ ;;
+ u)
+ USERNAME="${OPTARG}"
+ ;;
+ v)
+ VERSION="${OPTARG}"
+ ;;
+ *)
+ ;;
+ esac
+ done
+
+ if [ -z "${BOX}" -o \
+ -z "${FILE}" -o \
+ -z "${KEY}" -o \
+ -z "${PROVIDER}" -o \
+ -z "${USERNAME}" -o \
+ -z "${VERSION}" ];
+ then
+ usage || exit 0
+ fi
+
+ # Check to see if the box exists or create it
+ BOXRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}?access_token=${KEY}")
+ if [ $? != 0 ]; then
+ echo "Failed to connect to the API"
+ exit 2;
+ fi
+ echo $BOXRESULT | grep "\"name\":\"${BOX}\"" > /dev/null
+ if [ $? != 0 ]; then
+ echo "Creating box: ${BOX}"
+ /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/boxes -X POST -d "box[name]=${BOX}" -d "access_token=${KEY}" > /dev/null
+ /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[is_private]=false" -d "access_token=${KEY}" > /dev/null
+ /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[description]='${DESCRIPTION}'" -d "access_token=${KEY}" > /dev/null
+ else
+ echo "Box already exists"
+ fi
+
+ # Check to see if the version exists or create it
+ VERSIONRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}")
+ if [ $? != 0 ]; then
+ echo "Failed to connect to the API"
+ exit 2;
+ fi
+ echo $VERSIONRESULT | grep "version/${VERSION}" > /dev/null
+ if [ $? != 0 ]; then
+ echo "Creating version: ${VERSION}"
+ /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/versions -X POST -d "version[version]=${VERSION}" -d "access_token=${KEY}" > /dev/null
+ /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION} -X PUT -d "version[description]=${DESCRIPTION}" -d "access_token=${KEY}" > /dev/null
+ VERSIONRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}")
+ echo $VERSIONRESULT | grep "version/${VERSION}" > /dev/null
+ if [ $? != 0 ]; then
+ echo "Failed to create version"
+ exit 2
+ fi
+ else
+ echo "Version already exists"
+ fi
+
+ # Check to see if the provider exists or create it
+ PROVIDERRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}")
+ if [ $? != 0 ]; then
+ echo "Failed to connect to the API"
+ exit 2;
+ fi
+ echo $PROVIDERRESULT | grep "provider/${PROVIDER}" > /dev/null
+ if [ $? != 0 ]; then
+ echo "Creating provider: ${PROVIDER}"
+ /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/providers -X POST -d "provider[name]=${PROVIDER}" -d "access_token=${KEY}" > /dev/null
+ else
+ echo "Provider already exists"
+ fi
+
+ # Request an upload token
+ TOKENRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}/upload?access_token=${KEY}")
+ if [ $? != 0 ]; then
+ echo "Failed to get the token from the API"
+ exit 2;
+ fi
+ echo ${TOKENRESULT} | grep -E "upload_path" > /dev/null
+ if [ $? != 0 ]; then
+ echo "No token found from the API"
+ exit 2
+ else
+ TOKEN=$(echo $TOKENRESULT | sed -e 's/.*token":"//' -e 's/.*upload_path":"//' -e 's/}$//g' -e 's/"//g')
+ echo "Uploading to Atlas"
+ UPLOADRESULT=$(/usr/local/bin/curl -s -X PUT --upload-file ${FILE} "${TOKEN}")
+
+ # Validate the Upload
+ echo "Validating"
+ VALIDRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}")
+ HOSTED_TOKEN=$(echo $VALIDRESULT | sed -e 's/.*"hosted"://' -e 's/,.*$//')
+ if [ ! -z ${TOKEN} -a "${HOSTED_TOKEN}" != "true" ]; then
+ echo "Upload failed, try again."
+ exit 2
+ fi
+
+ # Release the version
+ echo "Releasing ${VERSION} of ${BOX} in Atlas"
+ /usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/release -X PUT -d "access_token=${KEY}" > /dev/null
+ fi
+}
+
+main "$@"
Property changes on: trunk/release/scripts/atlas-upload.sh
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/release/scripts/box.ovf
===================================================================
(Binary files differ)
Index: trunk/release/scripts/box.ovf
===================================================================
--- trunk/release/scripts/box.ovf 2018-07-13 00:26:06 UTC (rev 11835)
+++ trunk/release/scripts/box.ovf 2018-07-13 00:29:53 UTC (rev 11836)
Property changes on: trunk/release/scripts/box.ovf
___________________________________________________________________
Added: mnbsd:nokeywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+application/xml
\ No newline at end of property
Added: trunk/release/scripts/mk-vmimage.sh
===================================================================
--- trunk/release/scripts/mk-vmimage.sh (rev 0)
+++ trunk/release/scripts/mk-vmimage.sh 2018-07-13 00:29:53 UTC (rev 11836)
@@ -0,0 +1,112 @@
+#!/bin/sh
+#-
+# Copyright (c) 2014 The FreeBSD Foundation
+# All rights reserved.
+#
+# This software was developed by Glen Barber under sponsorship
+# from the FreeBSD Foundation.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# mk-vmimage.sh: Create virtual machine disk images in various formats.
+#
+# $MidnightBSD$
+#
+
+usage() {
+ echo "${0} usage:"
+ echo "${@}"
+ return 1
+}
+
+main() {
+ local arg
+ VMCONFIG="/dev/null"
+ while getopts "C:c:d:f:i:o:s:S:" arg; do
+ case "${arg}" in
+ C)
+ VMBUILDCONF="${OPTARG}"
+ ;;
+ c)
+ VMCONFIG="${OPTARG}"
+ ;;
+ d)
+ DESTDIR="${OPTARG}"
+ ;;
+ f)
+ VMFORMAT="${OPTARG}"
+ ;;
+ i)
+ VMBASE="${OPTARG}"
+ ;;
+ o)
+ VMIMAGE="${OPTARG}"
+ ;;
+ s)
+ VMSIZE="${OPTARG}"
+ ;;
+ S)
+ WORLDDIR="${OPTARG}"
+ ;;
+ *)
+ ;;
+ esac
+ done
+ shift $(( ${OPTIND} - 1))
+
+ if [ -z "${VMBASE}" -o \
+ -z "${WORLDDIR}" -o \
+ -z "${DESTDIR}" -o \
+ -z "${VMSIZE}" -o \
+ -z "${VMIMAGE}" ];
+ then
+ usage || exit 0
+ fi
+
+ if [ -z "${VMBUILDCONF}" ] || [ ! -e "${VMBUILDCONF}" ]; then
+ echo "Must provide the path to vmimage.subr."
+ return 1
+ fi
+
+ . "${VMBUILDCONF}"
+
+ if [ ! -z "${VMCONFIG}" ] && [ ! -c "${VMCONFIG}" ]; then
+ . "${VMCONFIG}"
+ fi
+
+ vm_create_base
+ vm_install_base
+ vm_extra_install_base
+ vm_extra_install_packages
+ vm_extra_install_ports
+ vm_extra_enable_services
+ vm_extra_pre_umount
+ vm_extra_pkg_rmcache
+ cleanup
+ vm_copy_base
+ vm_create_disk || return 0
+ vm_extra_create_disk
+
+ return 0
+}
+
+main "$@"
Property changes on: trunk/release/scripts/mk-vmimage.sh
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
More information about the Midnightbsd-cvs
mailing list