|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +##-------------------------------------------------------------------------- |
| 4 | +## Copyright (c) 2021 Dianomic Systems |
| 5 | +## |
| 6 | +## Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +## you may not use this file except in compliance with the License. |
| 8 | +## You may obtain a copy of the License at |
| 9 | +## |
| 10 | +## http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +## |
| 12 | +## Unless required by applicable law or agreed to in writing, software |
| 13 | +## distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +## See the License for the specific language governing permissions and |
| 16 | +## limitations under the License. |
| 17 | +##------------------------------------------------------------------------- |
| 18 | +## |
| 19 | +## Author: Ashish Jabble |
| 20 | +## |
| 21 | + |
| 22 | +set -e |
| 23 | + |
| 24 | +USAGE="$(basename "$0") [-h] [-a] ... |
| 25 | +This script is used to create the RPM package for to support other additional libraries as separately such as mqtt |
| 26 | +
|
| 27 | +Arguments: |
| 28 | + -h - Display this help text |
| 29 | + -a - Remove all the archive versions" |
| 30 | + |
| 31 | +while getopts ":ha" opt; do |
| 32 | + case "$opt" in |
| 33 | + a) |
| 34 | + if [ -d "./archive" ]; then |
| 35 | + echo -n "Cleaning the package archive folder..." |
| 36 | + rm -rf ./archive/* |
| 37 | + echo "Done." |
| 38 | + else |
| 39 | + echo "No archive folder, skipping cleanall" |
| 40 | + fi |
| 41 | + exit 0 |
| 42 | + ;; |
| 43 | + h) |
| 44 | + echo "${USAGE}" |
| 45 | + exit 0 |
| 46 | + ;; |
| 47 | + \?) |
| 48 | + echo "Invalid option -$OPTARG" |
| 49 | + exit 1 |
| 50 | + ;; |
| 51 | + :) |
| 52 | + echo "-$OPTARG requires an argument" |
| 53 | + exit 1 |
| 54 | + esac |
| 55 | +done |
| 56 | +shift $((OPTIND -1)) |
| 57 | + |
| 58 | +ADDITIONAL_LIB_NAME=$1 |
| 59 | +if [ "${ADDITIONAL_LIB_NAME}" = "" ]; then |
| 60 | + echo "You must specify additional library name to package. For example: mqtt" |
| 61 | + exit 1 |
| 62 | +fi |
| 63 | + |
| 64 | +# VERSION |
| 65 | +if [ -f scripts/${ADDITIONAL_LIB_NAME}/VERSION ]; then |
| 66 | + VERSION=`cat scripts/${ADDITIONAL_LIB_NAME}/VERSION | tr -d ' ' | grep "fledge_${ADDITIONAL_LIB_NAME}_version" | head -1 | sed -e 's/\(.*\)=\(.*\)/\2/g'` |
| 67 | + FLEDGE_VERSION=`cat scripts/${ADDITIONAL_LIB_NAME}/VERSION | tr -d ' ' | grep 'fledge_version' | head -1 | sed -e 's/\(.*\)version\([>=|>|<|<=|=]*\)\(.*\)/\2 \3/g'` |
| 68 | +else |
| 69 | + echo VERSION file is missing for ${ADDITIONAL_LIB_NAME} in "others/scripts/" directory |
| 70 | + exit 1 |
| 71 | +fi |
| 72 | + |
| 73 | +# Description |
| 74 | +if [ -f scripts/${ADDITIONAL_LIB_NAME}/Description ]; then |
| 75 | + DESCRIPTION=`cat "scripts/${ADDITIONAL_LIB_NAME}/Description"` |
| 76 | +else |
| 77 | + echo Description file is missing for ${ADDITIONAL_LIB_NAME} in "others/scripts/" directory |
| 78 | + exit 1 |
| 79 | +fi |
| 80 | + |
| 81 | +# requirements.sh |
| 82 | +if [ -f scripts/${ADDITIONAL_LIB_NAME}/requirements.sh ]; then |
| 83 | + ./scripts/${ADDITIONAL_LIB_NAME}/requirements.sh |
| 84 | +else |
| 85 | + echo Requirement script is missing for ${ADDITIONAL_LIB_NAME} "others/scripts/" directory |
| 86 | + exit 1 |
| 87 | +fi |
| 88 | + |
| 89 | +GIT_ROOT=`pwd` |
| 90 | +ARCHIVE_PATH=${GIT_ROOT}/archive/RPM |
| 91 | +PKG_NAME="fledge-${ADDITIONAL_LIB_NAME}" |
| 92 | +ARCHITECTURE=`arch` |
| 93 | +PACKAGE_NAME="${PKG_NAME}-${VERSION}" |
| 94 | +BUILD_ROOT="${GIT_ROOT}/packages/build" |
| 95 | + |
| 96 | +if [ ! -d "${ARCHIVE_PATH}/${ARCHITECTURE}" ]; then |
| 97 | + mkdir -p "${ARCHIVE_PATH}/${ARCHITECTURE}" |
| 98 | +fi |
| 99 | + |
| 100 | +# Print the summary of findings |
| 101 | +echo "Additional ${ADDITIONAL_LIB_NAME} Package version is : ${VERSION}" |
| 102 | +echo "The Fledge required version is : ${FLEDGE_VERSION}" |
| 103 | +echo "The architecture is set as : ${ARCHITECTURE}" |
| 104 | +echo "The package root directory is : ${GIT_ROOT}" |
| 105 | +echo "The package will be built in : ${BUILD_ROOT}" |
| 106 | +echo "The package name is : ${PACKAGE_NAME}" |
| 107 | +echo |
| 108 | + |
| 109 | +# First, create the BUILD_ROOT folder, if necessary |
| 110 | +if [ ! -L "${BUILD_ROOT}" -a ! -d "${BUILD_ROOT}" ]; then |
| 111 | + mkdir -p ${BUILD_ROOT} |
| 112 | +fi |
| 113 | + |
| 114 | +# Check old copy of PACKAGE_NAME; if exists then remove |
| 115 | +if [ -d "${BUILD_ROOT}/${PACKAGE_NAME}" ]; then |
| 116 | + rm -rf ${BUILD_ROOT}/${PACKAGE_NAME}* |
| 117 | +fi |
| 118 | + |
| 119 | +# Populate the package directory with RPM files |
| 120 | +echo -n "Populating the package and updating version file..." |
| 121 | +cd ${BUILD_ROOT} |
| 122 | +mkdir -p ${PACKAGE_NAME} |
| 123 | +cd ${PACKAGE_NAME} |
| 124 | +cp -R ${GIT_ROOT}/packages/RPM/* SPECS |
| 125 | +sed -i "s/__NAME__/${PKG_NAME}/g" SPECS/others.spec |
| 126 | +sed -i "s/__VERSION__/${VERSION}/g" SPECS/others.spec |
| 127 | +sed -i "s/__ARCH__/${ARCHITECTURE}/g" SPECS/others.spec |
| 128 | +sed -i "s/__REQUIRES__/fledge ${FLEDGE_VERSION}/g" SPECS/others.spec |
| 129 | +sed -i "s/__DESCRIPTION__/${DESCRIPTION}/g" SPECS/others.spec |
| 130 | +echo "Done." |
| 131 | + |
| 132 | +# RPM file structure |
| 133 | +echo "Copying artifacts..." |
| 134 | +mkdir -p BUILDROOT |
| 135 | +cd BUILDROOT |
| 136 | +mkdir -p ${PACKAGE_NAME}-1.${ARCHITECTURE} |
| 137 | +cd ${PACKAGE_NAME}-1.${ARCHITECTURE} |
| 138 | +mkdir -p usr/local/lib64 |
| 139 | +if [ "${ADDITIONAL_LIB_NAME}" == "mqtt" ]; then |
| 140 | + cp -R --preserve=links /usr/local/lib64/libpaho* usr/local/lib64 |
| 141 | +fi |
| 142 | +# TODO: FOGL-3632 - Blocked with its compilation |
| 143 | +#if [ "${ADDITIONAL_LIB_NAME}" == "gcp" ]; then |
| 144 | +# cp -R --preserve=links /usr/local/lib64/libjwt* usr/local/lib64 |
| 145 | +# cp -R --preserve=links /usr/local/lib64/libjansson* usr/local/lib64 |
| 146 | +#fi |
| 147 | +echo "Done." |
| 148 | +find -L . -type f -exec echo '/'{} \; >> ../../SPECS/others.spec |
| 149 | +echo "Building the RPM package..." |
| 150 | +cd ${BUILD_ROOT} |
| 151 | +rpmbuild --define "_topdir ${BUILD_ROOT}/${PACKAGE_NAME}" --noclean -bb ${BUILD_ROOT}/${PACKAGE_NAME}/SPECS/others.spec |
| 152 | +echo "Building Complete." |
| 153 | +echo "Artifacts copied to "${ARCHIVE_PATH}/${ARCHITECTURE} |
| 154 | +PKG_NAME_WITH_EXT="${PACKAGE_NAME}-1.${ARCHITECTURE}.rpm" |
| 155 | +cp ${BUILD_ROOT}/${PACKAGE_NAME}/RPMS/${ARCHITECTURE}/${PKG_NAME_WITH_EXT} ${ARCHIVE_PATH}/${ARCHITECTURE}/${PKG_NAME_WITH_EXT} |
0 commit comments