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 の投票を解除しました"
68 ["Help for this operation is not implemented"]="このオペレーションのヘルプは実装されていません"
70 ["(Orphaned)"]="(メンテナ不在)"
71 ["[Installed]"]="[インストール済み]"
72 ["This is a feature that has not been implemented yet"]="まだ実装されていない機能です"
77 # 翻訳データが存在しない場合はデフォルトメッセージ(英語)が出力されます
78 # そのため英語の翻訳データは必要ありません
82 ######################################################################################
89 wfa_path="$(dirname "$(realpath "${0}")")/$(basename "${0}")"
97 aururl="https://aur.archlinux.org/"
100 #-- options (bool) --#
115 makepkg_command="/usr/bin/makepkg"
117 makepkg_config="/etc/makepkg.conf"
123 pacman_command="/usr/bin/pacman"
125 pacman_config="/etc/pacman.conf"
131 git_command="/usr/bin/git"
137 gpg_command="/usr/bin/gpg"
143 sudo_command="/usr/bin/sudo"
149 curl_command="/usr/bin/curl"
154 ######################################################################################
159 # https://github.com/FascodeNet/alterlinux/blob/dev/tools/msg.sh の変数名にアンダーバーを追加し関数化
161 local OPTIND OPTARG arg
163 local _appname="msg.sh"
164 local _bash_debug=false
168 local _msg_type="info"
170 local _label_space="7"
171 local _adjust_chr=" "
172 local _customized_label=false
173 local _customized_label_color=false
175 local _noappname=false
176 local _noadjust=false
177 local _output="stdout"
180 echo "usage msg [option] [type] [message]"
182 echo "Display a message with a colored app name and message type label"
184 echo " General type:"
185 echo " info General message"
186 echo " warn Warning message"
187 echo " error Error message"
188 echo " debug Debug message"
190 echo " General options:"
191 echo " -a [name] Specify the app name"
192 echo " -c [character] Specify the character to adjust the label"
193 echo " -l [label] Specify the label."
194 echo " -n | --nocolor No output colored output"
195 echo " -o [option] Specify echo options"
196 echo " -r [color] Specify the color of label"
197 echo " -s [number] Specifies the label space."
198 echo " -x | --bash-debug Enables output bash debugging"
199 echo " -h | --help This help message"
201 echo " --nolabel Do not output label"
202 echo " --noappname Do not output app name"
203 echo " --noadjust Do not adjust the width of the label"
206 while getopts "a:c:l:no:r:s:xh-:" arg; do
212 _adjust_chr="${OPTARG}"
215 _customized_label=true
216 _msg_label="${OPTARG}"
222 _echo_opts="${OPTARG}"
225 _customized_label_color=true
257 _label_space="${OPTARG}"
298 shift $((OPTIND - 1))
323 # You can specify multiple decorations with ;.
324 # 0 => All attributs off (ノーマル)
326 # 4 => Underscore (下線)
328 # 7 => Reverse video on (色反転)
335 [[ "${_customized_label_color}" = false ]] && _labelcolor="32"
336 [[ "${_customized_label}" = false ]] && _msg_label="Info"
342 [[ "${_customized_label_color}" = false ]] && _labelcolor="33"
343 [[ "${_customized_label}" = false ]] && _msg_label="Warning"
349 [[ "${_customized_label_color}" = false ]] && _labelcolor="35"
350 [[ "${_customized_label}" = false ]] && _msg_label="Debug"
356 [[ "${_customized_label_color}" = false ]] && _labelcolor="31"
357 [[ "${_customized_label}" = false ]] && _msg_label="Error"
361 echo "Please specify the message type" >&2
365 echo "Unknown message type" >&2
370 _word_count="${#_msg_label}"
375 if [[ "${_nolabel}" = false ]]; then
376 if [[ "${_noadjust}" = false ]]; then
377 for __time in $( seq 1 $(( ${_label_space} - ${_word_count})) ); do
378 echo -ne "${_adjust_chr}"
381 if [[ "${_nocolor}" = false ]]; then
382 echo -ne "\e[$([[ -v _backcolor ]] && echo -n "${_backcolor}"; [[ -v _labelcolor ]] && echo -n ";${_labelcolor}"; [[ -v _decotypes ]] && echo -n ";${_decotypes}")m${_msg_label}\e[m "
384 echo -ne "${_msg_label} "
390 if [[ "${_noappname}" = false ]]; then
391 if [[ "${_nocolor}" = false ]]; then
392 echo -ne "\e[36m[${_appname}]\e[m "
394 echo -ne "[${_appname}] "
399 for _count in $(seq "1" "$(echo -ne "${_message}\n" | wc -l)"); do
400 _echo_message=$(echo -ne "${_message}\n" |head -n "${_count}" | tail -n 1 )
401 _full_message="$(echo_appname)$(echo_type)${_echo_message}"
404 echo ${_echo_opts} "${_full_message}" >&1
407 echo ${_echo_opts} "${_full_message}" >&2
410 echo ${_echo_opts} "${_full_message}" > ${_output}
422 local _locale="$(echo "${LANG}" | cut -d "." -f 1)"
426 local _translated_text="$(eval echo '$'{${_locale}[\"${*}\"]})"
428 if [[ -z "${_translated_text}" ]]; then
429 if [[ ! "${_locale}" = "C" ]] && [[ ! "${_locale}" = "en_US" ]]; then
430 echo "$(text -nc cyan "[WFA]") $(text -nc yellow "Warning") No translation data was found" 1>&2
434 echo "${_translated_text}"
438 local _text _fulltext=() _main
440 if declare -p "${_locale}" 2> /dev/null 1>/dev/null; then
441 _main="$(_get_text ${1})"
446 echo "$(printf "${_main}" "${@}")"
448 _msg_translate "${@}"
453 # Show an INFO message
456 if [[ "${msgdebug}" = false ]]; then
459 local _msg_opts="-a ${wfa_name}"
460 if [[ "${1}" = "-n" ]]; then
461 _msg_opts="${_msg_opts} -o -n"
464 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
465 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
466 msg ${_msg_opts} info "$(translate "${@}")"
467 if [[ "${bash_debug}" = true ]]; then
472 # Show an Warning message
475 if [[ "${msgdebug}" = false ]]; then
478 local _msg_opts="-a ${wfa_name}"
479 if [[ "${1}" = "-n" ]]; then
480 _msg_opts="${_msg_opts} -o -n"
483 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
484 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
485 msg ${_msg_opts} warn "$(translate "${@}")"
486 if [[ "${bash_debug}" = true ]]; then
491 # Show an debug message
494 if [[ "${msgdebug}" = false ]]; then
497 if [[ "${debug}" = true ]]; then
498 local _msg_opts="-a ${wfa_name}"
499 if [[ "${1}" = "-n" ]]; then
500 _msg_opts="${_msg_opts} -o -n"
503 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
504 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
505 msg ${_msg_opts} debug "$(translate "${@}")"
507 if [[ "${bash_debug}" = true ]]; then
512 # Show an ERROR message then exit with status
514 # $2: exit code number (with 0 does not exit)
516 if [[ "${msgdebug}" = false ]]; then
519 local _msg_opts="-a ${wfa_name}"
520 if [[ "${1}" = "-n" ]]; then
521 _msg_opts="${_msg_opts} -o -n"
524 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
525 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
526 msg ${_msg_opts} error "$(translate "${@}")"
527 if [[ "${bash_debug}" = true ]]; then
533 local OPTIND OPTARG arg _textcolor _decotypes=() _message _notranslate=false
534 while getopts "c:bn" arg; do
575 shift $((OPTIND - 1))
578 if [[ "${_notranslate}" = false ]]; then
579 _message="$(translate "${@}")"
581 if [[ "${nocolor}" = true ]]; then
584 echo -ne "\e[$([[ -v _textcolor ]] && echo -n ";${_textcolor}"; [[ -v _decotypes ]] && echo -n ";${_decotypes}")m${_message}\e[m"
588 ######################################################################################
593 # Delete the file if it exists.
594 # For directories, rm -rf is used.
595 # If the file does not exist, skip it.
596 # remove <file> <file> ...
598 local _list=($(echo "$@")) _file
599 for _file in "${_list[@]}"; do
600 msg_debug "Removing ${_file}"
601 if [[ -f "${_file}" ]]; then
603 elif [[ -d "${_file}" ]]; then
610 local _pacman_help=false
615 echo "${wfa_command}"
616 echo "${wfa_command} <operation> [...]"
619 echo " ${wfa_command} {-h --help}"
620 echo " ${wfa_command} {-A --vote}"
621 echo " ${wfa_command} {-V --version}"
622 #echo " ${wfa_command} {-D --database} <options> <package(s)>"
623 #echo " ${wfa_command} {-F --files} [options] [package(s)]"
624 echo " ${wfa_command} {-Q --query} [options] [package(s)]"
625 echo " ${wfa_command} {-R --remove} [options] <package(s)>"
626 echo " ${wfa_command} {-S --sync} [options] [package(s)]"
627 #echo " ${wfa_command} {-T --deptest} [options] [package(s)]"
628 #echo " ${wfa_command} {-U --upgrade} [options] <file(s)>"
630 #echo "New operations:"
631 #echo " ${wfa_command} {-P --show} [options]"
632 #echo " ${wfa_command} {-G --getpkgbuild} [package(s)]"
635 echo " --repo Assume targets are from the repositories"
636 echo " -a --aur Assume targets are from the AUR"
638 echo "Permanent configuration options:"
639 echo " --aururl <url> Set an alternative AUR URL"
640 echo " --makepkg <file> makepkg command to use"
641 echo " --mflags <flags> Pass arguments to makepkg"
642 echo " --pacman <file> pacman command to use"
643 echo " --git <file> git command to use"
644 echo " --gitflags <flags> Pass arguments to git"
645 echo " --gpg <file> gpg command to use"
646 echo " --gpgflags <flags> Pass arguments to gpg"
647 echo " --config <file> pacman.conf file to use"
648 echo " --makepkgconf <file> makepkg.conf file to use"
649 echo " --nomakepkgconf Use the default makepkg.conf"
651 echo "wfa specific options:"
652 echo " -c --clean Remove unneeded dependencies"
655 local _wfa_usage_sync
657 echo "usage: ${wfa_command} {-S --sync} [options] [package(s)]"
659 echo " -b, --dbpath <path> set an alternate database location"
660 echo " -c, --clean remove old packages from cache directory (-cc for all)"
661 echo " -d, --nodeps skip dependency version checks (-dd to skip all checks)"
662 echo " -s, --search <regex> search remote repositories for matching strings"
663 echo " -u, --sysupgrade upgrade installed packages (-uu enables downgrades)"
664 echo " -y, --refresh download fresh package databases from the server"
665 echo " (-yy to force a refresh even if up to date)"
666 echo " --arch <arch> set an alternate architecture"
667 echo " --color <when> colorize the output"
668 echo " --config <path> set an alternate configuration file"
669 echo " --confirm always ask for confirmation"
670 echo " --debug display debug messages"
671 echo " --disable-download-timeout"
672 echo " use relaxed timeouts for download"
673 echo " --noconfirm do not ask for any confirmation"
677 if [[ "${operation}" = "none" ]]; then
679 elif [[ "${_pacman_help}" = true ]]; then
680 "${pacman_command}" -h --${operation}
681 elif [[ "$(type -t "_wfa_usage_${operation}" )" = "function" ]]; then
682 _wfa_usage_${operation}
684 msg_error "Help for this operation is not implemented"
690 if [[ "${operation}" = "none" ]]; then
692 add_args pacman "--${operation}"
694 msg_error "only one operation may be used at a time"
700 if (( ${UID} == 0 )); then
708 run_sudo "${pacman_command}" ${@}
716 # https://github.com/FascodeNet/aptpac/blob/master/aptpac のADD_OPTION関数を参考
717 # Usage: add_args [pacman/makepkg/git/gpg/sudo/curl] <args1> <args2>...
725 _args_array=(${makepkg_args})
727 makepkg_args=${_args_array[@]}
728 msg_debug "makepkg ARGS: ${makepkg_args}"
732 _args_array=(${pacman_args})
734 pacman_args=${_args_array[@]}
735 msg_debug "pacman ARGS: ${pacman_args}"
738 _args_array=(${mpg_args})
740 git_args=${_args_array[@]}
741 msg_debug "git ARGS: ${git_args}"
744 _args_array=(${gpg_args})
746 gpg_args=${_args_array[@]}
747 msg_debug "gpg ARGS: ${gpg_args}"
750 _args_array=(${sudo_args})
752 sudo_args=${_args_array[@]}
753 msg_debug "sudo ARGS: ${sudo_args}"
756 _args_array=(${curl_args})
758 curl_args=${_args_array[@]}
759 msg_debug "curl ARGS: ${curl_args}"
762 msg_error "Failed to set the argument of %s" "${_target}"
763 msg_error "Setting that command is not currently supported"
769 # 引数で指定されたパッケージがAUR以外の場所に存在しない場合にのみ正常終了します(AURのパッケージの場合に正常終了)
770 check_aur_package() {
771 local _package="${1}"
772 # 参考: https://qiita.com/Hayao0819/items/a8740a17301fafa2fdab
773 if [[ -z "$(pacman -Ssq "${_package}" 2>/dev/null | grep -o ".*${_package}$")" ]]; then
782 # 引数で指定されたパッケージが既にインストールされている場合は正常終了します。
783 check_installed_package() {
784 local _package="${1}"
785 if "${pacman_command}" -Qq "${_package}" > /dev/null 2>&1; then
792 # ~/.cacheに相当するディレクトリを返します
794 local _user_config_dir _cache_dir
795 if [[ -v XDG_CONFIG_HOME ]]; then
796 _user_config_dir="${XDG_CONFIG_HOME}"
798 _use_config_dir="${HOME}/.config"
800 if [[ -f "${_use_config_dir}/user-dirs.dirs" ]]; then
801 source "${_use_config_dir}/user-dirs.dirs"
803 if [[ -v XDG_CACHE_HOME ]]; then
804 _cache_dir="${XDG_CACHE_HOME}"
806 _cache_dir="${HOME}/.cache"
808 echo -n "${_cache_dir}"
811 # Usage: get_srcinfo_data <path> <var>
812 # 参考: https://qiita.com/withelmo/items/b0e1ffba639dd3ae18c0
814 local _srcinfo="${1}" _ver="${2}"
815 local _srcinfo_json=$(python << EOF
816 from srcinfo.parse import parse_srcinfo; import json
820 parsed, errors = parse_srcinfo(text)
821 print(json.dumps(parsed))
824 echo "${_srcinfo_json}" | jq -rc "${2}" | tr '\n' ' '
828 # AURからパッケージをビルドしてインストールします
829 # 現在1つのパッケージしか指定できません
830 install_aur_package() {
831 local _package="${1}"
834 if [[ ! -v wfa_cache_dir ]]; then
835 wfa_cache_dir="$(get_cache_dir)/wfa"
837 mkdir -p "${wfa_cache_dir}/archive"
838 mkdir -p "${wfa_cache_dir}/build/${_package}"
841 msg_info "Searching in AUR ..."
842 local _aur_json=$("${curl_command}" ${curl_args} -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name&arg=${_package}" | jq -r)
843 if (( "$(echo "${_aur_json}" | jq -r ".resultcount")" == 0 )); then
844 msg_error "Could not find all required packages: %s" "${_package}"
848 local _found_packages="$(echo "${_aur_json}" | jq -r --tab '.results[].Name')"
849 #msg_debug "Found package: $(echo ${_found_packages} | tr '\n' ' ')"
851 if [[ -n "$(echo "${_found_packages}" | grep -x "${_package}" )" ]]; then
852 msg_debug "Select a package %s with an exact name match" "${_package}"
854 msg_error "No package with an exact name match was found"
859 msg_info "Download PKGBUILD of %s" "${_package}"
860 _aur_json=$(echo "${_aur_json}" | jq -r ".results[] | select(.Name == \"${_package}\")" )
861 local _aur_snapshot_url="${aururl%/}$(echo "${_aur_json}" | jq -r ".URLPath")"
862 local _aur_version="$(echo "${_aur_json}" | jq -r ".Version")"
863 msg_debug "Get PKGBUILD from %s" "${_aur_snapshot_url}"
865 local _pkgbuild_archive_path="${wfa_cache_dir}/archive/${_package}-${_aur_version}"
866 local _download_pkgbuild=true
867 if [[ -f "${_pkgbuild_archive_path}" ]]; then
868 msg_warn "PKGBUILD has already been downloaded"
869 msg_warn -n "Do you want to overwrite and download? [n] :"
871 if [[ "${noconfirm}" = true ]]; then
877 case "${_yes_or_no}" in
878 "y" | "Y" | "yes" | "Yes" | "YES" ) _download_pkgbuild=true ;;
879 * ) _download_pkgbuild=false ;;
882 if [[ "${_download_pkgbuild}" = true ]]; then
883 remove "${_pkgbuild_archive_path}"
884 "${curl_command}" ${curl_args} -L -C - -f -o "${_pkgbuild_archive_path}" "${_aur_snapshot_url}"
888 msg_info "Unpacking the tarball of PKGBUILD ..."
889 tar -xv -f "${_pkgbuild_archive_path}" -C "${wfa_cache_dir}/build/" > /dev/null 2>&1
892 local _build_dir="${wfa_cache_dir}/build/${_package}"
893 if [[ ! -f "${_build_dir}/.SRCINFO" ]]; then
894 msg_warn ".SRCINFO was not found.\nGenerating it using makepkg"
897 "${makepkg_command}" --printsrcinfo > "${_build_dir}/.SRCINFO"
901 local _makedepends="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".makedepends[]?")"
902 local _depends="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".depends[]?")"
903 local _conflicts="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".conflicts[]?")"
904 msg_debug "makedepends: %s" "${_makedepends}"
905 msg_debug "depends: %s" "${_depends}"
906 msg_debug "conflicts: %s " "${_conflicts}"
910 local _pkg _conflicts_found=false
911 for _pkg in ${_conflicts[@]}; do
912 if "${pacman_command}" -Qq "${_pkg}" > /dev/null 2>&1 ; then
913 _conflicts_found=true
914 msg_error "${_package} is colliding with ${_pkg}"
917 if "${pacman_command}" -Qq "${_package}" > /dev/null 2>&1 && [[ ! "$("${pacman_command}" -Qq "${_package}" 2> /dev/null)" = "${_package}" ]]; then
918 msg_error "${_package} is colliding with $("${pacman_command}" -Qq "${_package}")"
919 _conflicts_found=true
921 if [[ "${_conflicts_found}" = true ]]; then
922 msg_error "Conflict(s) was found"
928 if [[ "${nodeps}" = false ]]; then
929 msg_info "Install dependent packages..."
930 local _force_aur="${force_aur}"
932 install_package "${_depends}"
933 force_aur="${_force_aur}"
939 if [[ -d "${_build_dir}/src" ]]; then
940 msg_info "Found %s" "${_build_dir}/src"
941 msg_info -n "Packages to cleanBuild? [n] :"
944 if [[ "${noconfirm}" = true ]]; then
950 case "${_yes_or_no}" in
951 "y" | "Y" | "yes" | "Yes" | "YES" ) add_args makepkg "--clean" ;;
957 add_args "makepkg" "-sf"
960 "${makepkg_command}" "${makepkg_args}"
967 "${makepkg_command}" --printsrcinfo > "${_build_dir}/.SRCINFO"
969 local _pkgnames=($(get_srcinfo_data "${_build_dir}/.SRCINFO" ".packages | keys[]"))
970 local _pkgver="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".pkgver" | sed 's/ //g')"
971 local _pkgrel="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".pkgrel" | sed 's/ //g')"
972 local _arch_array=($(get_srcinfo_data "${_build_dir}/.SRCINFO" ".arch[]"))
974 if [[ "${_arch_array[*]}" = "any" ]]; then
980 source "${makepkg_config}"
983 local _pkgfilelist=()
984 for _pkgname in ${_pkgnames[@]}; do
985 _pkgfilelist+=("${_build_dir}/${_pkgname}-${_pkgver}-${_pkgrel}-${_arch}${_PKGEXT}")
989 run_pacman -U --noconfirm ${_pkgfilelist[@]}
993 search_aur_package() {
994 local _package="${1}"
995 #msg_info "Searching in AUR ..."
996 local _aur_json=$("${curl_command}" ${curl_args} -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name-desc&arg=${_package}" | jq -r )
997 local _found_result_count="$(echo "${_aur_json}" | jq -r ".resultcount")"
998 if (( "${_found_result_count}" == 0 )); then
999 msg_error "Could not find all required packages: %s" "${_package}"
1002 _aur_json=$(echo "${_aur_json}" | jq -r ".results[]")
1004 local _found_pkgname=($(echo "${_aur_json}" | jq -r ".Name" ))
1006 if [[ "${quiet}" = true ]]; then
1009 echo "${_found_pkgname[*]}"
1012 local _found_package __pkgver __popularity __vote __pkgdesc __orphaned __installed __output_text=()
1013 for _found_package in ${_found_pkgname[@]}; do
1016 _found_json="$(echo ${_aur_json} | jq "select(.Name == \"${_found_package}\")")"
1018 #echo "${_found_json}"
1019 __pkgver="$(echo "${_found_json}" | jq -r ".Version" )"
1020 __popularity="$(echo "${_found_json}" | jq -r ".Popularity" )"
1021 __vote="$(echo "${_found_json}" | jq -r ".NumVotes" )"
1022 __pkgdesc="$(echo "${_found_json}" | jq -r ".Description" )"
1025 # 参考: http://www.rivhiro-weather.com/knowledge/?p=536
1026 msg_debug "Row popularity: %s" "${__popularity}"
1027 __popularity="$(printf "%g\n" "${__popularity}" | awk '{printf("%4.2f", $1)}')"
1030 #参考: https://www.366service.com/jp/qa/7c95f46e5236039134ff5b862ae2cd13
1031 if ! echo "${_found_json}" | jq -r --exit-status ".Maintainer" 1> /dev/null 2> /dev/null ; then
1036 if check_installed_package "${_found_package}"; then
1041 "$(text -c blue -b "aur")/$(text -b "${_found_package}") $(text -c cyan "${__pkgver}") (+$(text -b "${__vote} ${__popularity}"))"
1044 if [[ "${__orphaned}" = true ]]; then
1045 __output_text+=("$(text -bc red "(Orphaned)")")
1048 if [[ "${__installed}" = true ]]; then
1049 __output_text+=("$(text -bc cyan "[Installed]")")
1051 echo "${__output_text[*]}"
1052 echo " ${__pkgdesc}"
1053 unset __pkgver __popularity __vote __pkgdesc _found_json __orphaned __installed __output_text
1059 operation_version() {
1060 # Pyalpmからlibalpmの値を取得
1061 # 参考: https://pyalpm.readthedocs.io/en/latest/pyalpm/pyalpm.html
1062 local _libalpm_version="$(python3 -c 'import pyalpm; print(pyalpm.alpmversion())')"
1063 local _pacman_version="$("${pacman_command}" -Q pacman | cut -d ' ' -f 2)"
1064 echo "wfa v${wfa_version} - pacman v${_pacman_version} - libalpm v${_libalpm_version}"
1067 operation_remove() {
1068 run_pacman ${pacman_args} "${specified_packages[@]}"
1071 # Usage: install_package <package1> <package2>...
1073 local _package _repo_packages=() _aur_packages=()
1074 for _package in ${@}; do
1075 if ! check_installed_package "${_package}"; then
1076 if ! check_aur_package "${_package}"; then
1077 # 公式パッケージなのでpacmanでそのままインストール
1078 _repo_packages+=("${_package}")
1081 _aur_packages+=("${_package}")
1086 if (( "${#_repo_packages[@]}" > 0 )); then
1087 run_pacman --asdeps ${pacman_args} "${_repo_packages[@]}"
1090 if (( "${#_aur_packages[@]}" > 0 )); then
1092 for _package in ${_aur_packages[@]}; do
1093 install_aur_package "${_package}"
1098 upgrade_aur_package() {
1100 msg_error "This is a feature that has not been implemented yet"
1105 if (( "${sync_clean_count}" >= 1 )); then
1106 remove "$(get_cache_dir)/wfa"
1107 run_pacman ${pacman_args} $(
1109 for _count in $(seq 1 ${sync_clean_count}); do
1116 if [[ "${sync_search}" = true ]]; then
1117 for _package in ${specified_packages[@]}; do
1118 search_aur_package "${_package}"
1120 "${pacman_command}" ${pacman_args} ${specified_packages[@]} || :
1122 if [[ "${sync_upgrade}" = true ]]; then
1124 run_pacman ${pacman_args} --sysupgrade
1126 for _package in ${specified_packages[@]}; do
1127 if ! check_aur_package "${_package}" && [[ "${force_aur}" = false ]]; then
1128 # 公式パッケージなのでpacmanでそのままインストール
1129 run_pacman ${pacman_args} "${_package}"
1132 install_aur_package "${_package}"
1133 #msg_error "Getting the AUR package has not been implemented yet."
1144 if ! type aurvote 1> /dev/null 2> /dev/null; then
1145 msg_error "There is no aurvote"
1146 msg_error "Please install with %s" "\"wfa -S aurvote\""
1150 local _package _aur_json _found_result_count _pkgver _before_popularity _before_vote
1151 for _package in ${specified_packages[@]}; do
1154 _aur_json=$("${curl_command}" ${curl_args} -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name-desc&arg=${_package}" | jq -r)
1155 _found_result_count="$(echo "${_aur_json}" | jq -r ".resultcount")"
1156 _aur_json=$(echo "${_aur_json}" | jq -r ".results[] | select(.Name == \"${_package}\")")
1157 if (( "${_found_result_count}" == 0 )) || [[ -z "${_aur_json}" ]]; then
1158 msg_error "Package not found on AUR: %s" "${_package}"
1163 _pkgver="$(echo "${_aur_json}" | jq -r ".Version" )"
1164 _before_popularity="$(printf "%g\n" "$(echo "${_aur_json}" | jq -r ".Popularity" )" | awk '{printf("%4.2f", $1)}')"
1165 _before_vote="$(echo "${_aur_json}" | jq -r ".NumVotes" )"
1168 if [[ "$(aurvote --check "${_package}")" = "not voted" ]]; then
1169 msg_info "Voted for %s" "${_package}"
1170 aurvote --vote "${_package}" 1> /dev/null
1172 msg_info "Unvoted for %s" "${_package}"
1173 aurvote --unvote "${_package}" 1> /dev/null
1177 _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}\")")
1178 _after_popularity="$(printf "%g\n" "$(echo "${_aur_json}" | jq -r ".Popularity" )" | awk '{printf("%4.2f", $1)}')"
1179 _after_vote="$(echo "${_aur_json}" | jq -r ".NumVotes" )"
1182 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}")"
1188 _opt_short="AQRShVdb:aysuc"q
1189 _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:"
1191 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT})
1192 [[ ${?} != 0 ]] && exit 1
1193 unset _opt_short _opt_long
1195 eval set -- "${OPT}"
1196 msg_debug "Argument: ${OPT}"
1201 set_operation "vote"
1205 set_operation "query"
1209 set_operation "remove"
1213 set_operation "sync"
1217 set_operation "version"
1230 eval set -- "${OPT}"
1236 msg_debug "Assume targets are from the AUR"
1241 add_args pacman "--debug"
1246 add_args pacman "--nodeps"
1250 add_args pacman "--dbpath '${2}'"
1254 option_y_count=$(( option_y_count + 1 ))
1258 add_args pacman "--search"
1267 sync_clean_count=$(( sync_clean_count + 1 ))
1272 add_args pacman "--quiet"
1277 add_args pacman "--arch ${2}"
1285 add_args pacman "--noconfirm"
1290 pacman_config="${2}"
1291 add_args pacman "--config ${2}"
1295 makepkg_command="${2}"
1299 #makepkg_args="${2}"
1300 add_args makepkg "${2}"
1304 pacman_command="${2}"
1317 if [[ "${nomakepkgconf}" = false ]]; then
1318 makepkg_config="${2}"
1320 msg_warn "--nomakepkgconf is specified.\n--makepkgconf has been ignored."
1325 makepkg_config="/etc/makepkg.conf"
1342 add_args pacman "--color never"
1346 add_args pacman "--color always"
1349 msg_error "auto is not currently supported."
1350 add_args pacman "--color auto"
1356 add_args pacman "--color never"
1363 --disable-download-timeout)
1364 add_args curl "--max-time 0"
1365 add_args pacman "--disable-download-timeout"
1373 add_args curl "${2}"
1391 specified_packages=(${@})
1393 # Run database update
1394 if (( "${option_y_count}" == 1 )); then
1396 elif (( "${option_y_count}" >= 2 )); then
1400 # set_operationで設定された操作を実行
1401 case "${operation}" in
1418 msg_error "Undefined operation"