Skip to content

Commit

Permalink
Merge pull request #20 from plyint/help
Browse files Browse the repository at this point in the history
Fix broken help command on macOS and fallback to less when man is not…
  • Loading branch information
ahnick authored Jul 8, 2020
2 parents 589bcb5 + 04404ea commit 486a8f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
33 changes: 28 additions & 5 deletions encpass.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
################################################################################

ENCPASS_VERSION="v4.1.2"
ENCPASS_VERSION="v4.1.3"

encpass_checks() {
[ -n "$ENCPASS_CHECKS" ] && return
Expand Down Expand Up @@ -281,6 +281,25 @@ encpass_save_err() {
fi
}

encpass_remove_man_format() {
sed -r 's/\.TH//g; s/\.\\//g; s/\.RS//g; s/\.RE//g; s/\\fB//g; s/\\fR//g; s/\\fI//g; s/\\-/-/g; s/^ //g; s/.{80}/\0\n/g' | grep -v '^"' | grep -v '^man' | sed 's/^/ /g; s/ \.SH//g'
}

encpass_help_prog() {
if [ ! -z "$(command -v man)" ]; then
if [ "$(man -l 2>&1 | grep 'invalid' | awk '{print $2}')" = "invalid" ]; then
# man exists, but no -l option is available (e.g macOS)
# let's attempt to emulate what man does
{ /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | /usr/bin/less -is; }
else
man -l -
fi
else
# No man, strip formatting and fallback to less
encpass_remove_man_format | less
fi
}

encpass_help() {

# Descriptions for commands that will be displayed in the help
Expand Down Expand Up @@ -324,7 +343,7 @@ You can determine if your version of encpass.sh is identical to a specific commi
encpass_"${ENCPASS_EXTENSION}"_help_commands
fi

man -l - << EOF
encpass_help_prog << EOF
.\" Manpage for encpass.sh.
.\" Email contact@plyint.com to correct errors or typos.
.TH man 8 "06 March 2020" "1.0" "encpass.sh man page"
Expand All @@ -343,10 +362,11 @@ Include in shell scripts and call the \fBget_secret\fR function:
Or invoke/manage from the command line:
\fBencpass.sh\fR [ COMMAND ] [ OPTIONS ]... [ ARGS ]...
.SH DESCRIPTION
A lightweight solution for using encrypted passwords in shell scripts. It allows a user to encrypt a password (or any other secret) at runtime and then use it, decrypted, within a script. This prevents shoulder surfing passwords and avoids storing the password in plain text, within a script, which could inadvertently be sent to or discovered by an individual at a later date.
A lightweight solution for using encrypted passwords in shell scripts. It allows a user to encrypt a password (or any other secret) at runtime and then use it, decrypted, within a script. This prevents shoulder surfing passwords and avoids storing the password in plain text, within a script, which could inadvertently be sent to or discovered by an individual at a later date.
This script generates an AES 256 bit symmetric key for each script (or user-defined bucket) that stores secrets. This key will then be used to encrypt all secrets for that script or bucket.
This script generates an AES 256 bit symmetric key for each script (or user-defined bucket) that stores secrets. This key will then be used to encrypt all secrets for that script or bucket.
Subsequent calls to retrieve a secret will not prompt for the value of that secret to be entered as the file with the encrypted value already exists.
Expand All @@ -365,6 +385,7 @@ To use the encpass.sh script within a shell script, source the script and then c
password=\$(get_secret)\fR
Note: When no arguments are passed to the get_secret function, then the bucket name is set to the name of the script and the secret name is set to "password".
- bucket name = <script name>
- secret name = "password"
Expand Down Expand Up @@ -459,7 +480,9 @@ $ENCPASS_HELP_VERSION_CMD_DESC
Display this help manual.
.RE
Note: Wildcard handling is implemented for all commands that take secret and bucket names as arguments. This enables performing operations like adding/removing a secret to/from multiple buckets at once.
Note: Wildcard handling is implemented for all commands that take secret
and bucket names as arguments. This enables performing operations like
adding/removing a secret to/from multiple buckets at once.
${ENCPASS_EXT_HELP_COMMANDS}
Expand Down
36 changes: 10 additions & 26 deletions extensions/keybase/encpass-keybase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ EOF
}

encpass_keybase_cmd_version() {
ENCPASS_KEYBASE_PATH="$(command -v encpass-$ENCPASS_EXTENSION.sh)"
[ -x "$(command -v sha256sum)" ] && printf "SHA256 Checksum: %s\n" "$(sha256sum $ENCPASS_KEYBASE_PATH)"
ENCPASS_KEYBASE_PATH="$(command -v encpass-"$ENCPASS_EXTENSION".sh)"
[ -x "$(command -v sha256sum)" ] && printf "SHA256 Checksum: %s\n" "$(sha256sum "$ENCPASS_KEYBASE_PATH")"
}

encpass_keybase_help_commands() {
Expand All @@ -148,58 +148,42 @@ ENCPASS_EXT_HELP_COMMANDS=$(cat << EOF
.SH EXTENSION COMMANDS
\fBcreate-repo\fR \fIteam/user\fR \fIrepository\fR
.RS
Creates a remote repo in Keybase for the Keybase team/user
with the specified repository name.
Creates a remote repo in Keybase for the Keybase team/user with the specified repository name.
The Keybase repo will be created with the following format:
\fIteam/user\fR/\fIrepository\fR.encpass
.RE
\fBdelete-repo\fR \fIteam/user\fR \fIrepository\fR
.RS
Deletes the remote encpass.sh repo in Keybase for the specified
team/user and repo.
Deletes the remote encpass.sh repo in Keybase for the specified team/user and repo.
.RE
\fBclone-repo\fR \fIteam/user\fR \fIrepository\fR
.RS
Clones the encpass.sh repo in Keybase to the ENCPASS_HOME_DIR folder using Git.
Secrets will be stored under the local ENCPASS_HOME_DIR/secrets folder. The bucket
name that will be created will be \fIteam/user\fR~\fIrepository\R.
Clones the encpass.sh repo in Keybase to the ENCPASS_HOME_DIR folder using Git. Secrets will be stored under the local ENCPASS_HOME_DIR/secrets folder. The bucket name that will be created will be \fIteam/user\fR~\fIrepository\R.
.RE
\fBlist-repos\fR
.RS
Lists all the encpass.sh repositories in Keybase that can be cloned. It assumes that all
repos ending in ".encpass" are encpass.sh repositories.
Lists all the encpass.sh repositories in Keybase that can be cloned. It assumes that all repos ending in ".encpass" are encpass.sh repositories.
.RE
\fBrefresh\fR
.RS
Runs a "git pull --rebase" for all encpass.sh secrets for the ENCPASS_HOME_DIR
that is currently set. It is possible if the secrets held on the remote Keybase
repo have been updated, WHILE you were making updates on your local that there
could be conflicts that result. In that case you will need to change to the
local directory containing your modified secrets and then use git as you
normally would to stash your changes. Once your changes are stashed, run a
refresh and then unstash your changes and resolve the conflicts.
Runs a "git pull --rebase" for all encpass.sh secrets for the ENCPASS_HOME_DIR that is currently set. It is possible if the secrets held on the remote Keybase repo have been updated, WHILE you were making updates on your local that there could be conflicts that result. In that case you will need to change to the local directory containing your modified secrets and then use git as you normally would to stash your changes. Once your changes are stashed, run a refresh and then unstash your changes and resolve the conflicts.
.RE
\fBstatus\fR
.RS
Lists all the local changes to encpass.sh secrets that need to be committed
and pushed to the remote Keybase git repo. It will output the "git status" of
each bucket where the changes are located that need to be committed and pushed.
Lists all the local changes to encpass.sh secrets that need to be committed and pushed to the remote Keybase git repo. It will output the "git status" of each bucket where the changes are located that need to be committed and pushed.
The user can perform a "encpass.sh store \fIbucket\fR" command to commit and push
the changes to Keybase.
The user can perform a "encpass.sh store \fIbucket\fR" command to commit and push the changes to Keybase.
.RE
\fBstore\fR \fIbucket\fR
.RS
Commits and pushes all pending changes to Keybase for the specified bucket to the
corresponding repo for the team/user. If this fails you may need to run a "refresh"
to make sure you have the most current version of the secrets for that bucket.
Commits and pushes all pending changes to Keybase for the specified bucket to the corresponding repo for the team/user. If this fails you may need to run a "refresh" to make sure you have the most current version of the secrets for that bucket.
.RE
EOF
)
Expand Down

0 comments on commit 486a8f0

Please sign in to comment.