98adb905f6ea1f531e2a916255aa39ff0a2b820a
[csit.git] / resources / tools / disk-image-builder / centos / build-listmaker.sh
1 #!/bin/sh
2
3 # Copyright (c) 2016 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14
15 # This builds the "listmaker" image. This is essentially a one-time
16 # action and most likely applicable to CSIT test lab only.
17
18 cd $(dirname $0)
19 BUILD_DIR="$(pwd)/build"
20 PACKER_DIR="${BUILD_DIR}/packer"
21 OUT_DIR="${BUILD_DIR}/output/listmaker"
22
23 if [ "$1" = "centos-7-1511" ]; then
24     RELEASE_NAME="csit-centos-7-1511-listmaker"
25     PACKER_TEMPLATE="listmaker/centos-7-1511.json"
26 else
27     if [ "$1" = "centos-7.3-1611" ]; then
28         RELEASE_NAME="csit-centos-7.3-1611-listmaker"
29         PACKER_TEMPLATE="listmaker/centos-7.3-1611.json"
30     elif [ "$1" = "centos-7.4-1711" ]; then
31         RELEASE_NAME="csit-centos-7.4-1711-listmaker"
32         PACKER_TEMPLATE="listmaker/centos-7.4-1711.json"
33     else
34         if [ "$1" = "centos-7.6-1810" ]; then
35             RELEASE_NAME="csit-centos-7.6-1810-listmaker"
36             PACKER_TEMPLATE="listmaker/centos-7.6-1810.json"
37         else
38             echo "Please provide OS as parameter:"
39             echo "Options: ${0} [centos-7.3-1611|centos-7.4-1711|centos-7.6-1810]"
40             exit 1
41         fi
42     fi
43 fi
44
45 VIRL_IMAGE_SUBTYPE=server
46 VIRL_IMAGE_NAME="${RELEASE_NAME}"
47 VIRL_IMAGE_FILE="${OUT_DIR}/packer-${RELEASE_NAME}"
48
49 # export PACKER_LOG="1"
50
51 # This script requires that the following two environment variables be defined-
52 #
53 # $VIRL_USER
54 # $VIRL_PASSWORD
55
56 if [ "$VIRL_USER" = "" ] || [ "$VIRL_PASSWORD" = "" ]
57 then
58   echo '$VIRL_USER and $VIRL_PASSWORD environment variables must be defined'
59   exit 1
60 fi
61
62 ###
63 ### Download and extract packer, if not already installed
64 ###
65 os=$(uname -s)
66 if [ "$os" = "Darwin" ]
67 then
68   packer_url="https://releases.hashicorp.com/packer/0.10.1/packer_0.10.1_darwin_amd64.zip"
69 elif [ "$os" = "Linux" ]
70 then
71   packer_url="https://releases.hashicorp.com/packer/0.10.1/packer_0.10.1_linux_amd64.zip"
72 fi
73
74 mkdir -p $BUILD_DIR
75 wget -P ${PACKER_DIR} -N ${packer_url}
76
77 unzip -n ${PACKER_DIR}/packer*zip -d ${PACKER_DIR}
78
79 ###
80 ### Build the actual image as per packer script. Packer post-processor will
81 ### upload it to VIRL.
82 ###
83 ${BUILD_DIR}/packer/packer build -var "release=${RELEASE_NAME}" \
84   -var "outputdir=${OUT_DIR}" -force -machine-readable ${PACKER_TEMPLATE}