dam/src/export_rm

27 lines
821 B
Bash

#!/bin/bash
# doc export_rm {
#
# DESCRIPTION
# export_rm - Removes TRACKIDs from TARGET
#
# USAGE
# export_rm </path/to/target> </path/to/db/file> <TRACKID>
#
# DEPENDENCIES bunc/src/* src/print_present_path
#
# }
export_rm() {
## Argument parsing
local TARGET="${1}"
local DB_FILE="${2}"
local IMAGEID=$(awk 'BEGIN{FS="--"}{print $1"--"$2}' <<< ${3})
local TRACKID=$(awk 'BEGIN{FS="--"}{print $3}' <<< ${3})
## Removes trackids from TARGET
_msg EXEC "Removing ${TRACKID} from ${TARGET}"
rm "${TARGET}/$(print_present_path "${DB_FILE}" ${IMAGEID} ${TRACKID})" >${STDERR} 2>&1
[[ $? -eq 0 ]] && { _msg OK; gawk -i inplace -v trackid=${TRACKID} -v value=null 'BEGIN{FS="\t";OFS="\t"}{if($3==trackid){$4=value}{print $0}}' ${DB_FILE}; return 0; } || { _msg WARN; return 1; }
}