#!/bin/bash ### # Parses arguments and commands from shell ### GIT_DIR="./" #Recursive argument parser while true; do case ${1} in --help) shift HELP="${1}" [[ -z "${HELP}" ]] && HELP=general eval help_${HELP} exit ;; --info) help_info exit ;; --git-dir) shift GIT_DIR="${1}" ;; *) break ;; esac shift done 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" ;; import) shift case "${1}" in tracks) shift cmd_import_tracks "${GIT_DIR}" ${@} ;; images) shift cmd_import_images "${GIT_DIR}" ${@} ;; *) echo "${1} not a valid command" ;; esac ;; exclude) shift cmd_exclude "${GIT_DIR}" ${@} EXIT=$? [[ ${EXIT} -eq 3 ]] && echo "Database file non-existent" [[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository" ;; include) shift cmd_include "${GIT_DIR}" ${@} EXIT=$? [[ ${EXIT} -eq 3 ]] && echo "Database file non-existent" [[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository" ;; export) shift while [[ -n "${1}" ]]; do case ${1} in --from) shift OLD_COMMIT=${1} shift ;; *) TARGET="${1}" shift ;; esac done cmd_export "${GIT_DIR}" "${TARGET}" "${OLD_COMMIT}" EXIT=$? [[ ${EXIT} -eq 0 ]] && echo "Deployment completed successfully" [[ ${EXIT} -eq 1 ]] && echo "Deployment completed with errors" [[ ${EXIT} -eq 3 ]] && echo "Database file non-existent" [[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository" ;; update) shift while [[ -n "${1}" ]]; do case ${1} in --from) shift OLD_COMMIT=${1} shift ;; *) TARGET="${1}" shift ;; esac done cmd_update "${GIT_DIR}" "${TARGET}" "${OLD_COMMIT}" EXIT=$? [[ ${EXIT} -eq 0 ]] && echo "Update completed successfully" [[ ${EXIT} -eq 1 ]] && echo "Update completed with errors" [[ ${EXIT} -eq 3 ]] && echo "Database file non-existent" [[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository" ;; du) shift cmd_du "${GIT_DIR}" "${@}" EXIT=$? [[ ${EXIT} -eq 3 ]] && echo "Database file non-existent" [[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository" ;; fsck) shift while [[ -n "${1}" ]]; do case ${1} in --nonexistent-ids) cmdList=(${cmdList[@]} nonexistent-ids) shift ;; --deployed-ids) cmdList=(${cmdList[@]} deployed-ids) shift ;; --metadata) cmdList=(${cmdList[@]} metadata) shift ;; *) TARGET="${1}" shift ;; esac done [[ -z ${cmdList[@]} ]] && cmdList=(deployed-ids nonexistent-ids metadata) cmd_fsck "${GIT_DIR}" "${TARGET}" ${cmdList[@]} EXIT=$? [[ ${EXIT} -eq 3 ]] && echo "Database file non-existent" [[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository" ;; *) help_general ;; esac