Big doc update plus refined tools to work better outside of StackExchange.

This commit is contained in:
tlimoncelli@stackexchange.com
2014-08-13 15:16:35 -04:00
parent a9d0b830e1
commit 8a14c28510
7 changed files with 285 additions and 32 deletions

View File

@@ -12,14 +12,16 @@ PUBRING="${KEYRINGDIR}/pubring.gpg"
# Exit with error if the environment is not right.
function fail_if_bad_environment() {
# Current checked:
# Are we in the base directory.
# Nothing.
# Are we in the base directory.
if [[ ! $(pwd) =~ \/puppet$ ]]; then
echo 'ERROR: Please run this script from the base directory.'
echo 'Exiting...'
exit 1
fi
:
## Are we in the base directory.
#if [[ ! $(pwd) =~ \/puppet$ ]]; then
# echo 'ERROR: Please run this script from the base directory.'
# echo 'Exiting...'
# exit 1
#fi
}
# Exit with error if a file exists.
@@ -180,9 +182,13 @@ function enumerate_subdirs() {
# Are we in git, hg, or other repo?
function which_vcs() {
if [[ -d .git || git rev-parse --git-dir > /dev/null 2>&1 ]]; then
if [[ -d .git ]]; then
echo git
elif [[ -d .hg || hg status >/dev/null 2>&1 ]]; then
elif [[ -d .hg ]]; then
echo hg
elif git rev-parse --git-dir > /dev/null 2>&1 ; then
echo git
elif hg status >/dev/null 2>&1 ; then
echo hg
else
echo other
@@ -217,3 +223,19 @@ function is_in_git() {
echo false
fi
}
# Remove file from repo, even if it was deleted locally already.
# If it doesn't exist yet in the repo, it should be a no-op.
function rm_from_vcs() {
rm_from_$(which_vcs) """$@"""
}
# rm from mercurial.
function rm_from_hg() {
hg rm -A """$@"""
}
# rm from git.
function rm_from_git() {
git rm --ignore-unmatch -f -- """$@"""
}

View File

@@ -4,7 +4,7 @@
# blackbox_edit_end.sh -- Re-encrypt file after edits.
#
source bin/blackbox_common.sh
source blackbox_common.sh
set -e
fail_if_bad_environment

View File

@@ -4,7 +4,7 @@
# blackbox_edit_start.sh -- Decrypt a file for editing.
#
source bin/blackbox_common.sh
source blackbox_common.sh
set -e
fail_if_bad_environment

View File

@@ -8,7 +8,7 @@
# to the puppet masters, it will be decrypted. The puppet masters
# refer to the unencrypted filename.
source bin/blackbox_common.sh
source blackbox_common.sh
set -e
fail_if_bad_environment
@@ -34,20 +34,24 @@ add_filename_to_cryptlist "$unencrypted_file"
# for HG vs. GIT use and DTRT depending.
# Is the unencrypted file already in HG? (ie. are we correcting a bad situation)
SECRETSEXPOSED=$(is_in_hg ${unencrypted_file})
SECRETSEXPOSED=$(is_in_vcs ${unencrypted_file})
echo "========== CREATED: ${encrypted_file}"
echo "========== UPDATING HG:"
echo "========== UPDATING REPO:"
shred_file "$unencrypted_file"
# NOTE(tlim): Because we use $VCSCMD, we can only use commands that
# work for both git and hg.
VCSCMD=$(which_vcs)
if $SECRETSEXPOSED ; then
hg rm -A "$unencrypted_file"
hg add "$encrypted_file"
rm_from_vcs "$unencrypted_file"
$VCSCMD add "$encrypted_file"
COMMIT_FILES="$BB_FILES $encrypted_file $unencrypted_file"
else
COMMIT_FILES="$BB_FILES $encrypted_file"
fi
echo 'NOTE: "already tracked!" messages are safe to ignore.'
hg add $BB_FILES $encrypted_file
hg commit -m"registered in blackbox: ${unencrypted_file}" $COMMIT_FILES
$VCSCMD add $BB_FILES $encrypted_file
$VCSCMD commit -m"registered in blackbox: ${unencrypted_file}" $COMMIT_FILES
echo "========== UPDATING HG: DONE"
echo "Local repo updated. Please push when ready."
echo " hg push"
echo " $VCSCMD push"

View File

@@ -1,10 +1,10 @@
#!/bin/bash
#!/usr/bin/env bash
#
# blackbox_edit_end.sh -- Re-encrypt file after edits.
#
source bin/blackbox_common.sh
source blackbox_common.sh
set -e
fail_if_bad_environment

View File

@@ -4,7 +4,7 @@
# blackbox_edit_start.sh -- Decrypt a file for editing.
#
source bin/blackbox_common.sh
source blackbox_common.sh
fail_if_bad_environment