[parser] Added --git-dir option. Otherwise, GIT_DIR is defined as the current working directory
[cmd_deploy] [cmd_du] [cmd_exclude] [cmd_fsck] [cmd_include] [cmd_update] Added checks to ensure DB_FILE and GIT_DIR exist
This commit is contained in:
parent
81a132c1e4
commit
dc6464ab54
7 changed files with 67 additions and 12 deletions
|
@ -16,6 +16,7 @@ cmd_deploy() {
|
||||||
local ERR=false
|
local ERR=false
|
||||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||||
[[ ! -f "${DB_FILE}" ]] && return 1
|
[[ ! -f "${DB_FILE}" ]] && return 1
|
||||||
|
[[ ! -f "${GIT_DIR}/.git" ]] && 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}
|
||||||
|
|
|
@ -14,7 +14,9 @@ cmd_du() {
|
||||||
local GIT_DIR="${1}"
|
local GIT_DIR="${1}"
|
||||||
local TARGET="${2}"
|
local TARGET="${2}"
|
||||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||||
|
[[ ! -f "${DB_FILE}" ]] && return 1
|
||||||
|
[[ ! -f "${GIT_DIR}/.git" ]] && 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[@]})"
|
||||||
_msg ECHO "Current estimated disk usage: ${DU} bytes"
|
_msg ECHO "Current estimated disk usage: ${DU} bytes"
|
||||||
|
|
|
@ -20,7 +20,8 @@ cmd_exclude() {
|
||||||
local TARGET="${2}"
|
local TARGET="${2}"
|
||||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"; shift 2
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"; shift 2
|
||||||
local conditionList=("${@}")
|
local conditionList=("${@}")
|
||||||
echo ${conditionList[@]}
|
[[ ! -f "${DB_FILE}" ]] && return 1
|
||||||
|
[[ ! -f "${GIT_DIR}/.git" ]] && 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}"
|
||||||
|
|
|
@ -14,6 +14,8 @@ cmd_fsck() {
|
||||||
local GIT_DIR="${1}"
|
local GIT_DIR="${1}"
|
||||||
local TARGET="${2}"
|
local TARGET="${2}"
|
||||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||||
|
[[ ! -f "${DB_FILE}" ]] && return 1
|
||||||
|
[[ ! -f "${GIT_DIR}/.git" ]] && return 2
|
||||||
|
|
||||||
chk_deployed_ids "${TARGET}" "${DB_FILE}"
|
chk_deployed_ids "${TARGET}" "${DB_FILE}"
|
||||||
chk_nonexistent_ids "${TARGET}" "${DB_FILE}"
|
chk_nonexistent_ids "${TARGET}" "${DB_FILE}"
|
||||||
|
|
|
@ -20,6 +20,8 @@ cmd_include() {
|
||||||
local TARGET="${2}"
|
local TARGET="${2}"
|
||||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"; shift 2
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"; shift 2
|
||||||
local conditionList=("${@}")
|
local conditionList=("${@}")
|
||||||
|
[[ ! -f "${DB_FILE}" ]] && return 1
|
||||||
|
[[ ! -f "${GIT_DIR}/.git" ]] && 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}"
|
||||||
|
|
|
@ -14,6 +14,8 @@ cmd_update() {
|
||||||
local GIT_DIR="${1}"
|
local GIT_DIR="${1}"
|
||||||
local TARGET="${2}"
|
local TARGET="${2}"
|
||||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||||
|
[[ ! -f "${DB_FILE}" ]] && return 1
|
||||||
|
[[ ! -f "${GIT_DIR}/.git" ]] && 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
|
||||||
|
|
65
src/parser
65
src/parser
|
@ -4,35 +4,80 @@
|
||||||
# Parses arguments and commands from shell
|
# Parses arguments and commands from shell
|
||||||
###
|
###
|
||||||
|
|
||||||
|
GIT_DIR="./"
|
||||||
|
|
||||||
|
#Recursive argument parser
|
||||||
|
while true; do
|
||||||
|
case ${1} in
|
||||||
|
--help)
|
||||||
|
help
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
|
||||||
|
--info)
|
||||||
|
help info
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
|
||||||
|
|
||||||
|
--git-dir=*)
|
||||||
|
if [ -z "${1#*=}" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
log ECHO "--git-dir called. Git directory now defined as: ${1#*=}"
|
||||||
|
GIT_DIR="${1#*=}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
exclude)
|
exclude)
|
||||||
shift
|
shift
|
||||||
cmd_exclude ${@}
|
cmd_exclude "${GIT_DIR}" ${@}
|
||||||
|
[[ $? -eq 1 ]] && echo "Database file non-existent"
|
||||||
|
[[ $? -eq 2 ]] && echo "Git directory not a valid git repository"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
include)
|
include)
|
||||||
shift
|
shift
|
||||||
cmd_include ${@}
|
cmd_include$ "${GIT_DIR}" ${@}
|
||||||
;;
|
[[ $? -eq 1 ]] && echo "Database file non-existent"
|
||||||
|
[[ $? -eq 2 ]] && echo "Git directory not a valid git repository"
|
||||||
|
;;
|
||||||
|
|
||||||
deploy)
|
deploy)
|
||||||
shift
|
shift
|
||||||
cmd_deploy ${@}
|
cmd_deploy "${GIT_DIR}" ${@}
|
||||||
;;
|
[[ $? -eq 1 ]] && echo "Database file non-existent"
|
||||||
|
[[ $? -eq 2 ]] && echo "Git directory not a valid git repository"
|
||||||
|
;;
|
||||||
|
|
||||||
update)
|
update)
|
||||||
shift
|
shift
|
||||||
cmd_update ${@}
|
cmd_update "${GIT_DIR}" ${@}
|
||||||
;;
|
[[ $? -eq 1 ]] && echo "Database file non-existent"
|
||||||
|
[[ $? -eq 2 ]] && echo "Git directory not a valid git repository"
|
||||||
|
;;
|
||||||
|
|
||||||
du)
|
du)
|
||||||
shift
|
shift
|
||||||
cmd_du "${@}"
|
cmd_du "${GIT_DIR}" "${@}"
|
||||||
;;
|
[[ $? -eq 1 ]] && echo "Database file non-existent"
|
||||||
|
[[ $? -eq 2 ]] && echo "Git directory not a valid git repository"
|
||||||
|
;;
|
||||||
|
|
||||||
fsck)
|
fsck)
|
||||||
shift
|
shift
|
||||||
cmd_fsck "${@}"
|
cmd_fsck "${GIT_DIR}" "${@}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue