Merge branch 'dev-0.2.6' into dev-0.3
This commit is contained in:
commit
2741e72574
14 changed files with 66 additions and 15 deletions
|
@ -43,3 +43,8 @@
|
||||||
### v0.2.5
|
### v0.2.5
|
||||||
* Fixed bug with command parser not parsing options correctly
|
* Fixed bug with command parser not parsing options correctly
|
||||||
* Fixed bug where deploy would fail with errors that didn't exist
|
* Fixed bug where deploy would fail with errors that didn't exist
|
||||||
|
|
||||||
|
### v0.2.6
|
||||||
|
* Added "all" condition to apply exclude or include to all database
|
||||||
|
* Fixed bug where disk usage calculator would ungracefully exit when database had no selected tracks
|
||||||
|
* Added REPO_ID field to database to make sure that the provided GIT directory is the right git repo
|
||||||
|
|
|
@ -5,6 +5,8 @@ Options
|
||||||
Defines path to git directory that contains the music collection. Defaults to current directory when not set.
|
Defines path to git directory that contains the music collection. Defaults to current directory when not set.
|
||||||
|
|
||||||
Commands
|
Commands
|
||||||
|
init [<options>] </path/to/target>
|
||||||
|
Initializes target with database file
|
||||||
update [<options>] </path/to/target>
|
update [<options>] </path/to/target>
|
||||||
Populates database present in target folder with new images.
|
Populates database present in target folder with new images.
|
||||||
deploy [<options>] </path/to/target>
|
deploy [<options>] </path/to/target>
|
||||||
|
|
|
@ -18,13 +18,14 @@ cmd_deploy() {
|
||||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||||
[[ ! -f "${DB_FILE}" ]] && return 3
|
[[ ! -f "${DB_FILE}" ]] && return 3
|
||||||
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
||||||
|
[[ "$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" != "$(awk 'BEGIN{FS="\t"}{if($1=="REPO_ID"){print $2}}' "${DB_FILE}")" ]] && return 2
|
||||||
|
|
||||||
if [[ -z "$(grep LAST_DEPLOY ${DB_FILE})" ]]; then
|
if [[ -z "$(grep LAST_DEPLOY ${DB_FILE})" ]]; then
|
||||||
echo -e "LAST_DEPLOY\t$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" >> ${DB_FILE}
|
echo -e "LAST_DEPLOY\t$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" >> ${DB_FILE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local NEW_COMMIT=$(git -C "${GIT_DIR}" rev-parse HEAD)
|
local NEW_COMMIT=$(git -C "${GIT_DIR}" rev-parse HEAD)
|
||||||
[[ -z "${OLD_COMMIT}" ]] && local OLD_COMMIT=$(awk 'BEGIN{FS="\t"}{if($1=="LAST_DEPLOY"){print $2}}' ${DB_FILE})
|
[[ -z "${OLD_COMMIT}" ]] && local OLD_COMMIT=$(awk 'BEGIN{FS="\t"}{if($1=="LAST_DEPLOY"){print $2}}' "${DB_FILE}")
|
||||||
local removableidList=($(awk 'BEGIN{FS="\t"}{if(($1=="null" || $1=="false") && $4!="null"){print $2"--"$3}}' "${DB_FILE}"))
|
local removableidList=($(awk 'BEGIN{FS="\t"}{if(($1=="null" || $1=="false") && $4!="null"){print $2"--"$3}}' "${DB_FILE}"))
|
||||||
local deployableidList=($(awk 'BEGIN{FS="\t"}{if($1=="true" && $4=="null"){print $2}}' "${DB_FILE}" | awk '!seen[$0]++'))
|
local deployableidList=($(awk 'BEGIN{FS="\t"}{if($1=="true" && $4=="null"){print $2}}' "${DB_FILE}" | awk '!seen[$0]++'))
|
||||||
local changedidList=($(sed 's/\(.*\)\..*/\1/' <<< $(git -C "${GIT_DIR}" diff --name-only ${NEW_COMMIT} ${OLD_COMMIT}) | awk '!seen[$0]++' | grep SHA256))
|
local changedidList=($(sed 's/\(.*\)\..*/\1/' <<< $(git -C "${GIT_DIR}" diff --name-only ${NEW_COMMIT} ${OLD_COMMIT}) | awk '!seen[$0]++' | grep SHA256))
|
||||||
|
|
|
@ -16,6 +16,7 @@ cmd_du() {
|
||||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||||
[[ ! -f "${DB_FILE}" ]] && return 3
|
[[ ! -f "${DB_FILE}" ]] && return 3
|
||||||
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
||||||
|
[[ "$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" != "$(awk 'BEGIN{FS="\t"}{if($1=="REPO_ID"){print $2}}' "${DB_FILE}")" ]] && return 2
|
||||||
|
|
||||||
local imageidList=($(awk 'BEGIN{FS="\t"}{if($1=="true"){print $2}}' ${DB_FILE} | awk '!seen[$0]++'))
|
local imageidList=($(awk 'BEGIN{FS="\t"}{if($1=="true"){print $2}}' ${DB_FILE} | awk '!seen[$0]++'))
|
||||||
local DU="$(print_imageid_du ${GIT_DIR} ${imageidList[@]})"
|
local DU="$(print_imageid_du ${GIT_DIR} ${imageidList[@]})"
|
||||||
|
|
|
@ -22,12 +22,13 @@ cmd_exclude() {
|
||||||
local conditionList=("${@}")
|
local conditionList=("${@}")
|
||||||
[[ ! -f "${DB_FILE}" ]] && return 3
|
[[ ! -f "${DB_FILE}" ]] && return 3
|
||||||
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
||||||
|
[[ "$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" != "$(awk 'BEGIN{FS="\t"}{if($1=="REPO_ID"){print $2}}' "${DB_FILE}")" ]] && return 2
|
||||||
|
|
||||||
for condition in ${conditionList[@]}; do
|
for condition in ${conditionList[@]}; do
|
||||||
_msg EXEC "Excluding all tracks that match the following condition: ${condition}"
|
_msg EXEC "Excluding all tracks that match the following condition: ${condition}"
|
||||||
local MATCHES=$(db_set ${GIT_DIR} ${DB_FILE} false "${condition}" 2>${STDERR} | wc -l )
|
local MATCHES=$(db_set ${GIT_DIR} ${DB_FILE} false "${condition}" 2>${STDERR} | wc -l )
|
||||||
_msg ECHO "${MATCHES} matches"
|
_msg ECHO "${MATCHES} matches"
|
||||||
[[ $? -ne 0 ]] && { _msg WARN 2; } || { _msg OK 2; }
|
[[ $? -ne 0 ]] && { _msg WARN 1; } || { _msg OK 1; }
|
||||||
done
|
done
|
||||||
local imageidList=($(awk 'BEGIN{FS="\t"}{if($1=="true"){print $2}}' ${DB_FILE} | awk '!seen[$0]++'))
|
local imageidList=($(awk 'BEGIN{FS="\t"}{if($1=="true"){print $2}}' ${DB_FILE} | awk '!seen[$0]++'))
|
||||||
local DU="$(print_imageid_du ${GIT_DIR} ${imageidList[@]})"
|
local DU="$(print_imageid_du ${GIT_DIR} ${imageidList[@]})"
|
||||||
|
|
|
@ -17,6 +17,7 @@ cmd_fsck() {
|
||||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||||
[[ ! -f "${DB_FILE}" ]] && return 3
|
[[ ! -f "${DB_FILE}" ]] && return 3
|
||||||
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
||||||
|
[[ "$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" != "$(awk 'BEGIN{FS="\t"}{if($1=="REPO_ID"){print $2}}' "${DB_FILE}")" ]] && return 2
|
||||||
|
|
||||||
for cmd in ${cmdList[@]}; do
|
for cmd in ${cmdList[@]}; do
|
||||||
case ${cmd} in
|
case ${cmd} in
|
||||||
|
|
|
@ -22,6 +22,7 @@ cmd_include() {
|
||||||
local conditionList=("${@}")
|
local conditionList=("${@}")
|
||||||
[[ ! -f "${DB_FILE}" ]] && return 3
|
[[ ! -f "${DB_FILE}" ]] && return 3
|
||||||
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
||||||
|
[[ "$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" != "$(awk 'BEGIN{FS="\t"}{if($1=="REPO_ID"){print $2}}' "${DB_FILE}")" ]] && return 2
|
||||||
|
|
||||||
for condition in ${conditionList[@]}; do
|
for condition in ${conditionList[@]}; do
|
||||||
_msg EXEC "Including all tracks that match the following condition: ${condition}"
|
_msg EXEC "Including all tracks that match the following condition: ${condition}"
|
||||||
|
|
24
src/cmd_init
Normal file
24
src/cmd_init
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# doc cmd_init {
|
||||||
|
#
|
||||||
|
# DESCRIPTION
|
||||||
|
# cmd_init - Initialized target directory with database file
|
||||||
|
#
|
||||||
|
# USAGE
|
||||||
|
# cmd_init </path/to/git/dir> </path/to/target>
|
||||||
|
#
|
||||||
|
# }
|
||||||
|
|
||||||
|
cmd_init() {
|
||||||
|
local GIT_DIR="${1}"
|
||||||
|
local TARGET="${2}"
|
||||||
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||||
|
|
||||||
|
[[ -f "${DB_FILE}" ]] && return 1
|
||||||
|
|
||||||
|
_msg EXEC "Initializing ${TARGET}"
|
||||||
|
echo -e "REPO_ID\t$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" > ${DB_FILE} 2>${STDERR}
|
||||||
|
[[ $? -ne 0 ]] && { _msg WARN; return 2; }
|
||||||
|
_msg OK
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ cmd_update() {
|
||||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||||
[[ ! -f "${DB_FILE}" ]] && return 3
|
[[ ! -f "${DB_FILE}" ]] && return 3
|
||||||
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
||||||
|
[[ "$(git -C "${GIT_DIR}" rev-list HEAD | tail -n 1)" != "$(awk 'BEGIN{FS="\t"}{if($1=="REPO_ID"){print $2}}' "${DB_FILE}")" ]] && return 2
|
||||||
|
|
||||||
# In the event that LAST_COMMIT OR DB_FILE does not exist, echo out that the LAST_COMMIT
|
# In the event that LAST_COMMIT OR DB_FILE does not exist, echo out that the LAST_COMMIT
|
||||||
# is the first COMMIT of GIT_DIR, thus stating that no database update has ever occured
|
# is the first COMMIT of GIT_DIR, thus stating that no database update has ever occured
|
||||||
|
|
|
@ -21,13 +21,19 @@ db_set() {
|
||||||
local SELECTED="${3}"; shift 3
|
local SELECTED="${3}"; shift 3
|
||||||
local CONDITION="${@}"
|
local CONDITION="${@}"
|
||||||
|
|
||||||
|
if [[ "${CONDITION}" == "all" ]]; then
|
||||||
|
gawk -i inplace -v selected=${SELECTED} 'BEGIN{FS="\t";OFS="\t";}{if($1!="LAST_DEPLOY" && $1!="LAST_UPDATE" && $1!="REPO_ID" && $1!="null"){$1=selected}{print $0}}' "${DB_FILE}"
|
||||||
|
cat "${DB_FILE}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Defines what imageids are imported into database, as we're only going to act on those
|
# Defines what imageids are imported into database, as we're only going to act on those
|
||||||
local FIELD="$(echo ${CONDITION} | cut -d'=' -f1 | tr '[:lower:]' '[:upper:]' )"
|
local FIELD="$(echo ${CONDITION} | cut -d'=' -f1 | tr '[:lower:]' '[:upper:]' )"
|
||||||
local VALUE="$(echo ${CONDITION} | cut -d'=' -f2 | tr '[:lower:]' '[:upper:]' )"
|
local VALUE="$(echo ${CONDITION} | cut -d'=' -f2 | tr '[:lower:]' '[:upper:]' )"
|
||||||
|
|
||||||
# Determines which IMAGEIDs present in the DB_FILE match the CONDITION
|
# Determines which IMAGEIDs present in the DB_FILE match the CONDITION
|
||||||
local COUNT=1
|
local COUNT=1
|
||||||
local dbimageidList=$(awk 'BEGIN{FS="\t"}{if($1!="LAST_DEPLOY" && $1!="LAST_UPDATE" && $1!="null"){print $2}}' ${DB_FILE} | awk '!seen[$0]++')
|
local dbimageidList=$(awk 'BEGIN{FS="\t"}{if($1!="LAST_DEPLOY" && $1!="LAST_UPDATE" && $1!="REPO_ID" && $1!="null"){print $2}}' ${DB_FILE} | awk '!seen[$0]++')
|
||||||
for dbimageid in ${dbimageidList[@]}; do
|
for dbimageid in ${dbimageidList[@]}; do
|
||||||
local MTAG="$(printf "${GIT_DIR}/%s.tags" ${dbimageid})"
|
local MTAG="$(printf "${GIT_DIR}/%s.tags" ${dbimageid})"
|
||||||
local MATCH="$(grep -i -l "\"${FIELD}\" : \"${VALUE}\"" "${MTAG}")"
|
local MATCH="$(grep -i -l "\"${FIELD}\" : \"${VALUE}\"" "${MTAG}")"
|
||||||
|
|
|
@ -24,7 +24,7 @@ db_update() {
|
||||||
fi
|
fi
|
||||||
for trackid in ${trackidList[@]}; do
|
for trackid in ${trackidList[@]}; do
|
||||||
if [[ -z $(awk -v imageid="${IMAGEID}" -v trackid="${trackid}" 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $0}}' ${DB_FILE}) ]]; then
|
if [[ -z $(awk -v imageid="${IMAGEID}" -v trackid="${trackid}" 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $0}}' ${DB_FILE}) ]]; then
|
||||||
echo -e "true\t${IMAGEID}\t${trackid}\tnull" >> ${DB_FILE}
|
echo -e "false\t${IMAGEID}\t${trackid}\tnull" >> ${DB_FILE}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -32,7 +32,7 @@ deploy_meta() {
|
||||||
if [[ "${PRESENT_META}" != "${FUTURE_META}" ]]; then
|
if [[ "${PRESENT_META}" != "${FUTURE_META}" ]]; then
|
||||||
_msg ECHO "${trackid} has differing metadata. Updating"
|
_msg ECHO "${trackid} has differing metadata. Updating"
|
||||||
[[ "${PRESENT_PATH}" == "null" ]] || metaflac --remove-all "${TARGET}/${PRESENT_PATH}"
|
[[ "${PRESENT_PATH}" == "null" ]] || metaflac --remove-all "${TARGET}/${PRESENT_PATH}"
|
||||||
sed s'/;/\n/' <<< ${FUTURE_META} | metaflac --import-tags-from=- --import-picture-from="${GIT_DIR}/${IMAGEID}.jpg" "${TARGET}/${PRESENT_PATH}"
|
tr ';' \\n <<< ${FUTURE_META} | metaflac --import-tags-from=- --import-picture-from="${GIT_DIR}/${IMAGEID}.jpg" "${TARGET}/${PRESENT_PATH}"
|
||||||
[[ $? -eq 0 ]] || local ERR=true
|
[[ $? -eq 0 ]] || local ERR=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ while true; do
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
--git-dir)
|
--git-dir)
|
||||||
shift
|
shift
|
||||||
GIT_DIR="${1}"
|
GIT_DIR="${1}"
|
||||||
|
@ -39,6 +38,14 @@ done
|
||||||
|
|
||||||
|
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
|
init)
|
||||||
|
shift
|
||||||
|
cmd_init "${GIT_DIR}" ${@}
|
||||||
|
EXIT=$?
|
||||||
|
[[ ${EXIT} -eq 1 ]] && echo "Database file already present"
|
||||||
|
[[ ${EXIT} -eq 2 ]] && echo "Init had errors"
|
||||||
|
;;
|
||||||
|
|
||||||
exclude)
|
exclude)
|
||||||
shift
|
shift
|
||||||
cmd_exclude "${GIT_DIR}" ${@}
|
cmd_exclude "${GIT_DIR}" ${@}
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
print_imageid_du() {
|
print_imageid_du() {
|
||||||
local GIT_DIR="${1}"; shift
|
local GIT_DIR="${1}"; shift
|
||||||
local imageidList=(${@})
|
local imageidList=(${@})
|
||||||
[[ -z "${imageidList[@]}" ]] && echo 0
|
[[ -z "${imageidList[@]}" ]] && { echo 0; return 0; }
|
||||||
local bytesList=($(awk 'BEGIN{RS=",";FS=":"}{if($1=="\"size\""){print $2}}' <<<$(git -C "${GIT_DIR}" annex info --bytes --json $(printf "%s.flac\t" ${imageidList[@]}))))
|
local bytesList=($(awk 'BEGIN{RS=",";FS=":"}{if($1=="\"size\""){print $2}}' <<<$(git -C "${GIT_DIR}" annex info --bytes --json $(printf "%s.flac\t" ${imageidList[@]}))))
|
||||||
|
[[ -z "${bytesList[@]}" ]] && { echo 0; return 0; }
|
||||||
dc <<< '[+]sa[z2!>az2!>b]sb'"$(sed 's/"//g' <<< "${bytesList[@]}")lbxp"
|
dc <<< '[+]sa[z2!>az2!>b]sb'"$(sed 's/"//g' <<< "${bytesList[@]}")lbxp"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue