You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
git-secret/src/main.sh

84 lines
1.7 KiB
Bash

#!/usr/bin/env bash
set -e
function _check_setup {
# Checking git and secret-plugin setup:
local is_tree
is_tree=$(_is_inside_git_tree)
if [[ "$is_tree" -ne 0 ]]; then
_abort "git cannot locate repo. Perhaps use 'git init'/'git clone', then 'git secret init'"
fi
# Checking if the '.gitsecret' dir (or as set by SECRETS_DIR) is not ignored:
_secrets_dir_is_not_ignored
# Checking gpg setup:
local keys_dir
keys_dir=$(_get_secrets_dir_keys)
local secring="$keys_dir/secring.gpg"
if [[ -f $secring ]] && [[ -s $secring ]]; then
# secring.gpg exists and is not empty,
# someone has imported a private key.
_abort 'it seems that someone has imported a secret key.'
fi
}
function _incorrect_usage {
local message="$1"
local exitcode="$2"
shift 2
echo "git-secret: abort: ${message}"
usage "$@"
exit "${exitcode}"
}
function _show_version {
echo "$GITSECRET_VERSION"
exit 0
}
function _init_script {
if [[ $# == 0 ]]; then
_incorrect_usage 'no input parameters provided.' 126 "$@"
fi
# Parse plugin-level options:
local dry_run=0
while [[ $# -gt 0 ]]; do
local opt="$1"
case "$opt" in
# Options for quick-exit strategy:
--dry-run)
dry_run=1
shift;;
--version) _show_version;;
*) break;; # do nothing
esac
done
if [[ "$dry_run" == 0 ]]; then
# Checking for proper set-up:
_check_setup
# Routing the input command:
local function_exists
function_exists=$(_function_exists "$1")
if [[ "$function_exists" == 0 ]] && [[ ! $1 == _* ]]; then
$1 "${@:2}"
else # TODO: elif [[ $(_plugin_exists $1) == 0 ]]; then
_incorrect_usage "command $1 not found." 126 "$@"
fi
fi
}
_init_script "$@"