QUIET='n'
SIMULATE="n"
-VERSION="0.3"
+VERSION="0.4"
# console colors:
RED=""
local base_dir=
set +e
- tmp=$( getopt -o R:P:G:F:sdvhV \
+ tmp=$( getopt -o R:L:P:G:F:sdvhV \
--long resolution:,linkdir:,perms:,group:,field-separator:,simulate,debug,verbose,nocolor,help,version \
-n "${BASENAME}" -- "$@" )
if [[ $? != 0 ]] ; then
if [[ "${VERBOSE}" == "y" ]] ; then
cmd+=" --verbose"
fi
- eval ${cmd} "$@"
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Executing: ${cmd}" "$@"
+ else
+ debug "Executing: ${cmd}" "$@"
+ eval ${cmd} "$@"
+ fi
+}
+
+#------------------------------------------------------------------------------
+RM() {
+ local cmd="rm"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd+=" --verbose"
+ fi
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Executing: ${cmd}" "$@"
+ else
+ debug "Executing: ${cmd}" "$@"
+ eval ${cmd} "$@"
+ fi
}
#------------------------------------------------------------------------------
if [[ "${VERBOSE}" == "y" ]] ; then
cmd+=" --verbose"
fi
- eval ${cmd} "$@"
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Executing: ${cmd}" "$@"
+ else
+ debug "Executing: ${cmd}" "$@"
+ eval ${cmd} "$@"
+ fi
+}
+
+#------------------------------------------------------------------------------
+CHOWN() {
+ local cmd="chown"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd+=" --verbose"
+ fi
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Executing: ${cmd}" "$@"
+ else
+ debug "Executing: ${cmd}" "$@"
+ eval ${cmd} "$@"
+ fi
+}
+
+#------------------------------------------------------------------------------
+CHGRP() {
+ local cmd="sudo chgrp"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd+=" --verbose"
+ fi
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Executing: ${cmd}" "$@"
+ else
+ debug "Executing: ${cmd}" "$@"
+ eval ${cmd} "$@"
+ fi
+}
+
+#------------------------------------------------------------------------------
+CHMOD() {
+ local cmd="chmod"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd+=" --verbose"
+ fi
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Executing: ${cmd}" "$@"
+ else
+ debug "Executing: ${cmd}" "$@"
+ eval ${cmd} "$@"
+ fi
}
################################################################################
##
################################################################################
+#------------------------------------------------------------------------------
+perform_movie() {
+
+ src="$1"
+ tgt="$2"
+ title="$3"
+
+ if [[ -f "${tgt}" ]] ; then
+ info "Conversion of '${src}' => '${tgt}' already done."
+ sleep 2
+ return 0
+ fi
+
+ info "Start converting '${src}' => '${tgt}' ..."
+ sleep 2
+
+ local verbose_opt=""
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ verbose_opt="--verbose "
+ fi
+
+ RM -f divx2pass.log frameno.avi
+ echo
+ local cmd="${CONVERT_SCRIPT} ${verbose_opt}-y -S ${RESOLUTION} -T \"${title}\" \"${src}\" \"${tgt}\""
+ echo
+ sleep 2
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Executing: ${cmd}"
+ else
+ debug "Executing: ${cmd}"
+ eval ${cmd} "$@"
+ fi
+ echo
+
+ if [[ -n "${LINK_DIR}" ]] ; then
+ LN "${tgt}" "${LINK_DIR}"
+ echo
+ fi
+
+ CHMOD "${PERMS}" "${tgt}"
+ CHGRP "${OWNING_GROUP}" "${tgt}"
+ sleep 3
+
+}
+
#------------------------------------------------------------------------------
perform_csv() {
fi
debug "Evaluating line ${lnr}: ${line}"
+ cd $( dirname "${CSV_FILE}" )
+ debug "Current base directory is now: '$( pwd )'."
+
+ directory=$( echo "${line}" | \
+ awk -F"${FIELD_SEPARATOR}" '{print $1}' | \
+ sed -e 's/^[ ]*//' -e 's/[ ]*$//' )
+ src=$( echo "${line}" | \
+ awk -F"${FIELD_SEPARATOR}" '{print $2}' | \
+ sed -e 's/^[ ]*//' -e 's/[ ]*$//' | \
+ xargs basename )
+ tgt=$( echo "${line}" | \
+ awk -F"${FIELD_SEPARATOR}" '{print $3}' | \
+ sed -e 's/^[ ]*//' -e 's/[ ]*$//' | \
+ xargs basename )
+ title=$( echo "${line}" | \
+ awk -F"${FIELD_SEPARATOR}" '{print $4}' | \
+ sed -e 's/^[ ]*//' -e 's/[ ]*$//' )
+
+ if [[ -z "${directory}" ]] ; then
+ directory='.'
+ fi
+ debug "Checking working directory '${directory}' ..."
+ if [[ ! -d "${directory}" ]] ; then
+ error "Directory '${RED}${directory}${NORMAL}' not found."
+ continue
+ fi
+
+ cd "${directory}"
+ debug "Current working directory is now: '$( pwd )'."
+
+ debug "Checking source file ..."
+ if [[ -z "${src}" ]] ; then
+ error "No source file name found in line ${lnr}."
+ continue
+ fi
+
+ debug "Checking source file '${src}' ..."
+ if [[ ! -f "${src}" ]] ; then
+ error "Source file '${RED}${src}${NORMAL}' (line ${lnr}) not found."
+ continue
+ fi
+
+ debug "Checking target file ..."
+ if [[ -z "${tgt}" ]] ; then
+ error "No target file name found in line ${lnr}."
+ continue
+ fi
+
+ debug "Checking target file '${tgt}' ..."
+ if [[ "${src}" == "${tgt}" ]] ; then
+ error "Source and target file name '${tgt}' are identic in line ${lnr}."
+ continue
+ fi
+
+ echo
+ perform_movie "${src}" "${tgt}" "${title}"
+
done
}