Skip to content

Commit

Permalink
Squash merge PR #40 refactor: -e to type (#29)
Browse files Browse the repository at this point in the history
* refactor: -e to type (#29)
* Close #29
  • Loading branch information
KEINOS authored Jun 3, 2021
1 parent 7b864fa commit dde7df6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
11 changes: 7 additions & 4 deletions bin/archive
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

# md5s は md5sum/md5 のラッパー関数です.
md5s() {
if [ -e "$(which md5sum)" ]; then
if type md5sum 1>/dev/null 2>/dev/null; then
echo "$1" | md5sum | awk '{ print $1 }'
return $?
fi

if [ -e "$(which md5)" ]; then
if type md5 1>/dev/null 2>/dev/null; then
md5 -q -s "$1"
return $?
fi
Expand All @@ -30,9 +30,12 @@ md5s() {
}

md5f() {
if [ -e md5sum ]; then
if type md5sum 1>/dev/null 2>/dev/null; then
md5sum <"$1"
elif [ -e md5 ]; then
return $?
fi

if type md5 1>/dev/null 2>/dev/null; then
md5 -q "$1"
fi
}
Expand Down
11 changes: 9 additions & 2 deletions bin/checkkeylength
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ if [[ $# -lt 1 ]]; then
fi

md5s() {
if [ -e "$(which md5sum)" ]; then
if type md5sum 1>/dev/null 2>/dev/null; then
echo "$1" | md5sum | awk '{ print $1 }'
elif [ -e "$(which md5)" ]; then
return $?
fi

if type md5 1>/dev/null 2>/dev/null; then
md5 -q -s "$1"
return $?
fi

echo >&2 'MD5 ハッシュ関数がありません。'
exit 1
}

# コマンド引数取得
Expand Down
12 changes: 6 additions & 6 deletions bin/enc
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
# -----------------------------------------------------------------------------
# Requirement check
# -----------------------------------------------------------------------------
which openssl 2>/dev/null 1>/dev/null || {
if ! type openssl 2>/dev/null 1>/dev/null; then
echo >&2 '暗号化に必要な openssl コマンドがインストールされていません。'

exit 1
}
fi

which curl 2>/dev/null 1>/dev/null || {
if ! type curl 2>/dev/null 1>/dev/null; then
echo >&2 'データ取得に必要な curl コマンドがインストールされていません。'

exit 1
}
fi

# -----------------------------------------------------------------------------
# Main
Expand All @@ -50,12 +50,12 @@ fi

# md5s は md5sum/md5 のラッパー関数です.
md5s() {
if [ -e "$(which md5sum)" ]; then
if type md5sum 1>/dev/null 2>/dev/null; then
echo "$1" | md5sum | awk '{ print $1 }'
return $?
fi

if [ -e "$(which md5)" ]; then
if type md5 1>/dev/null 2>/dev/null; then
md5 -q -s "$1"
return $?
fi
Expand Down
4 changes: 2 additions & 2 deletions bin/sign
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ fi

# md5s は md5sum/md5 のラッパー関数です.
md5s() {
if [ -e "$(which md5sum)" ]; then
if type md5sum 1>/dev/null 2>/dev/null; then
echo "$1" | md5sum | awk '{ print $1 }'
return $?
fi

if [ -e "$(which md5)" ]; then
if type md5 1>/dev/null 2>/dev/null; then
md5 -q -s "$1"
return $?
fi
Expand Down
4 changes: 2 additions & 2 deletions bin/verify
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ fi

# md5s は md5sum/md5 のラッパー関数です.
md5s() {
if [ -e "$(which md5sum)" ]; then
if type md5sum 1>/dev/null 2>/dev/null; then
echo "$1" | md5sum | awk '{ print $1 }'
return $?
fi

if [ -e "$(which md5)" ]; then
if type md5 1>/dev/null 2>/dev/null; then
md5 -q -s "$1"
return $?
fi
Expand Down
6 changes: 3 additions & 3 deletions tests/issues/issue25_test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#shellcheck shell=bash
#shellcheck shell=sh

# md5s は md5sum/md5 のラッパー関数です.
md5s() {
if [ -e "$(which md5sum)" ]; then
if type md5sum 1>/dev/null 2>/dev/null; then
echo "$1" | md5sum | awk '{ print $1 }'
return $?
fi

if [ -e "$(which md5)" ]; then
if type md5 1>/dev/null 2>/dev/null; then
md5 -q -s "$1"
return $?
fi
Expand Down

0 comments on commit dde7df6

Please sign in to comment.