diff --git a/build_flat_perl_file.sh b/build_flat_perl_file.sh new file mode 100644 index 0000000000000000000000000000000000000000..e97c40c5034aa1273432313a2b68ce488ba51a7e --- /dev/null +++ b/build_flat_perl_file.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Script to bundle *local* Perl-Module with Script +# by Andreas Romeyke @ SLUB Dresden +WHAT_TO_BUNDLE=bin/slubsipbuilderbagit.pl +LIB_TO_BUNDLE="lib/" +BUNDLE_NAME=slubsipbuilder_bundled.pl +BUNDLE_LOG=bundle.log +echo "#!/usr/bin/env perl" > ${BUNDLE_NAME}; +echo "detecting all *.pm modules in $LIB_TO_BUNDLE and cat them to bundle ${BUNDLE_NAME}" > ${BUNDLE_LOG} +find $LIB_TO_BUNDLE -name "*.pm" -exec cat \{\} \; >> ${BUNDLE_NAME}; +echo "patching main package to bundle ${BUNDLE_NAME}" >> ${BUNDLE_LOG}; +echo "######################################" >> ${BUNDLE_NAME}; +cat <<__MAIN >> ${BUNDLE_NAME} +package main; +BEGIN{ + if ($^O eq 'MSWin32') { + require Win32::Console::ANSI; + Win32::Console::ANSI->import(); + } + ## no critic + # HINT: enhance \$INC foreach module in lib/-dir! + \$INC{'SLUB/LZA/SIPBuilderBagIt.pm'} = 1; # needed because inlined module + ## use critic +} +return 1 if caller; # avoids main code running if module stuff is needed +__MAIN +echo "######################################" >> ${BUNDLE_NAME}; +echo "adding main script to bundle ${BUNDLE_NAME}" >> ${BUNDLE_LOG} +cat ${WHAT_TO_BUNDLE} >> ${BUNDLE_NAME}; +echo "checking bundle ${BUNDLE_NAME} if compiled successfully" >> ${BUNDLE_LOG} +perl -c ${BUNDLE_NAME} >> ${BUNDLE_LOG} +if [[ $? -eq 0 ]]; then + echo "fine :)" + echo "Successfully build bundles in ${BUNDLE_NAME}" + rm -f ${BUNDLE_LOG} +else + echo "failed! :'(" + echo "Something was wrong in bundling to ${BUNDLE_NAME}" + echo "Check ${BUNDLE_LOG} for details" +fi