|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +##-------------------------------------------------------------------- |
| 4 | +## Copyright (c) 2021 Dianomic Systems Inc. |
| 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 Debian package for to support other additional libraries as separately such as mqtt, gcp |
| 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 |
| 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/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 | +architecture=`arch` |
| 90 | +PKG_ROOT=`pwd` |
| 91 | +archive=${PKG_ROOT}/archive/DEBIAN |
| 92 | +pkg_name="fledge-${ADDITIONAL_LIB_NAME}" |
| 93 | +arch_name=$(dpkg --print-architecture) |
| 94 | +package_name="${pkg_name}-${version}-${architecture}" |
| 95 | + |
| 96 | +if [ ! -d "${archive}/${architecture}" ]; then |
| 97 | + mkdir -p "${archive}/${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 will be built in : ${archive}/${architecture}" |
| 105 | +echo "The package name is : ${package_name}" |
| 106 | +echo |
| 107 | + |
| 108 | +echo -n "Populating the package and updating version file..." |
| 109 | +if [ ! -d "${archive}/${architecture}/${package_name}" ]; then |
| 110 | + mkdir -p "${archive}/${architecture}/${package_name}" |
| 111 | +fi |
| 112 | +cd "${archive}/${architecture}/${package_name}" |
| 113 | +mkdir -p DEBIAN |
| 114 | +cp -R ${PKG_ROOT}/packages/DEBIAN/* DEBIAN |
| 115 | +sed -i "s/__VERSION__/${version}/g" DEBIAN/control |
| 116 | +sed -i "s/__NAME__/${pkg_name}/g" DEBIAN/control |
| 117 | +sed -i "s/__ARCH__/${arch_name}/g" DEBIAN/control |
| 118 | +sed -i "s/__REQUIRES__/fledge (${fledge_version})/g" DEBIAN/control |
| 119 | +sed -i "s/__DESCRIPTION__/${description}/g" DEBIAN/control |
| 120 | + |
| 121 | +# Debian file structure |
| 122 | +mkdir -p usr/local/lib |
| 123 | +if [ "${ADDITIONAL_LIB_NAME}" == "mqtt" ]; then |
| 124 | + cp -R --preserve=links /usr/local/lib/libpaho* usr/local/lib |
| 125 | +fi |
| 126 | +if [ "${ADDITIONAL_LIB_NAME}" == "gcp" ]; then |
| 127 | + cp -R --preserve=links /usr/local/lib/libjwt* usr/local/lib |
| 128 | + cp -R --preserve=links /usr/local/lib/libjansson* usr/local/lib |
| 129 | +fi |
| 130 | +echo "Done." |
| 131 | + |
| 132 | +# Build the package |
| 133 | +cd "${archive}/${architecture}" |
| 134 | +echo "Building the ${package_name} package..." |
| 135 | +dpkg-deb --build ${package_name} |
| 136 | +echo "Building Complete." |
0 commit comments