|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
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 |
4 | 17 |
|
| 18 | +# searchpkg <pkg> |
5 | 19 | function searchpkg(){ |
| 20 | + msg_debug " In group ..." |
6 | 21 | if printf "%s\n" "${group_list[@]}" | grep -x "${1}" >/dev/null; then |
7 | 22 | return 0 |
8 | 23 | fi |
9 | | - #if pacman -Ssq "${1}" 2>/dev/null | grep -o "^${1}*\$" 1>/dev/null; then |
| 24 | + msg_debug " In official repo (package name)..." |
10 | 25 | if [[ -n "$(curl -sL "https://archlinux.org/packages/search/json/?name=${1}" | jq -r '.results[]')" ]]; then |
11 | 26 | 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 |
13 | 30 | 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 |
15 | 34 | return 0 |
16 | | - else |
17 | | - return 1 |
18 | 35 | fi |
| 36 | + return 1 |
19 | 37 | } |
20 | 38 |
|
| 39 | +# ユーザーによって中止された場合に終了 |
21 | 40 | function trap_exit() { |
22 | 41 | local status="${?}" |
23 | 42 | exit "${status}" |
24 | 43 | } |
25 | | - |
26 | 44 | trap 'trap_exit' 1 2 3 15 |
27 | 45 |
|
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)) |
31 | 100 |
|
| 101 | +# 実行開始 |
32 | 102 | for pkg in ${packages[@]}; do |
| 103 | + msg_debug "Searching ${pkg} ..." |
33 | 104 | if ! searchpkg "${pkg}"; then |
34 | 105 | echo "${pkg} is not in the official repository." >&2 |
35 | 106 | error=true |
36 | 107 | fi |
37 | 108 | done |
38 | 109 |
|
| 110 | +# エラーが出た場合は異常終了 |
39 | 111 | if [[ "${error}" = true ]]; then |
40 | 112 | exit 1 |
41 | 113 | else |
|
0 commit comments