67 lines
3.4 KiB
Bash
Executable file
67 lines
3.4 KiB
Bash
Executable file
#! Name: ExampleAddNewFuncAndCallOnSuccessfulDownload.sh
|
|
#! Author: kittykat
|
|
#! Version: 2024.09.21
|
|
#! Desc: Add a new function to MAD and call it whenever a file is successfully downloaded
|
|
#! Usage: Edit LoadPlugin="" line in mad.sh or mad.config
|
|
#! LoadPlugin="ExampleAddNewFuncAndCallOnSuccessfulDownload.sh"
|
|
#!
|
|
#! Notes: Not that this would be used as such (performing a sha256 hash of file would be added directly to the
|
|
#! desired hook -- PostSuccessfulDownload(). This is just an example to show that creating your own
|
|
#! function and then calling it is possible.
|
|
#!
|
|
#! * This could be used to add new host urls, and process them:
|
|
#! PreProcessUrl_mysha256() : parse the line and determine if it is a supported host, call new functions
|
|
#!
|
|
#! Plugin System: Additional Hook Functions added for easy of overriding:
|
|
#!
|
|
#! To Hook a Function, your function must begin with the hookable function name, and be unique
|
|
#! Best practice: HooKFuncName_<yourfilename>
|
|
#! ie.
|
|
#! PostSuccessfulDownload_myfilename() {
|
|
#! }
|
|
#!
|
|
#! Available Hook Functions:
|
|
#! -------------------------
|
|
#! * OnLoad(): Occurs after load mad.config / load plugins (prior to processing).
|
|
#! * BeginProcessing(): Occurs immediately after beginning processin of urls.txt (loops with Catnaps).
|
|
#! * PreProcessUrl(): occurs immediately after reading in an unprocessed url (^http) line to process.
|
|
#! * PostSuccessfulDownload(): occurs after a download success (is marked #OK# in the urls.txt).
|
|
#! * PostFailedDownload(): occurs after a download fails (is marked #FAIL# in the urls.txt).
|
|
#! * PostFailRetryDownload(): occurs after a download fails with a retry (is marked #RETRY# in the urls.txt).
|
|
#! * DoneProcessingAllUrls(): occurs after all the urls have finished processing (no flocks or other terms downloading).
|
|
#! * PostSuccessfulUpload(): occurs after an upload success (after upload completed ticket is created in ./downloads/).
|
|
#! * PostFailedUpload(): occurs after an upload fails definitively -- #FAIL# in the temp_upload_handler.txt
|
|
#! * PostFailRetryUpload(): occurs after an upload fails with a retry (network drop, unexpected result)
|
|
#! * DoneProcessingAllUploads: occurs after alll the files have finished processing
|
|
#!
|
|
#! ----------- Hooks ----------------------------
|
|
#!
|
|
#! Hook PostSuccessfulDownload() function
|
|
PostSuccessfulDownload_mysha256() {
|
|
local plugName='ExampleAddNewFuncAndCallOnSuccessfulDownload'
|
|
local plugFunc='PostSuccessfulDownload_mysha256'
|
|
if [ "${DebugAllEnabled}" == "true" ]; then
|
|
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
|
|
fi
|
|
local pRemoteUrl="$1"
|
|
local pFilePath="$2"
|
|
local pFileName="$3"
|
|
local pFolderName="$4"
|
|
local pFileSize="$5"
|
|
local fileHash=$(hookHashFile "$pFilePath")
|
|
echo -e "${BLUE}File${NC}: $pFileName"
|
|
echo -e "${BLUE}sha256${NC}: $fileHash"
|
|
return 0
|
|
}
|
|
#! ---------- New User Defined Functions --------------------
|
|
#! Define a new function to hash a file
|
|
#! This will be loaded in the OnLoad() hook in mad.sh, and will become an available function to use after OnLoad()
|
|
hookHashFile() {
|
|
local plugName='ExampleAddNewFuncAndCallOnSuccessfulDownload'
|
|
local plugFunc='hookHashFile'
|
|
if [ "${DebugPluginsEnabled}" == "true" ]; then
|
|
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
|
|
fi
|
|
local pFilePath="$1"
|
|
echo $(sha256sum "$pFilePath" | awk '{ print $1 }')
|
|
}
|