File file_completed_command.sh of Package mldonkey-service

#!/bin/sh
#
# MLDonkey script to be called after a file is committed
# this is called by setting value in 'downloads.ini':
#    file_completed_cmd = "/var/lib/mldonkey/bin/file_completed_command.sh"
# Ref: http://mldonkey.sourceforge.net/File_completed_cmd
#

# Arguments passed in -- (kept for compatibility):
tmpFileName="$1"
fileSize="$2"
fileName="$3"

#----------------------
# Enviroment variables set on call -- (preferred way)
#    TEMPNAME: Temp file name, including path.
#    FILEID: The MD4 hash of the file (same as $1).
#    FILESIZE: The size of the file in bytes (same as $2).
#    FILENAME: The file name for the download (same as $3).
#    FILEHASH: Internal hash.
#    DURATION: Download duration in seconds.
#    INCOMING: Directory used for commit.
#    NETWORK: Network name used for downloading.
#    ED2K_HASH: ed2k hash if MD4 is known.
#    DLFILES: Number of downloading files. (since 2.7.5)
#    FILE_OWNER: The user who owns the downloaded file.
#    FILE_GROUP: The group which owns the downloaded file.
#    USER_MAIL: E-mail of the user who owns the downloaded file. 
#    FILE_GROUP_CNT: Number of other users besides FILE_OWNER who could see the file.
#    FILE_GROUP_USER_n: User name n.
#    FILE_GROUP_DIR_n: User n commit directory. 
#----------------------

# Defaults:
MLNET_HOME="/var/lib/mldonkey"
MLNET_LOGDIR="/var/log/mldonkey"

# Control Parameters
SENDCOMMAND_KEYFILE="${MLNET_HOME}/.keys/mlnet.service.key"
SHUTDOWN_AFTER_LAST_DNLD=1
SHUTDOWN_DELAY="5m"

[ -e /etc/sysconfig/mldonkey ] && source /etc/sysconfig/mldonkey

# Logging
LOGFILE="${MLNET_LOGDIR}/file_cmd.log"
logThis(){
    echo -e "$(date +%Y%m%d-%H%M%S)] $@" >> ${LOGFILE}
}

# Send command to mldonkey service
mlnet_cmd(){
    #/usr/bin/mldonkey_command --auth 'admin password' "$@" >/dev/null 2>&1
    ${MLNET_HOME}/bin/mlnet_sendcommand --auth-keyfile "${SENDCOMMAND_KEYFILE}" "$@"
}

# Log when called
logThis "Completed: ${FILEID} ${fileName} ${fileSize} ${ED2K_HASH}, ${USER_MAIL} | dlfiles: ${DLFILES}"

# Shutdown core after last downloaded file
if [ $SHUTDOWN_AFTER_LAST_DNLD == 1 ] && [ ${DLFILES} == 0 ]; then
        logThis "--- Stopping mldonkey service --- (after delay of ${SHUTDOWN_DELAY})"
        sleep ${SHUTDOWN_DELAY}
        #systemctl stop mldonkey.service
        logThis "--- Sending Kill command ---"
        mlnet_cmd kill
fi

# What else to do? ;) ....
openSUSE Build Service is sponsored by