Skip to content

Commit

Permalink
use strict bash
Browse files Browse the repository at this point in the history
  • Loading branch information
andreineculau committed Dec 19, 2018
1 parent 4c011df commit 8e37456
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions transcrypt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail

#
# transcrypt - https://github.com/elasticdog/transcrypt
Expand Down Expand Up @@ -199,7 +200,7 @@ get_password() {
else
printf 'Password: '
read -r password
[[ ! $password ]] && printf 'no password was specified\n'
[[ $password ]] || printf 'no password was specified\n'
fi
done
}
Expand All @@ -209,7 +210,7 @@ confirm_configuration() {
local answer

printf '\nRepository metadata:\n\n'
[[ $REPO ]] && printf ' GIT_WORK_TREE: %s\n' "$REPO"
[[ ! $REPO ]] || printf ' GIT_WORK_TREE: %s\n' "$REPO"
printf ' GIT_DIR: %s\n' "$GIT_DIR"
printf ' GIT_ATTRIBUTES: %s\n\n' "$GIT_ATTRIBUTES"
printf 'The following configuration will be saved:\n\n'
Expand All @@ -232,7 +233,7 @@ confirm_rekey() {
local answer

printf '\nRepository metadata:\n\n'
[[ $REPO ]] && printf ' GIT_WORK_TREE: %s\n' "$REPO"
[[ ! $REPO ]] || printf ' GIT_WORK_TREE: %s\n' "$REPO"
printf ' GIT_DIR: %s\n' "$GIT_DIR"
printf ' GIT_ATTRIBUTES: %s\n\n' "$GIT_ATTRIBUTES"
printf 'The following configuration will be saved:\n\n'
Expand Down Expand Up @@ -267,7 +268,7 @@ stage_rekeyed_files() {

# save helper scripts under the repository's git directory
save_helper_scripts() {
[[ ! -d "${GIT_DIR}/crypt" ]] && mkdir "${GIT_DIR}/crypt"
mkdir -p "${GIT_DIR}/crypt"

# The `decryption -> encryption` process on an unchanged file must be
# deterministic for everything to work transparently. To do that, the same
Expand Down Expand Up @@ -362,7 +363,7 @@ display_configuration() {

printf 'The current repository was configured using transcrypt version %s\n' "$CONFIGURED"
printf 'and has the following configuration:\n\n'
[[ $REPO ]] && printf ' GIT_WORK_TREE: %s\n' "$REPO"
[[ ! $REPO ]] || printf ' GIT_WORK_TREE: %s\n' "$REPO"
printf ' GIT_DIR: %s\n' "$GIT_DIR"
printf ' GIT_ATTRIBUTES: %s\n\n' "$GIT_ATTRIBUTES"
printf ' CIPHER: %s\n' "$current_cipher"
Expand All @@ -373,15 +374,15 @@ display_configuration() {

# remove transcrypt-related settings from the repository's git config
clean_gitconfig() {
git config --remove-section transcrypt 2> /dev/null
git config --remove-section filter.crypt 2> /dev/null
git config --remove-section diff.crypt 2> /dev/null
git config --remove-section transcrypt 2> /dev/null || true
git config --remove-section filter.crypt 2> /dev/null || true
git config --remove-section diff.crypt 2> /dev/null || true
git config --unset merge.renormalize

# remove the merge section if it's now empty
local merge_values=$(git config --get-regex --local 'merge\..*')
if [[ ! $merge_values ]]; then
git config --remove-section merge 2> /dev/null
git config --remove-section merge 2> /dev/null || true
fi
}

Expand Down Expand Up @@ -454,9 +455,9 @@ uninstall_transcrypt() {

# remove helper scripts
for script in {clean,smudge,textconv}; do
[[ -f "${GIT_DIR}/crypt/${script}" ]] && rm "${GIT_DIR}/crypt/${script}"
[[ ! -f "${GIT_DIR}/crypt/${script}" ]] || rm "${GIT_DIR}/crypt/${script}"
done
[[ -d "${GIT_DIR}/crypt" ]] && rmdir "${GIT_DIR}/crypt"
[[ ! -d "${GIT_DIR}/crypt" ]] || rmdir "${GIT_DIR}/crypt"

# touch all encrypted files to prevent stale stat info
local encrypted_files=$(git ls-crypt)
Expand All @@ -471,7 +472,7 @@ uninstall_transcrypt() {
# remove the alias section if it's now empty
local alias_values=$(git config --get-regex --local 'alias\..*')
if [[ ! $alias_values ]]; then
git config --remove-section alias 2> /dev/null
git config --remove-section alias 2> /dev/null || true
fi

# remove any defined crypt patterns in gitattributes
Expand Down Expand Up @@ -535,7 +536,7 @@ export_gpg() {

local current_cipher=$(git config --get --local transcrypt.cipher)
local current_password=$(git config --get --local transcrypt.password)
[[ ! -d "${GIT_DIR}/crypt" ]] && mkdir "${GIT_DIR}/crypt"
mkdir -p "${GIT_DIR}/crypt"

local gpg_encrypt_cmd="gpg --batch --recipient $gpg_recipient --trust-model always --yes --armor --quiet --encrypt -"
printf 'password=%s\ncipher=%s\n' "$current_password" "$current_cipher" | $gpg_encrypt_cmd > "${GIT_DIR}/crypt/${gpg_recipient}.asc"
Expand Down

0 comments on commit 8e37456

Please sign in to comment.