diff options
Diffstat (limited to 'debian/_buildscripts/local/scripts/build_module.sh')
-rwxr-xr-x | debian/_buildscripts/local/scripts/build_module.sh | 99 |
1 files changed, 30 insertions, 69 deletions
diff --git a/debian/_buildscripts/local/scripts/build_module.sh b/debian/_buildscripts/local/scripts/build_module.sh index 3961123fe..adfc4172e 100755 --- a/debian/_buildscripts/local/scripts/build_module.sh +++ b/debian/_buildscripts/local/scripts/build_module.sh @@ -4,15 +4,23 @@ # # Load common code and initialization -. ./_build_common.sh +. ./internals/_build_common.sh init_common + # Timer settings _BUILDMOD_TIMER_NUM=0 _BUILDMOD_TIME="--/--:--:--:---" exec_time_start $_BUILDMOD_TIMER_NUM +# Need sudo for non-root users +SUDO_CMD="" +if [ "`whoami`" != "root" ]; then + SUDO_CMD="sudo -E" +fi + + #---------------------------- # Parameters: # $1 - error code @@ -40,7 +48,7 @@ function do_exit() function recreate_folder() { if [ -d "$1" ]; then - rm -R "$1" + $SUDO_CMD rm -R "$1" fi mkdir -p "$1" } @@ -97,33 +105,18 @@ if [ "bool_BUILD_LOCALLY" = "y" ]; then bool_SHELL_HOOK="n" bool_INTERNAL_PBUILDER="n" fi - -# pbuilder absolute paths -PBUILDER_HOOK_DIR="$HOME/.pbuilder/hooks" -PBUILDER_SHELL_HOOK="$PBUILDER_HOOK_DIR/C10shell" -PBUILDER_SHELL_HOOK_TEMPLATE="$PBUILDER_HOOK_DIR/__template_C10shell" -PBUILDER_DEPS_HOOK="$PBUILDER_HOOK_DIR/D05deps" -PBUILDER_DEPS_HOOK_SAVE="$PBUILDER_HOOK_DIR/__saved_D05deps" +export bool_SHELL_HOOK +export bool_INTERNAL_PBUILDER # Local option variables -# - internal pbuilder -OPT_INTERNAL_PBUILDER="" -if [ "$bool_INTERNAL_PBUILDER" = "y" ]; then - OPT_INTERNAL_PBUILDER="--use-pdebuild-internal" -fi # - sign packages OPT_SIGN_PKG_LOCAL="-uc -us" -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 # - show logs OPT_SHOW_LOGS="&>" if [ "$bool_SHOW_BUILD_LOGS" = "y" ]; then OPT_SHOW_LOGS=" | tee " fi - +export OPT_SHOW_LOGS # Log start echo -e "${CLightCyan}#### Processing module \"$MOD_NAME\" ####${CNone}" @@ -154,7 +147,7 @@ done # Build output directories #---------------------------- TDE_BUILD_DIR="$TDE_DIR/$CFG_TDE_BUILD_DIR" -TDE_DEBS_DIR="$TDE_DIR/$CFG_TDE_DEBS_DIR" +export TDE_DEBS_DIR="$TDE_DIR/$CFG_TDE_DEBS_DIR" BUILD_DIRS=("TDE_BUILD_DIR" "TDE_DEBS_DIR") @@ -218,14 +211,13 @@ else fi fi - #---------------------------- # Prepare source files #---------------------------- # remove output from previous build if [ -d "$MOD_BUILD_PATH" ]; then cd "$MOD_BUILD_PATH/.." - rm *.deb *.dsc *.changes *.tar.bz2 *.tar.gz *.tar.xz *.log *.buildinfo &>/dev/null + $SUDO_CMD rm *.deb *.dsc *.changes *.tar.bz2 *.tar.gz *.tar.xz *.log *.buildinfo &>/dev/null fi # copy main repo source files, if needed @@ -249,7 +241,7 @@ if [ "$bool_COPY_MOD_SRC" = "y" ]; then # Extra dependency module if [ `find "$MOD_GIT_PATH" -name '*.dsc' | wc -l` == 1 ]; then if [ -d "$MOD_BUILD_PATH" ]; then - rm -R "$MOD_BUILD_PATH" + $SUDO_CMD rm -R "$MOD_BUILD_PATH" fi eval dpkg-source --no-copy --no-check -x `find "$MOD_GIT_PATH" -name '*.dsc'` \ \"$MOD_BUILD_PATH\" $OPT_SHOW_LOGS/dev/null @@ -267,7 +259,7 @@ fi # copying packaging scripts, if needed if [ "$bool_EXTRADEP_MOD" != "y" -a "$bool_COPY_PKGING_FILES" = "y" ]; then if [ -d "$MOD_BUILD_PKGING_PATH" ]; then - rm -R $MOD_BUILD_PKGING_PATH + $SUDO_CMD rm -R $MOD_BUILD_PKGING_PATH fi cp -R "$MOD_GIT_PKGING_PATH" "$MOD_BUILD_PKGING_PATH" @@ -327,7 +319,7 @@ if [ "$bool_EXTRADEP_MOD" != "y" -a "$bool_COPY_PKGING_FILES" = "y" ]; then fi # prepare destination directory for building -MOD_DEB_PATH="$TDE_DEBS_DIR/$MOD_NAME" +export MOD_DEB_PATH="$TDE_DEBS_DIR/$MOD_NAME" MOD_DEBSRC_PATH="$MOD_DEB_PATH/src" recreate_folder "$MOD_DEB_PATH" recreate_folder "$MOD_DEBSRC_PATH" @@ -390,57 +382,26 @@ fi #---------------------------- # Build #---------------------------- -BUILDING_LOG_FILE="$MOD_DEBSRC_PATH/__build__.log" +export BUILDING_LOG_FILE="$MOD_DEBSRC_PATH/__build__.log" cd "$MOD_BUILD_PATH" if [ "$bool_BUILD_LOCALLY" = "y" ]; then ## Build module locally echo -e "${CYellow}> Building locally${CNone}" eval dpkg-buildpackage $OPT_SIGN_PKG_LOCAL $OPT_SHOW_LOGS\"$BUILDING_LOG_FILE\" - build_retval=$? - # + build_retval=$? else ## Build module in a clean chroot environment using pbuilder - # Install/remove shell hook - if [ "$bool_SHELL_HOOK" = "y" ]; then - if [ -x "$PBUILDER_SHELL_HOOK_TEMPLATE" ]; then - cp "$PBUILDER_SHELL_HOOK_TEMPLATE" "$PBUILDER_SHELL_HOOK" &>/dev/null - else - echo "pbuilder shell hook template file not found! ($PBUILDER_SHELL_HOOK_TEMPLATE)" - fi - else - if [ -x "$PBUILDER_SHELL_HOOK" ]; then - rm "$PBUILDER_SHELL_HOOK" &>/dev/null - 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 - if [ -x "$PBUILDER_DEPS_HOOK" ]; then - mv "$PBUILDER_DEPS_HOOK" "$PBUILDER_DEPS_HOOK_SAVE" - fi - 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\" - build_retval=$? - if [ -x "$PBUILDER_DEPS_HOOK" ]; then - mv "$PBUILDER_DEPS_HOOK_SAVE" "$PBUILDER_DEPS_HOOK" - fi + $SUDO_CMD "$SCRIPT_DIR/internals/_pbuilder.sh" + build_retval=$? + if [ "`whoami`" != "root" ]; then + cd "$MOD_DEB_PATH" + $SUDO_CMD chown -R `id -u -n`:`id -g -n` . &>/dev/null + cd "$MOD_BUILD_PATH/.." + $SUDO_CMD chown `id -u -n`:`id -g -n` *.dsc *.changes *.tar.xz *.tar.bz2 *.tar.gz *.buildinfo &>/dev/null + $SUDO_CMD chown `id -u -n`:`id -g -n` "$TDE_DEBS_DIR/Packages" &>/dev/null + cd "$MOD_BUILD_PATH" + fi fi if [ $build_retval -eq 0 ]; then |