diff options
Diffstat (limited to 'debian/_buildscripts/local/scripts/internals')
7 files changed, 475 insertions, 0 deletions
diff --git a/debian/_buildscripts/local/scripts/internals/C10shell b/debian/_buildscripts/local/scripts/internals/C10shell new file mode 100755 index 000000000..7c6a8761b --- /dev/null +++ b/debian/_buildscripts/local/scripts/internals/C10shell @@ -0,0 +1,18 @@ +#!/bin/sh + +# Color table +CPurple='\e[0;35m' +CWhite='\e[1;37m' +CNone='\e[0m' + +# Invoke shell if build fails. +apt-get install -y --force-yes vim less bash mc +cd /tmp/buildd/*/debian/.. +echo "${CPurple}---------------------------------------------------------${CNone}" >/dev/tty +echo "${CPurple} !!! Build FAILED !!! ${CNone}" >/dev/tty +echo "${CPurple} You are now inside a shell in the building environment. ${CNone}" >/dev/tty +echo "${CPurple} ${CWhite}mc, vim, less${CPurple} are available for your convenience. ${CNone}" >/dev/tty +echo "${CPurple} Type ${CWhite}exit${CPurple} to leave the shell when you are done. ${CNone}" >/dev/tty +echo "${CPurple}---------------------------------------------------------${CNone}" >/dev/tty +/bin/bash </dev/tty >/dev/tty 2>/dev/tty + diff --git a/debian/_buildscripts/local/scripts/internals/_build_common.sh b/debian/_buildscripts/local/scripts/internals/_build_common.sh new file mode 100755 index 000000000..c692ac26c --- /dev/null +++ b/debian/_buildscripts/local/scripts/internals/_build_common.sh @@ -0,0 +1,162 @@ +#!/bin/bash + + +#---------------------------- +#---------------------------- +# Color table +# Black 0;30 Dark Gray 1;30 +# Blue 0;34 Light Blue 1;34 +# Green 0;32 Light Green 1;32 +# Cyan 0;36 Light Cyan 1;36 +# Red 0;31 Light Red 1;31 +# Purple 0;35 Light Purple 1;35 +# Brown 0;33 Yellow 1;33 +# Light Gray 0;37 White 1;37 +# No Color 0 +set -a +CBlack='\e[0;30m' +CDarkGray='\e[1;30m' +CBlue='\e[0;34m' +CLightBlue='\e[1;34m' +CGreen='\e[0;32m' +CLightGreen='\e[1;32m' +CCyan='\e[0;36m' +CLightCyan='\e[1;36m' +CRed='\e[0;31m' +CLightRed='\e[1;31m' +CPurple='\e[0;35m' +CLightPurple='\e[1;35m' +CBrown='\e[0;33m' +CYellow='\e[1;33m' +CGray='\e[0;37m' +CWhite='\e[1;37m' +CNone='\e[0m' +set +a + +#---------------------------- +function init_common() +{ + # Check script folder + export SCRIPT_DIR=$(dirname $(readlink -f "$0")) + + # Prevent the script to be run from TDE packaging repo + REPO_URL=$(git config --get remote.origin.url 2>/dev/null) + if [ ! -z "$REPO_URL" ] && [ -z "${REPO_URL##*tde-packaging}" ]; then + echo -e "${CYellow} --- ERROR ---${CNone}" + echo "This script cannot be run from the TDE packaging repository." + echo "Please follow the instructions provided, then rerun this script." + exit 1 + fi + + # Read config settings + CFG_FILE=$SCRIPT_DIR/_config.sh + if [ -f "$CFG_FILE" ]; then + . "$CFG_FILE" + else + echo -e "${CYellow} --- NOTE ---${CNone}" + echo "Creating TDE build configuration file from template as $CFG_FILE." + echo "Please check and modify as required, then rerun this script." + cp "$SCRIPT_DIR/internals/_config_template.sh" "$CFG_FILE" + exit 2 + fi + + # TDE root folder must exist + if [ ! -d "$TDE_DIR" ]; then + echo -e "${CYellow} --- ERROR ---${CNone}" + echo "A valid TDE root folder could not be located. Something is wrong with your configuration" + echo "in the config file $CFG_FILE" + echo "Please check and modify the TDE_DIR variable as required, then rerun this script." + exit 3 + fi + + # Search for main TDE repo + cd "$TDE_DIR/$CFG_GIT_TDE_MAIN" &>/dev/null + CURR_DIR=$(git rev-parse --show-toplevel 2>/dev/null) + if [ -z "$CURR_DIR" ]; then + echo -e "${CYellow} --- ERROR ---${CNone}" + echo "Main TDE repo could not be located. Something is wrong with your configuration" + echo "in the config file $CFG_FILE" + echo "Please check and modify the TDE_DIR variable as required, then rerun this script." + exit 4 + fi + + # Search for TDE packaging repo + cd "$TDE_DIR/$CFG_GIT_TDE_PACKAGING" &>/dev/null + CURR_DIR=$(git rev-parse --show-toplevel 2>/dev/null) + if [ -z "$CURR_DIR" ]; then + echo -e "${CYellow} --- ERROR ---${CNone}" + echo "TDE packaging repo could not be located. Something is wrong with your configuration" + echo "in the config file $CFG_FILE" + echo "Please check and modify the TDE_DIR variable as required, then rerun this script." + exit 5 + fi + + # Make sure we have selected a supported distribution + DISTS_FILE=$SCRIPT_DIR/internals/distro_list.txt + if [ ! -f "$DISTS_FILE" ]; then + echo -e "${CYellow} --- NOTE ---${CNone}" + echo "Could not find the list of supported distributions." + echo "Please check the file $DISTS_FILE exists, then rerun this script." + exit 6 + fi + export DISTRO_FOUND=${DISTRO_FOUND:-"n"} + if [ "$DISTRO_FOUND" != "y" ]; then + # Need to use a "here string" otherwise if the DISTRO_FOUND value is modified + # inside the while loop, this would not remember after the loop. + while read l_distro l_version l_name l_rel_suffix; do + if [ "$l_distro" = "$DISTRO" -a "$l_name" = "$DISTRO_NAME" ]; then + export DISTRO_FOUND="y" + export DISTRO_VERSION="$l_version" + export REL_SUFFIX="$l_rel_suffix" + break + fi + done <<< $(cat $DISTS_FILE | grep -E "^(\s*[^#\s]+\s+[^\s]+.*)$") + fi + if [ "$DISTRO_FOUND" != "y" ]; then + echo -e "${CYellow} --- NOTE ---${CNone}" + echo "The specified distribution ($DISTRO $DISTRO_NAME) is not supported." + echo "Something is wrong with your configuration ($CFG_FILE)" + echo "or with the list of supported distributions ($DISTS_FILE)." + echo "Please check the DISTRO and DISTRO_NAME variables, then rerun this script." + exit 7 + fi + + export SCRIPT_LOG_DIR=$TDE_DIR/$CFG_SCRIPT_LOG_DIR + export LOG_RESULT_FILENAME="$SCRIPT_LOG_DIR/build_result.log" # Log result into the common build logfile + + cd "$SCRIPT_DIR" +} + + +#---------------------------- +# Save execution start time +# Parameters: +# $1 - timer number +function exec_time_start() +{ + _ET_start_var="_ET_start_$1" + eval "$_ET_start_var=`date +%s.%N`" +} + + +#---------------------------- +# Save execution stop time and set $2 to the execution time +# in the format: dd/hh:mm:ss.mmm +# Parameters: +# $1 - timer number +# $2 - result variable name +function exec_time_stop() +{ + _ET_start_var="_ET_start_$1" + _ET_stop_var="_ET_stop_$1" + eval "$_ET_stop_var=`date +%s.%N`" + _ET_diff=`echo "${!_ET_stop_var} - ${!_ET_start_var}" | bc` + _ET_days=`echo "$_ET_diff/86400" | bc` + _ET_diff_day=`echo "$_ET_diff-86400*$_ET_days" | bc` + _ET_hours=`echo "$_ET_diff_day/3600" | bc` + _ET_diff_hour=`echo "$_ET_diff_day-3600*$_ET_hours" | bc` + _ET_mins=`echo "$_ET_diff_hour/60" | bc` + _ET_secs=`echo "$_ET_diff_hour-60*$_ET_mins" | bc` + local _resultvar=$2 + eval "$_resultvar=`printf \"%02d/%02d:%02d:%06.3f\" $_ET_days $_ET_hours $_ET_mins $_ET_secs`" +} diff --git a/debian/_buildscripts/local/scripts/internals/_build_set_common.sh b/debian/_buildscripts/local/scripts/internals/_build_set_common.sh new file mode 100755 index 000000000..7d28736b0 --- /dev/null +++ b/debian/_buildscripts/local/scripts/internals/_build_set_common.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# Load common code and initialization +. ./internals/_build_common.sh +init_common + +_BUILDSET_TIMER=1 +_BUILDSET_TIME="--/--:--:--:---" + +parm_SKIP_FETCH="n" # if "y" skips N packages from the list +parm_SKIP_N=0 # this argument represents the number of packages to skip +SKIP_cnt=0 + + +#---------------------------- +# do_exit for set building +function do_exit() +{ + cd "$SCRIPT_DIR" + if [ $1 -eq 0 ]; then + echo -e "${CGray}#### Building process for set \"${0##*/}\" completed ####${CNone}" + else + echo -e "${CGray}#### Building process for set \"${0##*/}\" interrupted ($1) ####${CNone}" + fi + exit $1 +} + + +#---------------------------- +function set_log_start() +{ + echo -e "${CGray}#### Starting building process for set \"${0##*/}\" ####${CNone}" + echo + echo "---------- ${0##*/} ----------" >>"$LOG_RESULT_FILENAME" + exec_time_start $_BUILDSET_TIMER +} + + +#---------------------------- +function set_log_end() +{ + exec_time_stop $_BUILDSET_TIMER "_BUILDSET_TIME" + echo " [$_BUILDSET_TIME] SET ${0##*/}" >>"$LOG_RESULT_FILENAME" + echo >>"$LOG_RESULT_FILENAME" + do_exit 0 +} + + +#---------------------------- +function build_module() +{ + if [ $parm_SKIP_N -gt 0 -a $SKIP_cnt -lt $parm_SKIP_N ]; then + SKIP_cnt=$((SKIP_cnt+1)) + else + ./build_module.sh "$BUILD_DEFAULT_OPTIONS $@" + echo + fi +} + + +#---------------------------- +# Check command line arguments +#---------------------------- +for arg in $@; do + if [ "$parm_SKIP_FETCH" = "y" ]; then + parm_SKIP_N=$arg + parm_SKIP_FETCH="n"BUILD_DEFAULT_OPTIONS + elif [ "$arg" = "-s" ]; then # skip first N packages + parm_SKIP_FETCH="y" + fi +done +if [ "$parm_SKIP_FETCH" = "y" ]; then + echo "Invalid command line arguments ($@)" + do_exit 3 +fi diff --git a/debian/_buildscripts/local/scripts/internals/_config_template.sh b/debian/_buildscripts/local/scripts/internals/_config_template.sh new file mode 100644 index 000000000..ea8f438ba --- /dev/null +++ b/debian/_buildscripts/local/scripts/internals/_config_template.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -a + +#---------------------------- +# Build information +#---------------------------- +TDE_RELEASE="14.1.0" # TDE release number +DISTRO="debian" # Distro family +DISTRO_NAME="buster" # Distro name of specific version +ARCHITECTURE="amd64" # Build for this architecture +USE_LOCAL_BUILD_NUMBER="n" # If == "y", use local build numbering for modules +BUILD_NUMBER="b001" # TDE build number +BUILD_DATE="" # Module build date (automatic if "" or fixed otherwise, ex 20171201) +BUILD_DEFAULT_OPTIONS="-g -lr" # Default building options (pbuilder) +GPG_SIGN_KEYID="" # Use this GPG key to sign packages. If null, packages will not be signed + +#---------------------------- +# Base directories +#---------------------------- +# TDE root folder +TDE_DIR="" +# Relative paths +CFG_SCRIPT_LOG_DIR="0_logs" +CFG_GIT_DIR="1_git" +CFG_BUILD_DIR="2_build" +CFG_REPO_DIR="3_repo" +CFG_EXTRA_DEPS_DIR="edeps" # Relative to CFG_GIT_DIR folder +CFG_HOOKS_DIR="hooks" # Relative to CFG_GIT_DIR folder +# Composite paths +CFG_GIT_TDE_MAIN="$CFG_GIT_DIR/tde/main" +CFG_GIT_TDE_PACKAGING="$CFG_GIT_DIR/tde-packaging/$DISTRO/$DISTRO_NAME" +CFG_GIT_EXTRA_DEPENDENCIES="$CFG_GIT_DIR/$CFG_EXTRA_DEPS_DIR" +CFG_HOOK_DIR="$CFG_GIT_DIR/$CFG_HOOKS_DIR" + +#---------------------------- +# Build output directories +#---------------------------- +CFG_TDE_BUILD_DIR="$CFG_BUILD_DIR/build" +CFG_TDE_DEBS_DIR="$CFG_BUILD_DIR/debs" + +#---------------------------- +set +a diff --git a/debian/_buildscripts/local/scripts/internals/_pbuilder.sh b/debian/_buildscripts/local/scripts/internals/_pbuilder.sh new file mode 100755 index 000000000..9b6ffb7b5 --- /dev/null +++ b/debian/_buildscripts/local/scripts/internals/_pbuilder.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +function run_pdebuild() +{ + # pbuilder absolute paths + PBUILDER_HOOK_DIR="/var/cache/pbuilder/hooks" + PBUILDER_SHELL_HOOK_TEMPLATE="$SCRIPT_DIR/internals/C10shell" + PBUILDER_SHELL_HOOK="$PBUILDER_HOOK_DIR/C10shell" + PBUILDER_DEPS_HOOK="$PBUILDER_HOOK_DIR/D05deps" + + # Local option variables + # - internal pbuilder + OPT_INTERNAL_PBUILDER="" + if [ "$bool_INTERNAL_PBUILDER" = "y" ]; then + OPT_INTERNAL_PBUILDER="--use-pdebuild-internal" + fi + # Sign packages optino + OPT_SIGN_PKG_PBUILDER="" + if [ ! -z "$GPG_SIGN_KEYID" ]; then + OPT_SIGN_PKG_LOCAL="-k$GPG_SIGN_KEYID" + OPT_SIGN_PKG_PBUILDER="--auto-debsign --debsign-k $GPG_SIGN_KEYID" + fi + + ## Build module in a clean chroot environment using pbuilder + # Install/remove shell hook + if [ ! -d "$PBUILDER_HOOK_DIR" ]; then + mkdir -p "$PBUILDER_HOOK_DIR" + fi + if [ "$bool_SHELL_HOOK" = "y" ]; then + cp "$PBUILDER_SHELL_HOOK_TEMPLATE" "$PBUILDER_SHELL_HOOK" + chmod a+x "$PBUILDER_SHELL_HOOK" + else + if [ -x "$PBUILDER_SHELL_HOOK" ]; then + rm "$PBUILDER_SHELL_HOOK" + fi + fi + # Build using pbuilder + echo -e "${CYellow}> Building using pbuilder${CNone}" + # Create pbuilder hook to make sure all available packages are scanned + # Store any existing D05 hook as a temporary file, this will be reinstated at the end + cat <<END_D05 > "$PBUILDER_DEPS_HOOK" +#!/bin/sh +(cd "$TDE_DEBS_DIR"; apt-ftparchive packages . > Packages) +echo "deb [trusted=yes] file://$TDE_DEBS_DIR ./" >> /etc/apt/sources.list +apt-get update +END_D05 + chmod a+x "$PBUILDER_DEPS_HOOK" + # Build + eval pdebuild $OPT_INTERNAL_PBUILDER $OPT_SIGN_PKG_PBUILDER \ + --architecture $ARCHITECTURE \ + --buildresult \"$MOD_DEB_PATH\" \ + --pbuilderroot \"sudo DIST=$DISTRO_NAME ARCH=$ARCHITECTURE\" \ + --logfile \"$BUILDING_LOG_FILE\" \ + -- \ + --bindmounts \"$TDE_DEBS_DIR\" \ + --hookdir \"$PBUILDER_HOOK_DIR\" \ + $OPT_SHOW_LOGS\"$BUILDING_LOG_FILE\" + PBUILDER_RETVAL=$? + # Remove shell hook if it was installed before the build + if [ -x "$PBUILDER_SHELL_HOOK" ]; then + rm "$PBUILDER_SHELL_HOOK" + fi + # Remove deps hook + if [ -x "$PBUILDER_DEPS_HOOK" ]; then + rm "$PBUILDER_DEPS_HOOK" + fi + # Return pdebuild return value to calling function + return $PBUILDER_RETVAL +} + + +#---------------------------- +# The actual code is inside a function to allow the pdebuild return value to be +# correctly passed back to the calling script in all cases (root and non root users) +run_pdebuild
\ No newline at end of file diff --git a/debian/_buildscripts/local/scripts/internals/_update_repositories.sh b/debian/_buildscripts/local/scripts/internals/_update_repositories.sh new file mode 100755 index 000000000..fa5a1bd74 --- /dev/null +++ b/debian/_buildscripts/local/scripts/internals/_update_repositories.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +#---------------------------- +# Update TDE main repository +echo -e "\n---- Updating main TDE GIT repo ----\n" + +cd "$TDE_DIR/$CFG_GIT_DIR/tde" +if [[ ! -e .git ]] || [[ -z "`git rev-parse --git-dir 2>/dev/null`" ]]; then + echo "Current directory does not contain a .git folder. Exiting..." + cd $SCRIPT_DIR + exit 1 +fi + +branch=`git symbolic-ref -q HEAD | sed "s|^refs/heads/||"` +if [[ -z "$branch" ]] || [[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then + echo "There is not active upstream branch. Exiting..." + cd $SCRIPT_DIR + exit 1 +fi + +touch /var/lock/update-tde-git-submodules + +PARENTDIR=$PWD +echo "---- Main repo ----" +git pull --rebase +if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then + git reset --hard HEAD + git clean -dxff +fi + +exec 3< submodules +while read <&3 +do + cd $PARENTDIR + DIR2UPDATE=$REPLY + if [[ $DIR2UPDATE != "" ]]; then + echo -e "\n---- Submodule $DIR2UPDATE ----" + cd $PARENTDIR/$DIR2UPDATE/.. + cd `git rev-parse --show-toplevel` + if [[ -z "`grep \"^Updated: $PWD$\" /var/lock/update-tde-git-submodules`" ]]; then + echo "Updated: $PWD" >>/var/lock/update-tde-git-submodules + git submodule init + git submodule update + fi + cd $PARENTDIR/$DIR2UPDATE + if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then + git reset --hard HEAD + git clean -dxff + fi + git checkout $branch + git pull --rebase + cd .. + cd `git rev-parse --show-toplevel` + fi +done +exec 3>&- + +rm /var/lock/update-tde-git-submodules + + +#------------------------------ +# Update TDE-packaging repository +echo -e "\n----------------------------------------" +echo -e "\n--- Updating TDE-packaging GIT repo ----\n" + +cd "$TDE_DIR/$CFG_GIT_DIR/tde-packaging" +git pull --rebase + + +#------------------------------ +# Done +cd $SCRIPT_DIR diff --git a/debian/_buildscripts/local/scripts/internals/distro_list.txt b/debian/_buildscripts/local/scripts/internals/distro_list.txt new file mode 100644 index 000000000..0ca037eb0 --- /dev/null +++ b/debian/_buildscripts/local/scripts/internals/distro_list.txt @@ -0,0 +1,31 @@ +#!/bin/bash + +# List of supported distributions +DISTROS=" + debian 5.0 lenny + debian 6.0 squeeze + debian 7.0 wheezy + debian 8.0 jessie + debian 9.0 stretch + debian 10.0 buster ~a + debian 10.0 sid ~b + raspbian 7.0 raspbian-wheezy + raspbian 8.0 raspbian-jessie + ubuntu 10.04 lucid + ubuntu 10.10 maverick + ubuntu 11.04 natty + ubuntu 11.10 oneiric + ubuntu 12.04 precise + ubuntu 12.10 quantal + ubuntu 13.04 raring + ubuntu 13.10 saucy + ubuntu 14.04 trusty + ubuntu 14.10 utopic + ubuntu 15.04 vivid + ubuntu 15.10 wily + ubuntu 16.04 xenial + ubuntu 16.10 yakkety + ubuntu 17.04 zesty + ubuntu 17.10 artful + ubuntu 18.04 bionic ~a +" |