diff --git a/build-package.sh b/build-package.sh index 16a4464bf1..dbd142d5af 100755 --- a/build-package.sh +++ b/build-package.sh @@ -159,6 +159,10 @@ termux_step_post_make_install() { return } +# Add service scripts from array TERMUX_PKG_SERVICE_SCRIPT, if it is set +# shellcheck source=scripts/build/termux_step_install_service_scripts.sh +source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_install_service_scripts.sh" + # Link/copy the LICENSE for the package to $TERMUX_PREFIX/share/$TERMUX_PKG_NAME/ # shellcheck source=scripts/build/termux_step_install_license.sh source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_install_license.sh" @@ -322,6 +326,7 @@ while (($# > 0)); do termux_step_make_install cd "$TERMUX_PKG_BUILDDIR" termux_step_post_make_install + termux_step_install_service_scripts termux_step_install_license cd "$TERMUX_PKG_MASSAGEDIR" termux_step_extract_into_massagedir diff --git a/scripts/build/termux_step_install_service_scripts.sh b/scripts/build/termux_step_install_service_scripts.sh new file mode 100644 index 0000000000..2b155e5fcc --- /dev/null +++ b/scripts/build/termux_step_install_service_scripts.sh @@ -0,0 +1,26 @@ +termux_step_install_service_scripts() { + array_length=${#TERMUX_PKG_SERVICE_SCRIPT[@]} + if [ $array_length -eq 0 ]; then return; fi + + # TERMUX_PKG_SERVICE_SCRIPT should have the structure =("daemon name" 'script to execute') + if [ $(( $array_length & 1 )) -eq 1 ]; then + termux_error_exit "TERMUX_PKG_SERVICE_SCRIPT has to be an array of even length" + fi + + mkdir -p $TERMUX_PREFIX/var/service + cd $TERMUX_PREFIX/var/service + for ((i=0; i<${array_length}; i+=2)); do + mkdir -p ${TERMUX_PKG_SERVICE_SCRIPT[$i]}/log + echo "#!$TERMUX_PREFIX/bin/sh" > ${TERMUX_PKG_SERVICE_SCRIPT[$i]}/run + echo -e ${TERMUX_PKG_SERVICE_SCRIPT[$((i + 1))]} >> ${TERMUX_PKG_SERVICE_SCRIPT[$i]}/run + + TERMUX_PKG_CONFFILES+=" + var/service/${TERMUX_PKG_SERVICE_SCRIPT[$i]}/run + var/service/${TERMUX_PKG_SERVICE_SCRIPT[$i]}/log/run + " + + chmod +x ${TERMUX_PKG_SERVICE_SCRIPT[$i]}/run + touch ${TERMUX_PKG_SERVICE_SCRIPT[$i]}/down + ln -sf $TERMUX_PREFIX/share/termux-services/svlogger ${TERMUX_PKG_SERVICE_SCRIPT[$i]}/log/run + done +} diff --git a/scripts/build/termux_step_setup_variables.sh b/scripts/build/termux_step_setup_variables.sh index c7dcd0a4be..e59a85aac2 100644 --- a/scripts/build/termux_step_setup_variables.sh +++ b/scripts/build/termux_step_setup_variables.sh @@ -125,6 +125,7 @@ termux_step_setup_variables() { TERMUX_PKG_SUGGESTS="" TERMUX_PKG_REPLACES="" TERMUX_PKG_PROVIDES="" #https://www.debian.org/doc/debian-policy/#virtual-packages-provides + TERMUX_PKG_SERVICE_SCRIPT=() # Fill with entries like: ("daemon name" 'script to execute'). Script is echoed with -e so can contain \n for multiple lines TERMUX_PKG_CONFFILES="" # Set if a host build should be done in TERMUX_PKG_HOSTBUILD_DIR: TERMUX_PKG_HOSTBUILD=false diff --git a/scripts/lint-packages.sh b/scripts/lint-packages.sh index 767d153b53..415d37f5a9 100755 --- a/scripts/lint-packages.sh +++ b/scripts/lint-packages.sh @@ -378,6 +378,17 @@ lint_package() { unset file_path_ok fi + if [ -n "$TERMUX_PKG_SERVICE_SCRIPT" ]; then + echo -n "TERMUX_PKG_SERVICE_SCRIPT: " + array_length=${#TERMUX_PKG_SERVICE_SCRIPT[@]} + if [ $(( $array_length & 1 )) -eq 1 ]; then + echo "INVALID (TERMUX_PKG_SERVICE_SCRIPT has to be an array of even length)" + pkg_lint_error=true + else + echo "PASS" + fi + fi + if $pkg_lint_error; then exit 1 else