Skip to content
Permalink
Browse files

build.sh: introduce option --target-dir.

This should be helpful for test installations. Result verified to
be identical to a ZIP created the former way, unpacked into an
empty diretory.

Unfortunately one can't instruct Composer to not create symbolic
links, so these have to get resolved "manually".
  • Loading branch information...
Traumflug committed Aug 9, 2019
1 parent c06ad3c commit 901b0a2cc21fb2e7efd95a4764605f876d8e7024
Showing with 53 additions and 9 deletions.
  1. +53 −9 build.sh
@@ -1,7 +1,8 @@
#!/usr/bin/env bash

function usage {
echo "Usage: build.sh [-h|--help] [--[no-]validate] [<git revision>]"
echo "Usage: build.sh [-h|--help] [--[no-]validate] [--target-dir=<dir>]"
echo " [<git revision>]"
echo
echo "This script builds an installation package from the current repository."
echo
@@ -11,6 +12,9 @@ function usage {
echo " validate when packaging 'master' or the"
echo " latest tag, but not when packaging others."
echo
echo " --target-dir=<dir> Instead of building a package, drop the to be"
echo " packaged files in <dir>."
echo
echo " <git revision> Any Git tag, branch or commit. Defaults to"
echo " the latest tag ( = latest release)."
echo
@@ -21,7 +25,7 @@ function usage {
#
# Triggered by a trap, because we have multiple exit points.
function cleanup {
if [ -n "${PACKAGING_DIR}" ]; then
if [ -n "${PACKAGING_DIR}" ] && [ -z "${TARGET_DIR}" ]; then
echo "Deleting temporary packaging directory."
rm -rf ${PACKAGING_DIR}
fi
@@ -44,6 +48,7 @@ trap cleanup 0

OPTION_VALIDATE='auto'
GIT_REVISION=''
TARGET_DIR=''

while [ ${#} -ne 0 ]; do
case "${1}" in
@@ -57,6 +62,21 @@ while [ ${#} -ne 0 ]; do
'--no-validate')
OPTION_VALIDATE='false'
;;
'--target-dir')
if [ -z "${2}" ]; then
echo "Option --target-dir missing parameter. Aborting."
exit 1
fi
TARGET_DIR="${2}"
shift
;;
'--target-dir='*)
TARGET_DIR="${1#*=}"
if [ -z "${TARGET_DIR}" ]; then
echo "Option --target-dir= missing parameter. Aborting."
exit 1
fi
;;
*)
if ! git show -q "${1}" 2>/dev/null | grep -q '.'; then
echo "Git revision '${1}' doesn't exist. Aborting."
@@ -95,6 +115,12 @@ if [ ! -e .git ]; then
exit 1
fi

# Test for the existence of the target directory.
if [ -n "${TARGET_DIR}" ] && ! [ -d "${TARGET_DIR}" ]; then
echo "Requested target directory doesn't exist. Aborting."
exit 1
fi

# There should be no staged changes.
if ([ ${OPTION_VALIDATE} = 'true' ] \
|| [ ${OPTION_VALIDATE} = 'auto' ]) \
@@ -209,11 +235,15 @@ done

### Actual packaging.

# Create packaging directory.
PACKAGING_DIR=$(mktemp -d)
if [ -z "${TARGET_DIR}" ]; then
# Create packaging directory.
PACKAGING_DIR=$(mktemp -d)

PACKAGING_DIR+="/${PACKAGE_NAME}"
mkdir "${PACKAGING_DIR}"
PACKAGING_DIR+="/${PACKAGE_NAME}"
mkdir "${PACKAGING_DIR}"
else
PACKAGING_DIR="${TARGET_DIR}"
fi
export PACKAGING_DIR


@@ -410,12 +440,26 @@ done || exit ${?}
cd "${PACKAGING_DIR}" || exit ${?}
php ./tools/generatemd5list.php || exit ${?}
rm -f cache/class_index.php # Gets created by running generatemd5list.php.
zip -r -q "${PACKAGE_NAME}".zip . || exit ${?}
if [ -z "${TARGET_DIR}" ]; then
zip -r -q "${PACKAGE_NAME}".zip . || exit ${?}
else
# Make links normal files to match what unpacking a ZIP would give.
TEMPNAME=$(mktemp -u)
find . -type l -print | while read F; do
cp -p "${F}" ${TEMPNAME} || exit ${?}
mv ${TEMPNAME} "${F}" || exit ${?}
done || exit ${?}
unset TEMPNAME
fi
echo "done."
) || exit ${?}

mv "${PACKAGING_DIR}"/"${PACKAGE_NAME}".zip . || exit ${?}
echo "Created ${PACKAGE_NAME}.zip successfully."
if [ -z "${TARGET_DIR}" ]; then
mv "${PACKAGING_DIR}"/"${PACKAGE_NAME}".zip . || exit ${?}
echo "Created ${PACKAGE_NAME}.zip successfully."
else
echo "Created files in ${TARGET_DIR} successfully."
fi


# Cleanup happens via a trap.

0 comments on commit 901b0a2

Please sign in to comment.
You can’t perform that action at this time.