Skip to content

Commit

Permalink
refactor: -e to type (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
KEINOS committed Jun 3, 2021
1 parent 3fb32a1 commit 71f99e4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 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

0 comments on commit 71f99e4

Please sign in to comment.