Started moving code into functions and fixed color

b3bp doesn't recognize rxvt-unicode as color ready?
This commit is contained in:
2Shirt 2018-06-01 01:56:30 -06:00
parent 89e90f818a
commit 3ed53c6ece

View file

@ -2,8 +2,6 @@
# Script to backup git repo(s) to Backblaze B2
script_name="$(basename "${0}")"
# Usage
read -r -d '' __usage <<-'EOF' || true
Usage: backup-git-repos-to-b2 [options] repo(s)...
@ -17,14 +15,43 @@ Options:
-h --help This page.
EOF
# Help text
__helptext='NOTE: --temp-dir defaults to "$(mktemp -d)" if not specified.'
# Source BASH3 Boilerplate
source bash3boilerplate/main.sh
# Color fix for rxvt-unicode (tell b3bp we're xterm)
TERM="xterm"
# Functions
function clone_github_repo() {
repo="$(fix_repo_name "${1:-}")"
git clone --mirror --verbose \
"https://github.com/${github_account}/${repo}.git" \
"${repo}-${date}.git"
}
function find_b2_cmd() {
if which backblaze-b2 >/dev/null 2>&1; then
# Arch Linux uses this name
echo "backblaze-b2"
elif which b2 > /dev/null 2>&1; then
echo "b2"
else
__b3bp_log error "B2 command-line tool not found"
exit 1
fi
}
function fix_repository_name() {
# Remove '.git' from the name (if present)
repository="${1:-}"
if [[ "${repository: -4:4}" == ".git" ]]; then
repository="${repository:0: -4}"
fi
echo "${repository}"
}
b2_bucket="${arg_b}"
b2_cmd="b2"
b2_cmd="$(find_b2_cmd)"
b2_id="${arg_i}"
b2_key="${arg_k}"
date="$(date '+%F_%H%M%z')"
@ -34,35 +61,12 @@ if [[ "$temp_dir" == "" ]]; then
temp_dir="$(mktemp -d)"
fi
# Check for backblaze-b2
# Check for b2 cmd
if which backblaze-b2 >/dev/null 2>&1; then
# Arch Linux uses this name
b2_cmd="backblaze-b2"
elif ! which b2 > /dev/null 2>&1; then
echo "Error B2 command-line tool not found"
exit 1
fi
# Setup repository to ${1}
repository="${1}"
if [[ "${repository: -4:4}" == ".git" ]]; then
repository="${repository:0: -4}"
fi
# Create the backup directory
mkdir -p "${temp_dir}"
pushd "${temp_dir}" > /dev/null
echo "Backing up ${repository}"
git clone --mirror --verbose \
"https://github.com/${github_account}/${repository}.git" \
"${repository}-${date}.git"
if [ $? -ne 0 ]; then
echo "Error cloning ${repository}"
exit 1
fi
tar cpzf "${repository}-${date}.git.tgz" "${repository}-${date}.git"
if [ $? -ne 0 ]; then