Skip to content

Commit fe9bdae

Browse files
committed
[update] : Refacterd package.sh
1 parent 446e389 commit fe9bdae

File tree

1 file changed

+30
-35
lines changed

1 file changed

+30
-35
lines changed

tools/package.sh

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ done
100100

101101
shift $((OPTIND - 1))
102102

103-
104-
_installed_pkg=($(pacman -Q | getclm 1))
105-
_installed_ver=($(pacman -Q | getclm 2))
106-
107103
if [[ -z "${1}" ]]; then
108104
if [[ "${script_mode}" = true ]]; then
109105
echo "error"
@@ -120,39 +116,38 @@ elif [[ -n "${2}" ]]; then
120116
exit 1
121117
fi
122118

123-
for pkg in $(seq 0 $(( ${#_installed_pkg[@]} - 1 ))); do
124-
# パッケージがインストールされているかどうか
125-
if [[ "${_installed_pkg[${pkg}]}" = ${1} ]]; then
126-
ver="$(pacman -Sp --print-format '%v' ${1} 2> /dev/null; :)"
127-
if [[ "${_installed_ver[${pkg}]}" = "${ver}" ]]; then
128-
# パッケージが最新の場合
129-
if [[ "${script_mode}" = true ]]; then
130-
echo "latest"
131-
else
132-
msg_info "The latest version of ${1} is installed."
133-
fi
134-
exit 0
135-
elif [[ -z "${ver}" ]]; then
136-
# リモートのバージョンの取得に失敗した場合
137-
if [[ "${script_mode}" = true ]]; then
138-
echo "noversion"
139-
else
140-
msg_warn "Failed to get the latest version of ${1}."
141-
fi
142-
exit 1
119+
latest_ver="$(pacman -Sp --print-format '%v' ${1} 2> /dev/null; :)"
120+
local_ver="$( (pacman -Q ${1} | getclm 2) 2> /dev/null; :)"
121+
if pacman -Q "${1}" 2> "/dev/null" 1>&2; then
122+
if [[ "${latest_ver}" = "${local_ver}" ]]; then
123+
# パッケージが最新の場合
124+
if [[ "${script_mode}" = true ]]; then
125+
echo "latest"
143126
else
144-
# リモートとローカルのバージョンが一致しない場合
145-
if [[ "${script_mode}" = true ]]; then
146-
echo "old"
147-
else
148-
msg_warn "${1} is not the latest package.\nLocal: $(pacman -Q ${1} 2> /dev/null | getclm 2) Latest: ${ver}"
149-
fi
150-
exit 1
127+
msg_info "The latest version of ${1} is installed."
128+
fi
129+
exit 0
130+
elif [[ -z "${latest_ver}" ]]; then
131+
# リモートのバージョンの取得に失敗した場合
132+
if [[ "${script_mode}" = true ]]; then
133+
echo "noversion"
134+
else
135+
msg_warn "Failed to get the latest version of ${1}."
151136
fi
137+
exit 1
138+
else
139+
# リモートとローカルのバージョンが一致しない場合
140+
if [[ "${script_mode}" = true ]]; then
141+
echo "old"
142+
else
143+
msg_warn "${1} is not the latest package.\nLocal: $(pacman -Q ${1} 2> /dev/null | getclm 2) Latest: ${latest_ver}"
144+
fi
145+
exit 1
152146
fi
153-
done
154-
if [[ "${script_mode}" = true ]]; then
155-
echo "failed"
156147
else
157-
msg_error "${1} is not installed."
148+
if [[ "${script_mode}" = true ]]; then
149+
echo "failed"
150+
else
151+
msg_error "${1} is not installed."
152+
fi
158153
fi

0 commit comments

Comments
 (0)