Skip to content

Commit ed98c81

Browse files
committed
[update] : Added debug message
1 parent 1ae0f69 commit ed98c81

File tree

1 file changed

+82
-10
lines changed

1 file changed

+82
-10
lines changed

tools/testpkg.sh

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,113 @@
11
#!/usr/bin/env bash
22

3-
group_list=($(curl -s https://archlinux.org/groups/ | grep "/groups/x86_64" | cut -d "/" -f 4))
3+
# 現在のスクリプトのパス
4+
script_path="$( cd -P "$( dirname "$(readlink -f "$0")" )" && cd .. && pwd )"
5+
6+
# エラーが出た場合はtrueになるので変更禁止
7+
error=false
8+
9+
# パッケージ一覧(初期化)
10+
packages=()
11+
12+
# アーキテクチャ一覧
13+
archs=("x86_64")
14+
15+
# デバッグモード
16+
debug=false
417

18+
# searchpkg <pkg>
519
function searchpkg(){
20+
msg_debug " In group ..."
621
if printf "%s\n" "${group_list[@]}" | grep -x "${1}" >/dev/null; then
722
return 0
823
fi
9-
#if pacman -Ssq "${1}" 2>/dev/null | grep -o "^${1}*\$" 1>/dev/null; then
24+
msg_debug " In official repo (package name)..."
1025
if [[ -n "$(curl -sL "https://archlinux.org/packages/search/json/?name=${1}" | jq -r '.results[]')" ]]; then
1126
return 0
12-
elif [[ -n "$(curl -sL "https://archlinux.org/packages/search/json/?q=${1}" | jq -r ".results[].provides[]")" ]]; then
27+
fi
28+
msg_debug " In official repo (provides)..."
29+
if [[ -n "$(curl -sL "https://archlinux.org/packages/search/json/?q=${1}" | jq -r ".results[].provides[]")" ]]; then
1330
return 0
14-
elif [[ -n "$(curl -s https://repo.dyama.net/alter-stable/x86_64/ | grep '\./' | grep "pkg.tar" | sed "s| ||g" | cut -d '"' -f 2 | xargs -If basename f | grep "${1}")" ]]; then
31+
fi
32+
msg_debug " In YamaD repo ..."
33+
if [[ -n "$(curl -s https://repo.dyama.net/alter-stable/x86_64/ | grep '\./' | grep "pkg.tar" | sed "s| ||g" | cut -d '"' -f 2 | xargs -If basename f | grep "${1}")" ]]; then
1534
return 0
16-
else
17-
return 1
1835
fi
36+
return 1
1937
}
2038

39+
# ユーザーによって中止された場合に終了
2140
function trap_exit() {
2241
local status="${?}"
2342
exit "${status}"
2443
}
25-
2644
trap 'trap_exit' 1 2 3 15
2745

28-
script_path="$( cd -P "$( dirname "$(readlink -f "$0")" )" && cd .. && pwd )"
29-
packages="$("${script_path}/tools/allpkglist.sh" -s -a "x86_64")"
30-
error=false
46+
# デバッグモード用関数
47+
msg_debug(){
48+
if [[ "${debug}" = true ]]; then
49+
"${script_path}/tools/msg.sh" -s "5" -a "testpkg.sh" -l "Debug" -r "magenta" error "${1}"
50+
fi
51+
}
52+
53+
# ヘルプ
54+
_help() {
55+
echo "usage ${0} [options]"
56+
echo
57+
echo " General options:"
58+
echo " -d | --debug Enable debug message"
59+
echo " -h | --help This help message"
60+
}
61+
62+
63+
# Parse options
64+
ARGUMENT="${@}"
65+
opt_short="dh"
66+
opt_long="debug,help"
67+
OPT=$(getopt -o ${opt_short} -l ${opt_long} -- ${ARGUMENT})
68+
[[ ${?} != 0 ]] && exit 1
69+
70+
eval set -- "${OPT}"
71+
unset OPT opt_short opt_long
72+
73+
while true; do
74+
case "${1}" in
75+
-d | --debug)
76+
debug=true
77+
shift 1
78+
;;
79+
-h | --help)
80+
_help
81+
exit 0
82+
;;
83+
--)
84+
shift 1
85+
break
86+
;;
87+
88+
esac
89+
done
90+
91+
# パッケージ一覧
92+
msg_debug "Getting package list ..."
93+
for arch in ${archs[@]}; do
94+
packages+=($("${script_path}/tools/allpkglist.sh" -s -a "${arch}"))
95+
done
96+
97+
# ArchLinux公式サイトからパッケージグループの一覧を取得
98+
msg_debug "Getting group list ..."
99+
group_list=($(curl -s https://archlinux.org/groups/ | grep "/groups/x86_64" | cut -d "/" -f 4))
31100

101+
# 実行開始
32102
for pkg in ${packages[@]}; do
103+
msg_debug "Searching ${pkg} ..."
33104
if ! searchpkg "${pkg}"; then
34105
echo "${pkg} is not in the official repository." >&2
35106
error=true
36107
fi
37108
done
38109

110+
# エラーが出た場合は異常終了
39111
if [[ "${error}" = true ]]; then
40112
exit 1
41113
else

0 commit comments

Comments
 (0)