7 # Email : hayao@fascode.net
9 # (c) 2019-2020 Fascode Network.
13 # Wfa is a multilingual AUR helper written in bash that is being developed to replace yaourt
17 # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
18 # Version 2, December 2004
20 # Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
22 # Everyone is permitted to copy and distribute verbatim or modified
23 # copies of this license document, and changing it is allowed as long
24 # as the name is changed.
26 # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
27 # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
29 # 0. You just DO WHAT THE FUCK YOU WANT TO.
36 ######################################################################################
38 # 翻訳はBashの連想配列を使用して行います
39 # 連想配列名は echo "${LANG}" | cut -d "." -f 1 の実行結果の値です
44 ["Undefined operation"]="未定義のオペレーションです"
45 ["only one operation may be used at a time"]="一度に使用できるオペレーションは1つだけです"
46 ["Failed to set the argument of %s"]="%sの引数の設定に失敗しました"
47 ["Setting that command is not currently supported"]="そのコマンドの設定は現在サポートされていません"
48 ["Searching in AUR ..."]="AUR内を検索しています..."
49 ["No package with an exact name match was found"]="完全に一致する名前のパッケージが見つかりませんでした"
50 ["Select a package %s with an exact name match"]="名前が完全に一致するパッケージ %s を選択します"
51 ["Download PKGBUILD of %s"]="%s のPKGBUILDをダウンロード"
52 ["Get PKGBUILD from %s"]="%sからPKGBUILDを取得します"
53 ["PKGBUILD has already been downloaded"]="PKGBUILDは既にダウンロードされています"
54 ["Do you want to overwrite and download? [n] :"]="上書きダウンロードしますか? [n] :"
55 ["Unpacking the tarball of PKGBUILD ..."]="PKGBUILDを展開しています ..."
56 [".SRCINFO was not found.\nGenerating it using makepkg"]=".SCRINFOが見つかりませんでした。makepkgを使用して生成しています"
57 ["Conflict(s) was found"]="衝突が見つかりました"
58 ["Install dependent packages..."]="依存パッケージをインストールします..."
59 ["Found %s"]="%s を見つけました"
60 ["Packages to cleanBuild? [n] :"]="パッケージをクリーンビルドしますか? [n] :"
61 ["Could not find all required packages: %s"]="必要なすべてのパッケージが見つかりませんでした: %s"
62 ["This is a feature that has not been implemented yet"]="まだ実装されていない機能です"
63 ["Package not found on AUR: %s"]="パッケージがAUR上から見つかりませんでした: "
64 ["There is no aurvote"]="aurvote が見つかりませんでした"
65 ["Please install with %s"]="%s でインストールしてください"
66 ["Voted for %s"]="%s に投票しました"
67 ["Unvoted for %s"]="%s の投票を解除しました"
69 ["(Orphaned)"]="(メンテナ不在)"
70 ["[Installed]"]="[インストール済み]"
71 ["This is a feature that has not been implemented yet"]="まだ実装されていない機能です"
76 # 翻訳データが存在しない場合はデフォルトメッセージ(英語)が出力されます
77 # そのため英語の翻訳データは必要ありません
81 ######################################################################################
88 wfa_path="$(dirname "$(realpath "${0}")")/$(basename "${0}")"
96 aururl="https://aur.archlinux.org/"
99 #-- options (bool) --#
114 makepkg_command="/usr/bin/makepkg"
116 makepkg_config="/etc/makepkg.conf"
122 pacman_command="/usr/bin/pacman"
124 pacman_config="/etc/pacman.conf"
130 git_command="/usr/bin/git"
136 gpg_command="/usr/bin/gpg"
142 sudo_command="/usr/bin/sudo"
148 curl_command="/usr/bin/curl"
153 ######################################################################################
158 # https://github.com/FascodeNet/alterlinux/blob/dev/tools/msg.sh の変数名にアンダーバーを追加し関数化
160 local OPTIND OPTARG arg
162 local _appname="msg.sh"
163 local _bash_debug=false
167 local _msg_type="info"
169 local _label_space="7"
170 local _adjust_chr=" "
171 local _customized_label=false
172 local _customized_label_color=false
174 local _noappname=false
175 local _noadjust=false
176 local _output="stdout"
179 echo "usage msg [option] [type] [message]"
181 echo "Display a message with a colored app name and message type label"
183 echo " General type:"
184 echo " info General message"
185 echo " warn Warning message"
186 echo " error Error message"
187 echo " debug Debug message"
189 echo " General options:"
190 echo " -a [name] Specify the app name"
191 echo " -c [character] Specify the character to adjust the label"
192 echo " -l [label] Specify the label."
193 echo " -n | --nocolor No output colored output"
194 echo " -o [option] Specify echo options"
195 echo " -r [color] Specify the color of label"
196 echo " -s [number] Specifies the label space."
197 echo " -x | --bash-debug Enables output bash debugging"
198 echo " -h | --help This help message"
200 echo " --nolabel Do not output label"
201 echo " --noappname Do not output app name"
202 echo " --noadjust Do not adjust the width of the label"
205 while getopts "a:c:l:no:r:s:xh-:" arg; do
211 _adjust_chr="${OPTARG}"
214 _customized_label=true
215 _msg_label="${OPTARG}"
221 _echo_opts="${OPTARG}"
224 _customized_label_color=true
256 _label_space="${OPTARG}"
297 shift $((OPTIND - 1))
322 # You can specify multiple decorations with ;.
323 # 0 => All attributs off (ノーマル)
325 # 4 => Underscore (下線)
327 # 7 => Reverse video on (色反転)
334 [[ "${_customized_label_color}" = false ]] && _labelcolor="32"
335 [[ "${_customized_label}" = false ]] && _msg_label="Info"
341 [[ "${_customized_label_color}" = false ]] && _labelcolor="33"
342 [[ "${_customized_label}" = false ]] && _msg_label="Warning"
348 [[ "${_customized_label_color}" = false ]] && _labelcolor="35"
349 [[ "${_customized_label}" = false ]] && _msg_label="Debug"
355 [[ "${_customized_label_color}" = false ]] && _labelcolor="31"
356 [[ "${_customized_label}" = false ]] && _msg_label="Error"
360 echo "Please specify the message type" >&2
364 echo "Unknown message type" >&2
369 _word_count="${#_msg_label}"
374 if [[ "${_nolabel}" = false ]]; then
375 if [[ "${_noadjust}" = false ]]; then
376 for __time in $( seq 1 $(( ${_label_space} - ${_word_count})) ); do
377 echo -ne "${_adjust_chr}"
380 if [[ "${_nocolor}" = false ]]; then
381 echo -ne "\e[$([[ -v _backcolor ]] && echo -n "${_backcolor}"; [[ -v _labelcolor ]] && echo -n ";${_labelcolor}"; [[ -v _decotypes ]] && echo -n ";${_decotypes}")m${_msg_label}\e[m "
383 echo -ne "${_msg_label} "
389 if [[ "${_noappname}" = false ]]; then
390 if [[ "${_nocolor}" = false ]]; then
391 echo -ne "\e[36m[${_appname}]\e[m "
393 echo -ne "[${_appname}] "
398 for _count in $(seq "1" "$(echo -ne "${_message}\n" | wc -l)"); do
399 _echo_message=$(echo -ne "${_message}\n" |head -n "${_count}" | tail -n 1 )
400 _full_message="$(echo_appname)$(echo_type)${_echo_message}"
403 echo ${_echo_opts} "${_full_message}" >&1
406 echo ${_echo_opts} "${_full_message}" >&2
409 echo ${_echo_opts} "${_full_message}" > ${_output}
421 local _locale="$(echo "${LANG}" | cut -d "." -f 1)"
425 local _translated_text="$(eval echo '$'{${_locale}[\"${*}\"]})"
427 if [[ -z "${_translated_text}" ]]; then
430 echo "${_translated_text}"
434 local _text _fulltext=() _main
436 if declare -p "${_locale}" 2> /dev/null 1>/dev/null; then
437 _main="$(_get_text ${1})"
442 echo "$(printf "${_main}" "${@}")"
444 _msg_translate "${@}"
449 # Show an INFO message
452 if [[ "${msgdebug}" = false ]]; then
455 local _msg_opts="-a ${wfa_name}"
456 if [[ "${1}" = "-n" ]]; then
457 _msg_opts="${_msg_opts} -o -n"
460 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
461 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
462 msg ${_msg_opts} info "$(translate "${@}")"
463 if [[ "${bash_debug}" = true ]]; then
468 # Show an Warning message
471 if [[ "${msgdebug}" = false ]]; then
474 local _msg_opts="-a ${wfa_name}"
475 if [[ "${1}" = "-n" ]]; then
476 _msg_opts="${_msg_opts} -o -n"
479 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
480 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
481 msg ${_msg_opts} warn "$(translate "${@}")"
482 if [[ "${bash_debug}" = true ]]; then
487 # Show an debug message
490 if [[ "${msgdebug}" = false ]]; then
493 if [[ "${debug}" = true ]]; then
494 local _msg_opts="-a ${wfa_name}"
495 if [[ "${1}" = "-n" ]]; then
496 _msg_opts="${_msg_opts} -o -n"
499 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
500 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
501 msg ${_msg_opts} debug "$(translate "${@}")"
503 if [[ "${bash_debug}" = true ]]; then
508 # Show an ERROR message then exit with status
510 # $2: exit code number (with 0 does not exit)
512 if [[ "${msgdebug}" = false ]]; then
515 local _msg_opts="-a ${wfa_name}"
516 if [[ "${1}" = "-n" ]]; then
517 _msg_opts="${_msg_opts} -o -n"
520 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
521 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
522 msg ${_msg_opts} error "$(translate "${@}")"
523 if [[ "${bash_debug}" = true ]]; then
529 local OPTIND OPTARG arg _textcolor _decotypes=() _message
530 while getopts "c:b" arg; do
568 shift $((OPTIND - 1))
571 _message="$(translate "${@}")"
572 if [[ "${nocolor}" = true ]]; then
575 echo -ne "\e[$([[ -v _textcolor ]] && echo -n ";${_textcolor}"; [[ -v _decotypes ]] && echo -n ";${_decotypes}")m${_message}\e[m"
579 ######################################################################################
584 # Delete the file if it exists.
585 # For directories, rm -rf is used.
586 # If the file does not exist, skip it.
587 # remove <file> <file> ...
589 local _list=($(echo "$@")) _file
590 for _file in "${_list[@]}"; do
591 msg_debug "Removing ${_file}"
592 if [[ -f "${_file}" ]]; then
594 elif [[ -d "${_file}" ]]; then
601 local _pacman_help=false
606 echo "${wfa_command}"
607 echo "${wfa_command} <operation> [...]"
610 echo " ${wfa_command} {-h --help}"
611 echo " ${wfa_command} {-A --vote}"
612 echo " ${wfa_command} {-V --version}"
613 #echo " ${wfa_command} {-D --database} <options> <package(s)>"
614 #echo " ${wfa_command} {-F --files} [options] [package(s)]"
615 echo " ${wfa_command} {-Q --query} [options] [package(s)]"
616 echo " ${wfa_command} {-R --remove} [options] <package(s)>"
617 echo " ${wfa_command} {-S --sync} [options] [package(s)]"
618 #echo " ${wfa_command} {-T --deptest} [options] [package(s)]"
619 #echo " ${wfa_command} {-U --upgrade} [options] <file(s)>"
621 #echo "New operations:"
622 #echo " ${wfa_command} {-P --show} [options]"
623 #echo " ${wfa_command} {-G --getpkgbuild} [package(s)]"
626 echo " --repo Assume targets are from the repositories"
627 echo " -a --aur Assume targets are from the AUR"
629 echo "Permanent configuration options:"
630 echo " --aururl <url> Set an alternative AUR URL"
631 echo " --makepkg <file> makepkg command to use"
632 echo " --mflags <flags> Pass arguments to makepkg"
633 echo " --pacman <file> pacman command to use"
634 echo " --git <file> git command to use"
635 echo " --gitflags <flags> Pass arguments to git"
636 echo " --gpg <file> gpg command to use"
637 echo " --gpgflags <flags> Pass arguments to gpg"
638 echo " --config <file> pacman.conf file to use"
639 echo " --makepkgconf <file> makepkg.conf file to use"
640 echo " --nomakepkgconf Use the default makepkg.conf"
642 echo "wfa specific options:"
643 echo " -c --clean Remove unneeded dependencies"
646 local _wfa_usage_sync
648 echo "usage: ${wfa_command} {-S --sync} [options] [package(s)]"
650 echo " -b, --dbpath <path> set an alternate database location"
651 echo " -c, --clean remove old packages from cache directory (-cc for all)"
652 echo " -d, --nodeps skip dependency version checks (-dd to skip all checks)"
653 echo " -s, --search <regex> search remote repositories for matching strings"
654 echo " -u, --sysupgrade upgrade installed packages (-uu enables downgrades)"
655 echo " -y, --refresh download fresh package databases from the server"
656 echo " (-yy to force a refresh even if up to date)"
657 echo " --arch <arch> set an alternate architecture"
658 echo " --color <when> colorize the output"
659 echo " --config <path> set an alternate configuration file"
660 echo " --confirm always ask for confirmation"
661 echo " --debug display debug messages"
662 echo " --disable-download-timeout"
663 echo " use relaxed timeouts for download"
664 echo " --noconfirm do not ask for any confirmation"
668 if [[ "${operation}" = "none" ]]; then
670 elif [[ "${_pacman_help}" = true ]]; then
671 "${pacman_command}" -h --${operation}
672 elif [[ "$(type -t "_wfa_usage_${operation}" )" = "function" ]]; then
673 _wfa_usage_${operation}
675 msg_error "Undefined operation"
681 if [[ "${operation}" = "none" ]]; then
683 add_args pacman "--${operation}"
685 msg_error "only one operation may be used at a time"
691 if (( ${UID} == 0 )); then
699 run_sudo "${pacman_command}" ${@}
707 # https://github.com/FascodeNet/aptpac/blob/master/aptpac のADD_OPTION関数を参考
708 # Usage: add_args [pacman/makepkg/git/gpg/sudo/curl] <args1> <args2>...
716 _args_array=(${makepkg_args})
718 makepkg_args=${_args_array[@]}
719 msg_debug "makepkg ARGS: ${makepkg_args}"
723 _args_array=(${pacman_args})
725 pacman_args=${_args_array[@]}
726 msg_debug "pacman ARGS: ${pacman_args}"
729 _args_array=(${mpg_args})
731 git_args=${_args_array[@]}
732 msg_debug "git ARGS: ${git_args}"
735 _args_array=(${gpg_args})
737 gpg_args=${_args_array[@]}
738 msg_debug "gpg ARGS: ${gpg_args}"
741 _args_array=(${sudo_args})
743 sudo_args=${_args_array[@]}
744 msg_debug "sudo ARGS: ${sudo_args}"
747 _args_array=(${curl_args})
749 curl_args=${_args_array[@]}
750 msg_debug "curl ARGS: ${curl_args}"
753 msg_error "Failed to set the argument of %s" "${_target}"
754 msg_error "Setting that command is not currently supported"
760 # 引数で指定されたパッケージがAUR以外の場所に存在しない場合にのみ正常終了します(AURのパッケージの場合に正常終了)
761 check_aur_package() {
762 local _package="${1}"
763 # 参考: https://qiita.com/Hayao0819/items/a8740a17301fafa2fdab
764 if [[ -z "$(pacman -Ssq "${_package}" 2>/dev/null | grep -o ".*${_package}$")" ]]; then
773 # 引数で指定されたパッケージが既にインストールされている場合は正常終了します。
774 check_installed_package() {
775 local _package="${1}"
776 if "${pacman_command}" -Qq "${_package}" > /dev/null 2>&1; then
783 # ~/.cacheに相当するディレクトリを返します
785 local _user_config_dir _cache_dir
786 if [[ -v XDG_CONFIG_HOME ]]; then
787 _user_config_dir="${XDG_CONFIG_HOME}"
789 _use_config_dir="${HOME}/.config"
791 if [[ -f "${_use_config_dir}/user-dirs.dirs" ]]; then
792 source "${_use_config_dir}/user-dirs.dirs"
794 if [[ -v XDG_CACHE_HOME ]]; then
795 _cache_dir="${XDG_CACHE_HOME}"
797 _cache_dir="${HOME}/.cache"
799 echo -n "${_cache_dir}"
802 # Usage: get_srcinfo_data <path> <var>
803 # 参考: https://qiita.com/withelmo/items/b0e1ffba639dd3ae18c0
805 local _srcinfo="${1}" _ver="${2}"
806 local _srcinfo_json=$(python << EOF
807 from srcinfo.parse import parse_srcinfo; import json
811 parsed, errors = parse_srcinfo(text)
812 print(json.dumps(parsed))
815 echo "${_srcinfo_json}" | jq -rc "${2}" | tr '\n' ' '
819 # AURからパッケージをビルドしてインストールします
820 # 現在1つのパッケージしか指定できません
821 install_aur_package() {
822 local _package="${1}"
825 if [[ ! -v wfa_cache_dir ]]; then
826 wfa_cache_dir="$(get_cache_dir)/wfa"
828 mkdir -p "${wfa_cache_dir}/archive"
829 mkdir -p "${wfa_cache_dir}/build/${_package}"
832 msg_info "Searching in AUR ..."
833 local _aur_json=$("${curl_command}" ${curl_args} -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name&arg=${_package}" | jq -r)
834 if (( "$(echo "${_aur_json}" | jq -r ".resultcount")" == 0 )); then
835 msg_error "Could not find all required packages: %s" "${_package}"
839 local _found_packages="$(echo "${_aur_json}" | jq -r --tab '.results[].Name')"
840 #msg_debug "Found package: $(echo ${_found_packages} | tr '\n' ' ')"
842 if [[ -n "$(echo "${_found_packages}" | grep -x "${_package}" )" ]]; then
843 msg_debug "Select a package %s with an exact name match" "${_package}"
845 msg_error "No package with an exact name match was found"
850 msg_info "Download PKGBUILD of %s" "${_package}"
851 _aur_json=$(echo "${_aur_json}" | jq -r ".results[] | select(.Name == \"${_package}\")" )
852 local _aur_snapshot_url="${aururl%/}$(echo "${_aur_json}" | jq -r ".URLPath")"
853 local _aur_version="$(echo "${_aur_json}" | jq -r ".Version")"
854 msg_debug "Get PKGBUILD from %s" "${_aur_snapshot_url}"
856 local _pkgbuild_archive_path="${wfa_cache_dir}/archive/${_package}-${_aur_version}"
857 local _download_pkgbuild=true
858 if [[ -f "${_pkgbuild_archive_path}" ]]; then
859 msg_warn "PKGBUILD has already been downloaded"
860 msg_warn -n "Do you want to overwrite and download? [n] :"
862 if [[ "${noconfirm}" = true ]]; then
868 case "${_yes_or_no}" in
869 "y" | "Y" | "yes" | "Yes" | "YES" ) _download_pkgbuild=true ;;
870 * ) _download_pkgbuild=false ;;
873 if [[ "${_download_pkgbuild}" = true ]]; then
874 remove "${_pkgbuild_archive_path}"
875 "${curl_command}" ${curl_args} -L -C - -f -o "${_pkgbuild_archive_path}" "${_aur_snapshot_url}"
879 msg_info "Unpacking the tarball of PKGBUILD ..."
880 tar -xv -f "${_pkgbuild_archive_path}" -C "${wfa_cache_dir}/build/" > /dev/null 2>&1
883 local _build_dir="${wfa_cache_dir}/build/${_package}"
884 if [[ ! -f "${_build_dir}/.SRCINFO" ]]; then
885 msg_warn ".SRCINFO was not found.\nGenerating it using makepkg"
888 "${makepkg_command}" --printsrcinfo > "${_build_dir}/.SRCINFO"
892 local _makedepends="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".makedepends[]?")"
893 local _depends="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".depends[]?")"
894 local _conflicts="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".conflicts[]?")"
895 msg_debug "makedepends: %s" "${_makedepends}"
896 msg_debug "depends: %s" "${_depends}"
897 msg_debug "conflicts: %s " "${_conflicts}"
901 local _pkg _conflicts_found=false
902 for _pkg in ${_conflicts[@]}; do
903 if "${pacman_command}" -Qq "${_pkg}" > /dev/null 2>&1 ; then
904 _conflicts_found=true
905 msg_error "${_package} is colliding with ${_pkg}"
908 if "${pacman_command}" -Qq "${_package}" > /dev/null 2>&1 && [[ ! "$("${pacman_command}" -Qq "${_package}" 2> /dev/null)" = "${_package}" ]]; then
909 msg_error "${_package} is colliding with $("${pacman_command}" -Qq "${_package}")"
910 _conflicts_found=true
912 if [[ "${_conflicts_found}" = true ]]; then
913 msg_error "Conflict(s) was found"
919 if [[ "${nodeps}" = false ]]; then
920 msg_info "Install dependent packages..."
921 local _force_aur="${force_aur}"
923 install_package "${_depends}"
924 force_aur="${_force_aur}"
930 if [[ -d "${_build_dir}/src" ]]; then
931 msg_info "Found %s" "${_build_dir}/src"
932 msg_info -n "Packages to cleanBuild? [n] :"
935 if [[ "${noconfirm}" = true ]]; then
941 case "${_yes_or_no}" in
942 "y" | "Y" | "yes" | "Yes" | "YES" ) add_args makepkg "--clean" ;;
948 add_args "makepkg" "-sf"
951 "${makepkg_command}" "${makepkg_args}"
958 "${makepkg_command}" --printsrcinfo > "${_build_dir}/.SRCINFO"
960 local _pkgnames=($(get_srcinfo_data "${_build_dir}/.SRCINFO" ".packages | keys[]"))
961 local _pkgver="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".pkgver" | sed 's/ //g')"
962 local _pkgrel="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".pkgrel" | sed 's/ //g')"
963 local _arch_array=($(get_srcinfo_data "${_build_dir}/.SRCINFO" ".arch[]"))
965 if [[ "${_arch_array[*]}" = "any" ]]; then
971 source "${makepkg_config}"
974 local _pkgfilelist=()
975 for _pkgname in ${_pkgnames[@]}; do
976 _pkgfilelist+=("${_build_dir}/${_pkgname}-${_pkgver}-${_pkgrel}-${_arch}${_PKGEXT}")
980 run_pacman -U --noconfirm ${_pkgfilelist[@]}
984 search_aur_package() {
985 local _package="${1}"
986 #msg_info "Searching in AUR ..."
987 local _aur_json=$("${curl_command}" ${curl_args} -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name-desc&arg=${_package}" | jq -r )
988 local _found_result_count="$(echo "${_aur_json}" | jq -r ".resultcount")"
989 if (( "${_found_result_count}" == 0 )); then
990 msg_error "Could not find all required packages: %s" "${_package}"
993 _aur_json=$(echo "${_aur_json}" | jq -r ".results[]")
995 local _found_pkgname=($(echo "${_aur_json}" | jq -r ".Name" ))
997 if [[ "${quiet}" = true ]]; then
1000 echo "${_found_pkgname[*]}"
1003 local _found_package __pkgver __popularity __vote __pkgdesc __orphaned __installed __output_text=()
1004 for _found_package in ${_found_pkgname[@]}; do
1007 _found_json="$(echo ${_aur_json} | jq "select(.Name == \"${_found_package}\")")"
1009 #echo "${_found_json}"
1010 __pkgver="$(echo "${_found_json}" | jq -r ".Version" )"
1011 __popularity="$(echo "${_found_json}" | jq -r ".Popularity" )"
1012 __vote="$(echo "${_found_json}" | jq -r ".NumVotes" )"
1013 __pkgdesc="$(echo "${_found_json}" | jq -r ".Description" )"
1016 # 参考: http://www.rivhiro-weather.com/knowledge/?p=536
1017 msg_debug "Row popularity: %s" "${__popularity}"
1018 __popularity="$(printf "%g\n" "${__popularity}" | awk '{printf("%4.2f", $1)}')"
1021 #参考: https://www.366service.com/jp/qa/7c95f46e5236039134ff5b862ae2cd13
1022 if ! echo "${_found_json}" | jq -r --exit-status ".Maintainer" 1> /dev/null 2> /dev/null ; then
1027 if check_installed_package "${_found_package}"; then
1032 "$(text -c blue -b "aur")/$(text -b "${_found_package}") $(text -c cyan "${__pkgver}") (+$(text -b "${__vote} ${__popularity}"))"
1035 if [[ "${__orphaned}" = true ]]; then
1036 __output_text+=("$(text -bc red "(Orphaned)")")
1039 if [[ "${__installed}" = true ]]; then
1040 __output_text+=("$(text -bc cyan "[Installed]")")
1042 echo "${__output_text[*]}"
1043 echo " ${__pkgdesc}"
1044 unset __pkgver __popularity __vote __pkgdesc _found_json __orphaned __installed __output_text
1050 operation_version() {
1051 # Pyalpmからlibalpmの値を取得
1052 # 参考: https://pyalpm.readthedocs.io/en/latest/pyalpm/pyalpm.html
1053 local _libalpm_version="$(python3 -c 'import pyalpm; print(pyalpm.alpmversion())')"
1054 local _pacman_version="$("${pacman_command}" -Q pacman | cut -d ' ' -f 2)"
1055 echo "wfa v${wfa_version} - pacman v${_pacman_version} - libalpm v${_libalpm_version}"
1058 operation_remove() {
1059 run_pacman ${pacman_args} "${specified_packages[@]}"
1062 # Usage: install_package <package1> <package2>...
1064 local _package _repo_packages=() _aur_packages=()
1065 for _package in ${@}; do
1066 if ! check_installed_package "${_package}"; then
1067 if ! check_aur_package "${_package}"; then
1068 # 公式パッケージなのでpacmanでそのままインストール
1069 _repo_packages+=("${_package}")
1072 _aur_packages+=("${_package}")
1077 if (( "${#_repo_packages[@]}" > 0 )); then
1078 run_pacman --asdeps ${pacman_args} "${_repo_packages[@]}"
1081 if (( "${#_aur_packages[@]}" > 0 )); then
1083 for _package in ${_aur_packages[@]}; do
1084 install_aur_package "${_package}"
1089 upgrade_aur_package() {
1091 msg_error "This is a feature that has not been implemented yet"
1096 if (( "${sync_clean_count}" >= 1 )); then
1097 remove "$(get_cache_dir)/wfa"
1098 run_pacman ${pacman_args} $(
1100 for _count in $(seq 1 ${sync_clean_count}); do
1107 if [[ "${sync_search}" = true ]]; then
1108 for _package in ${specified_packages[@]}; do
1109 search_aur_package "${_package}"
1111 "${pacman_command}" ${pacman_args} ${specified_packages[@]} || :
1113 if [[ "${sync_upgrade}" = true ]]; then
1115 run_pacman ${pacman_args} --sysupgrade
1117 for _package in ${specified_packages[@]}; do
1118 if ! check_aur_package "${_package}" && [[ "${force_aur}" = false ]]; then
1119 # 公式パッケージなのでpacmanでそのままインストール
1120 run_pacman ${pacman_args} "${_package}"
1123 install_aur_package "${_package}"
1124 #msg_error "Getting the AUR package has not been implemented yet."
1135 if ! type aurvote 1> /dev/null 2> /dev/null; then
1136 msg_error "There is no aurvote"
1137 msg_error "Please install with %s" "\"wfa -S aurvote\""
1141 local _package _aur_json _found_result_count _pkgver _before_popularity _before_vote
1142 for _package in ${specified_packages[@]}; do
1145 _aur_json=$("${curl_command}" ${curl_args} -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name-desc&arg=${_package}" | jq -r)
1146 _found_result_count="$(echo "${_aur_json}" | jq -r ".resultcount")"
1147 _aur_json=$(echo "${_aur_json}" | jq -r ".results[] | select(.Name == \"${_package}\")")
1148 if (( "${_found_result_count}" == 0 )) || [[ -z "${_aur_json}" ]]; then
1149 msg_error "Package not found on AUR: %s" "${_package}"
1154 _pkgver="$(echo "${_aur_json}" | jq -r ".Version" )"
1155 _before_popularity="$(printf "%g\n" "$(echo "${_aur_json}" | jq -r ".Popularity" )" | awk '{printf("%4.2f", $1)}')"
1156 _before_vote="$(echo "${_aur_json}" | jq -r ".NumVotes" )"
1159 if [[ "$(aurvote --check "${_package}")" = "not voted" ]]; then
1160 msg_info "Voted for %s" "${_package}"
1161 aurvote --vote "${_package}" 1> /dev/null
1163 msg_info "Unvoted for %s" "${_package}"
1164 aurvote --unvote "${_package}" 1> /dev/null
1168 _aur_json=$("${curl_command}" ${curl_args} -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name-desc&arg=${_package}" | jq -r ".results[] | select(.Name == \"${_package}\")")
1169 _after_popularity="$(printf "%g\n" "$(echo "${_aur_json}" | jq -r ".Popularity" )" | awk '{printf("%4.2f", $1)}')"
1170 _after_vote="$(echo "${_aur_json}" | jq -r ".NumVotes" )"
1173 msg_info "%s %s (+%s) → (+%s)" "$(text -b "${_package}")" "$(text -c cyan "${_pkgver}")" "$(text -b "${_before_vote} ${_before_popularity}")" "$(text -b "${_after_vote} ${_after_popularity}")"
1179 _opt_short="AQRShVdb:aysuc"q
1180 _opt_long="query,remove,sync,help,version,debug,dbpath:,aururl,aur,noconfirm,config:,makepkg:,mflags:,pacman:,git:,gitflags:,gpg:,gpgflags:,makepkgconf:,nomakepkgconf,nodeps,refresh,bash-debug,msg-debug,sysupgrade,color:,nocolor,clean,quiet,arch:,confirm,disable-download-timeout,curl:,curlflags:"
1182 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT})
1183 [[ ${?} != 0 ]] && exit 1
1184 unset _opt_short _opt_long
1186 eval set -- "${OPT}"
1187 msg_debug "Argument: ${OPT}"
1192 set_operation "vote"
1196 set_operation "query"
1200 set_operation "remove"
1204 set_operation "sync"
1208 set_operation "version"
1221 eval set -- "${OPT}"
1227 msg_debug "Assume targets are from the AUR"
1232 add_args pacman "--debug"
1237 add_args pacman "--nodeps"
1241 add_args pacman "--dbpath '${2}'"
1245 option_y_count=$(( option_y_count + 1 ))
1249 add_args pacman "--search"
1258 sync_clean_count=$(( sync_clean_count + 1 ))
1263 add_args pacman "--quiet"
1268 add_args pacman "--arch ${2}"
1276 add_args pacman "--noconfirm"
1281 pacman_config="${2}"
1282 add_args pacman "--config ${2}"
1286 makepkg_command="${2}"
1290 #makepkg_args="${2}"
1291 add_args makepkg "${2}"
1295 pacman_command="${2}"
1308 if [[ "${nomakepkgconf}" = false ]]; then
1309 makepkg_config="${2}"
1311 msg_warn "--nomakepkgconf is specified.\n--makepkgconf has been ignored."
1316 makepkg_config="/etc/makepkg.conf"
1333 add_args pacman "--color never"
1337 add_args pacman "--color always"
1340 msg_error "auto is not currently supported."
1341 add_args pacman "--color auto"
1347 add_args pacman "--color never"
1354 --disable-download-timeout)
1355 add_args curl "--max-time 0"
1356 add_args pacman "--disable-download-timeout"
1364 add_args curl "${2}"
1382 specified_packages=(${@})
1384 # Run database update
1385 if (( "${option_y_count}" == 1 )); then
1387 elif (( "${option_y_count}" >= 2 )); then
1391 # set_operationで設定された操作を実行
1392 case "${operation}" in
1409 msg_error "Undefined operation"