|
|
@@ -11,6 +11,7 @@ BORG_SHA256=8dd6c2769d9bf3ca7a65ebf6781302029fc3b15105aff63d33195c007f897360 |
|
|
|
|
|
|
|
# Main dir is where this repo was checked out |
|
|
|
BORG_DIR="$(realpath "$(dirname "$0")")" |
|
|
|
cd "${BORG_DIR}" |
|
|
|
|
|
|
|
# This is named with uppercase so that it doesn't tab-complete for |
|
|
|
# "./b<tab>", which should give us "./borg.sh" |
|
|
@@ -29,14 +30,14 @@ trap 'error_handler ${BASH_SOURCE} ${LINENO} $?' ERR |
|
|
|
set -o errexit |
|
|
|
set -o errtrace |
|
|
|
|
|
|
|
if [ -e "$BORG_DIR/.setup-complete" ]; then |
|
|
|
if [ -e ".setup-complete" ]; then |
|
|
|
echo "Error: BORG_DIR $BORG_DIR was already set up; giving up." |
|
|
|
echo "Use \"git clean\" to return it to original state if desired" |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
# Make a temp dir to work in |
|
|
|
TMP=$(mktemp -d --tmpdir="$BORG_DIR") |
|
|
|
TMP=$(mktemp -d) |
|
|
|
|
|
|
|
# Install some cleanup handlers |
|
|
|
cleanup() |
|
|
@@ -71,7 +72,8 @@ error() { msg 31 "Error:" "$@" ; exit 1 ; } |
|
|
|
# Create pip environment |
|
|
|
setup_venv() |
|
|
|
{ |
|
|
|
( cd "${BORG_DIR}" && mkdir .venv && pipenv install ) |
|
|
|
mkdir .venv |
|
|
|
pipenv install |
|
|
|
} |
|
|
|
|
|
|
|
# Install borg |
|
|
@@ -127,8 +129,8 @@ generate_keys() |
|
|
|
{ |
|
|
|
PASS_SSH=$(print_random_key) |
|
|
|
PASS_REPOKEY=$(print_random_key) |
|
|
|
echo "$PASS_REPOKEY" > "${BORG_DIR}/passphrase" |
|
|
|
chmod 600 "${BORG_DIR}/passphrase" |
|
|
|
echo "$PASS_REPOKEY" > passphrase |
|
|
|
chmod 600 passphrase |
|
|
|
} |
|
|
|
|
|
|
|
# Run a command on the remote host over an existing SSH tunnel |
|
|
@@ -217,9 +219,9 @@ create_repo() |
|
|
|
export_keys() |
|
|
|
{ |
|
|
|
log "Exporting keys" |
|
|
|
$BORG key export --paper '' "${BORG_DIR}/key.txt" |
|
|
|
chmod 600 "${BORG_DIR}/key.txt" |
|
|
|
cat >>"${BORG_DIR}/key.txt" <<EOF |
|
|
|
$BORG key export --paper '' key.txt |
|
|
|
chmod 600 key.txt |
|
|
|
cat >>key.txt <<EOF |
|
|
|
|
|
|
|
Repository: ${BORG_REPO} |
|
|
|
Passphrase: ${PASS_REPOKEY} |
|
|
@@ -292,7 +294,7 @@ update_readme() |
|
|
|
-e "s!\${BACKUP_USER}!${BACKUP_USER}!g" \ |
|
|
|
-e "s!\${BACKUP_HOST}!${BACKUP_HOST}!g" \ |
|
|
|
-e "s!\${BACKUP_REPO}!${BACKUP_REPO}!g" \ |
|
|
|
"${BORG_DIR}/README.md" |
|
|
|
README.md |
|
|
|
} |
|
|
|
|
|
|
|
git_setup() |
|
|
|