|
| 1 | +#!/usr/bin/env bash |
| 2 | +### @File : git-build.sh |
| 3 | +### @Author : Luke Penrod - support@deepinthought.io |
| 4 | +### @Company : DeepInThought |
| 5 | +### @Link : https://deepinthought.io |
| 6 | +### @Date : Saturday,September 29 2018 11:26:22 |
| 7 | +###- |
| 8 | + |
| 9 | +echo -e "\\033[0;32mDeploying updates to GitHub...\\033[0m" |
| 10 | +export ROOT_PATH="${HOME}/Documents" |
| 11 | +export GIT_LOCAL_PATH="${ROOT_PATH}/vscode-shell-snippets" |
| 12 | +export GIT_REPOSITORY="https://github.com/DeepInThought/vscode-shell-snippets.git" |
| 13 | +export GIT_RAW_TEST="https://raw.githubusercontent.com/DeepInThought/vscode-shell-snippets/master/README.md" |
| 14 | +export GIT_COMMIT_MSG= |
| 15 | + |
| 16 | +__username="$(whoami)" |
| 17 | +__dir="$(cd "$(dirname "${HOME}"/"${__username}")" && pwd)" |
| 18 | +__file="${__dir}/$(basename "${BASH_SOURCE[0]}")" |
| 19 | +__base="$(basename "${__file}" .sh)" |
| 20 | +__with_extension="${__base}.sh" |
| 21 | + |
| 22 | +# todo: create a functions file. |
| 23 | +handle_exit_code() { |
| 24 | + ERROR_CODE="$?" |
| 25 | + if [ "${ERROR_CODE}" = "0" ]; then |
| 26 | + printf -- '\033[32m SUCCESS: %s \033[0m\n' "${deepMsg:-${__with_extension}}"; |
| 27 | + printf -- '\033[32m Finished without errors. \033[0m\n' |
| 28 | + printf -- '\033[32m Exiting with status code 0.\033[0m\n'; |
| 29 | + exit ${ERROR_CODE} |
| 30 | + fi |
| 31 | + # ... |
| 32 | + if [ "${ERROR_CODE}" != "0" ]; then |
| 33 | + printf -- 'Exiting with status code 2.\n' |
| 34 | + exit ${ERROR_CODE} |
| 35 | + fi |
| 36 | + printf -- "an error occurred. cleaning up now... " |
| 37 | + # ... cleanup code ... |
| 38 | + printf -- "DONE.\\nExiting with error code %s.\\n", "${ERROR_CODE}" |
| 39 | + exit "${ERROR_CODE}" |
| 40 | +} |
| 41 | +trap "handle_exit_code" EXIT |
| 42 | + |
| 43 | +if [ $# -eq 1 ]; then |
| 44 | + "${GIT_COMMIT_MSG}"="$1" |
| 45 | + ${GIT_REPOSITORY:-'https://github.com/DeepInThought/vscode-shell-snippets.git'} |
| 46 | + echo "[Git Comment]: ${GIT-COMMIT}" |
| 47 | + echo "[Git Repository]: ${GIT_REPOSITORY}" |
| 48 | + if [ -d "${GIT_RAW_TEST}" ]; then |
| 49 | + echo "[Testing]: ${GIT_RAW_TEST} exists." |
| 50 | + curl "${GIT_RAW_TEST}" && echo |
| 51 | + sleep 1 |
| 52 | + else |
| 53 | + echo "[GIT_RAW_TEST]: Not Setup! ${GIT_RAW_TEST}" |
| 54 | + git clone "${ROOT_PATH}/${GIT_REPOSITORY}" |
| 55 | + sleep 1 |
| 56 | + fi |
| 57 | + echo "[Git Comment]: ${GIT-COMMIT}" |
| 58 | + echo "Commit on: $(date --rfc-3339=seconds)" |
| 59 | + git commit -m ${GIT_COMMIT_MSG} || printf -- '\033[31m ERROR: git commit -m ${GIT_COMMIT_MSG} failed! \033[0m\n' && exit 1 |
| 60 | + printf -- '\033[32m Finished without errors. \033[0m\n' |
| 61 | +else |
| 62 | + echo "Commit on: $(date --rfc-3339=seconds)" && echo "${GIT_COMMIT_MSG}" |
| 63 | +fi |
| 64 | + |
| 65 | +cd "${GIT_LOCAL_PATH}" || exit 2 |
| 66 | +# Add changes to git. |
| 67 | +git add . |
| 68 | + |
| 69 | +# Commit changes. |
| 70 | +msg="rebuilding site $(date) $theme_name" |
| 71 | +if [ $# -eq 2 ]; then |
| 72 | + msg="$2" |
| 73 | +fi |
| 74 | +git commit -m "$msg" |
| 75 | + |
| 76 | +# Push source and build repos. |
| 77 | +git push origin master |
| 78 | + |
| 79 | +# Come Back up to the Project Root |
| 80 | +cd .. |
0 commit comments