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"]="まだ実装されていない機能です"
74 ["Please make a contract with me and become a Puella Magi !"]="僕と契約して魔法少女になってよ! "
79 # 翻訳データが存在しない場合はデフォルトメッセージ(英語)が出力されます
80 # そのため英語の翻訳データは必要ありません
84 ######################################################################################
91 wfa_path="$(dirname "$(realpath "${0}")")/$(basename "${0}")"
99 aururl="https://aur.archlinux.org/"
102 #-- options (bool) --#
117 makepkg_command="/usr/bin/makepkg"
119 makepkg_config="/etc/makepkg.conf"
125 pacman_command="/usr/bin/pacman"
127 pacman_config="/etc/pacman.conf"
133 git_command="/usr/bin/git"
139 gpg_command="/usr/bin/gpg"
145 sudo_command="/usr/bin/sudo"
151 curl_command="/usr/bin/curl"
156 ######################################################################################
161 # https://github.com/FascodeNet/alterlinux/blob/dev/tools/msg.sh の変数名にアンダーバーを追加し関数化
163 local OPTIND OPTARG arg
165 local _appname="msg.sh"
166 local _bash_debug=false
170 local _msg_type="info"
172 local _label_space="7"
173 local _adjust_chr=" "
174 local _customized_label=false
175 local _customized_label_color=false
177 local _noappname=false
178 local _noadjust=false
179 local _output="stdout"
182 echo "usage msg [option] [type] [message]"
184 echo "Display a message with a colored app name and message type label"
186 echo " General type:"
187 echo " info General message"
188 echo " warn Warning message"
189 echo " error Error message"
190 echo " debug Debug message"
192 echo " General options:"
193 echo " -a [name] Specify the app name"
194 echo " -c [character] Specify the character to adjust the label"
195 echo " -l [label] Specify the label."
196 echo " -n | --nocolor No output colored output"
197 echo " -o [option] Specify echo options"
198 echo " -r [color] Specify the color of label"
199 echo " -s [number] Specifies the label space."
200 echo " -x | --bash-debug Enables output bash debugging"
201 echo " -h | --help This help message"
203 echo " --nolabel Do not output label"
204 echo " --noappname Do not output app name"
205 echo " --noadjust Do not adjust the width of the label"
208 while getopts "a:c:l:no:r:s:xh-:" arg; do
214 _adjust_chr="${OPTARG}"
217 _customized_label=true
218 _msg_label="${OPTARG}"
224 _echo_opts="${OPTARG}"
227 _customized_label_color=true
259 _label_space="${OPTARG}"
300 shift $((OPTIND - 1))
325 # You can specify multiple decorations with ;.
326 # 0 => All attributs off (ノーマル)
328 # 4 => Underscore (下線)
330 # 7 => Reverse video on (色反転)
337 [[ "${_customized_label_color}" = false ]] && _labelcolor="32"
338 [[ "${_customized_label}" = false ]] && _msg_label="Info"
344 [[ "${_customized_label_color}" = false ]] && _labelcolor="33"
345 [[ "${_customized_label}" = false ]] && _msg_label="Warning"
351 [[ "${_customized_label_color}" = false ]] && _labelcolor="35"
352 [[ "${_customized_label}" = false ]] && _msg_label="Debug"
358 [[ "${_customized_label_color}" = false ]] && _labelcolor="31"
359 [[ "${_customized_label}" = false ]] && _msg_label="Error"
363 echo "Please specify the message type" >&2
367 echo "Unknown message type" >&2
372 _word_count="${#_msg_label}"
377 if [[ "${_nolabel}" = false ]]; then
378 if [[ "${_noadjust}" = false ]]; then
379 for __time in $( seq 1 $(( ${_label_space} - ${_word_count})) ); do
380 echo -ne "${_adjust_chr}"
383 if [[ "${_nocolor}" = false ]]; then
384 echo -ne "\e[$([[ -v _backcolor ]] && echo -n "${_backcolor}"; [[ -v _labelcolor ]] && echo -n ";${_labelcolor}"; [[ -v _decotypes ]] && echo -n ";${_decotypes}")m${_msg_label}\e[m "
386 echo -ne "${_msg_label} "
392 if [[ "${_noappname}" = false ]]; then
393 if [[ "${_nocolor}" = false ]]; then
394 echo -ne "\e[36m[${_appname}]\e[m "
396 echo -ne "[${_appname}] "
401 for _count in $(seq "1" "$(echo -ne "${_message}\n" | wc -l)"); do
402 _echo_message=$(echo -ne "${_message}\n" |head -n "${_count}" | tail -n 1 )
403 _full_message="$(echo_appname)$(echo_type)${_echo_message}"
406 echo ${_echo_opts} "${_full_message}" >&1
409 echo ${_echo_opts} "${_full_message}" >&2
412 echo ${_echo_opts} "${_full_message}" > ${_output}
424 local _locale="$(echo "${LANG}" | cut -d "." -f 1)"
428 if [[ -z "${*}" ]]; then
431 local _translated_text="$(eval echo '$'{${_locale}[\"${*}\"]})"
433 if [[ -z "${_translated_text}" ]]; then
434 if [[ ! "${_locale}" = "C" ]] && [[ ! "${_locale}" = "en_US" ]]; then
435 echo "$(text -nc cyan "[WFA]") $(text -nc yellow "Warning") (No translation data was found)" 1>&2
439 echo "${_translated_text}"
443 local _text _fulltext=() _main
445 if declare -p "${_locale}" 2> /dev/null 1>/dev/null; then
446 _main="$(_get_text ${1})"
451 echo "$(printf "${_main}" "${@}")"
453 _msg_translate "${@}"
458 # Show an INFO message
461 if [[ "${msgdebug}" = false ]]; then
464 local _msg_opts="-a ${wfa_name}"
465 if [[ "${1}" = "-n" ]]; then
466 _msg_opts="${_msg_opts} -o -n"
469 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
470 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
471 msg ${_msg_opts} info "$(translate "${@}")"
472 if [[ "${bash_debug}" = true ]]; then
477 # Show an Warning message
480 if [[ "${msgdebug}" = false ]]; then
483 local _msg_opts="-a ${wfa_name}"
484 if [[ "${1}" = "-n" ]]; then
485 _msg_opts="${_msg_opts} -o -n"
488 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
489 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
490 msg ${_msg_opts} warn "$(translate "${@}")"
491 if [[ "${bash_debug}" = true ]]; then
496 # Show an debug message
499 if [[ "${msgdebug}" = false ]]; then
502 if [[ "${debug}" = true ]]; then
503 local _msg_opts="-a ${wfa_name}"
504 if [[ "${1}" = "-n" ]]; then
505 _msg_opts="${_msg_opts} -o -n"
508 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
509 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
510 msg ${_msg_opts} debug "$(translate "${@}")"
512 if [[ "${bash_debug}" = true ]]; then
517 # Show an ERROR message then exit with status
519 # $2: exit code number (with 0 does not exit)
521 if [[ "${msgdebug}" = false ]]; then
524 local _msg_opts="-a ${wfa_name}"
525 if [[ "${1}" = "-n" ]]; then
526 _msg_opts="${_msg_opts} -o -n"
529 [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
530 [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
531 msg ${_msg_opts} error "$(translate "${@}")"
532 if [[ "${bash_debug}" = true ]]; then
538 # text [-b/-c color/-n/-f/-l/]
540 local OPTIND OPTARG arg _textcolor _decotypes="" _message _notranslate=false
541 while getopts "c:bnfl" arg; do
575 _decotypes="${_decotypes};1"
578 _decotypes="${_decotypes};5"
581 _decotypes="${_decotypes};4"
588 shift $((OPTIND - 1))
591 if [[ "${_notranslate}" = false ]]; then
592 _message="$(translate "${@}")"
594 if [[ "${nocolor}" = true ]]; then
597 echo -ne "\e[$([[ -v _textcolor ]] && echo -n ";${_textcolor}"; [[ -v _decotypes ]] && echo -n "${_decotypes}")m${_message}\e[m"
601 ######################################################################################
606 # Delete the file if it exists.
607 # For directories, rm -rf is used.
608 # If the file does not exist, skip it.
609 # remove <file> <file> ...
611 local _list=($(echo "$@")) _file
612 for _file in "${_list[@]}"; do
613 msg_debug "Removing ${_file}"
614 if [[ -f "${_file}" ]]; then
616 elif [[ -d "${_file}" ]]; then
623 local _pacman_help=false
628 echo "${wfa_command}"
629 echo "${wfa_command} <operation> [...]"
632 echo " ${wfa_command} {-h --help}"
633 echo " ${wfa_command} {-A --vote}"
634 echo " ${wfa_command} {-V --version}"
635 #echo " ${wfa_command} {-D --database} <options> <package(s)>"
636 #echo " ${wfa_command} {-F --files} [options] [package(s)]"
637 echo " ${wfa_command} {-Q --query} [options] [package(s)]"
638 echo " ${wfa_command} {-R --remove} [options] <package(s)>"
639 echo " ${wfa_command} {-S --sync} [options] [package(s)]"
640 #echo " ${wfa_command} {-T --deptest} [options] [package(s)]"
641 #echo " ${wfa_command} {-U --upgrade} [options] <file(s)>"
643 #echo "New operations:"
644 #echo " ${wfa_command} {-P --show} [options]"
645 #echo " ${wfa_command} {-G --getpkgbuild} [package(s)]"
648 echo " --repo Assume targets are from the repositories"
649 echo " -a --aur Assume targets are from the AUR"
651 echo "Permanent configuration options:"
652 echo " --aururl <url> Set an alternative AUR URL"
653 echo " --makepkg <file> makepkg command to use"
654 echo " --mflags <flags> Pass arguments to makepkg"
655 echo " --pacman <file> pacman command to use"
656 echo " --git <file> git command to use"
657 echo " --gitflags <flags> Pass arguments to git"
658 echo " --gpg <file> gpg command to use"
659 echo " --gpgflags <flags> Pass arguments to gpg"
660 echo " --config <file> pacman.conf file to use"
661 echo " --makepkgconf <file> makepkg.conf file to use"
662 echo " --nomakepkgconf Use the default makepkg.conf"
664 echo "wfa specific options:"
665 echo " -c --clean Remove unneeded dependencies"
667 echo "This program is an alpha version that is not yet stable"
668 echo "If you find a bug, please share it on GitHub"
669 echo "https://github.com/hayao0819/wfa/issues"
673 local _wfa_usage_sync
675 echo "usage: ${wfa_command} {-S --sync} [options] [package(s)]"
677 echo " -b, --dbpath <path> set an alternate database location"
678 echo " -c, --clean remove old packages from cache directory (-cc for all)"
679 echo " -d, --nodeps skip dependency version checks (-dd to skip all checks)"
680 echo " -s, --search <regex> search remote repositories for matching strings"
681 echo " -u, --sysupgrade upgrade installed packages (-uu enables downgrades)"
682 echo " -y, --refresh download fresh package databases from the server"
683 echo " (-yy to force a refresh even if up to date)"
684 echo " --arch <arch> set an alternate architecture"
685 echo " --color <when> colorize the output"
686 echo " --config <path> set an alternate configuration file"
687 echo " --confirm always ask for confirmation"
688 echo " --debug display debug messages"
689 echo " --disable-download-timeout"
690 echo " use relaxed timeouts for download"
691 echo " --noconfirm do not ask for any confirmation"
695 local _wfa_usage_remove
696 _wfa_usage_remove() {
697 echo "usage: ${wfa_command} {-R --remove} [options] <package(s)>"
699 echo " -b, --dbpath <path> set an alternate database location"
700 echo " -d, --nodeps skip dependency version checks (-dd to skip all checks)"
701 echo " -u, --unneeded remove unneeded packages"
702 echo " --arch <arch> set an alternate architecture"
703 echo " --color <when> colorize the output"
704 echo " --config <path> set an alternate configuration file"
705 echo " --confirm always ask for confirmation"
706 echo " --debug display debug messages"
707 echo " --disable-download-timeout"
708 echo " use relaxed timeouts for download"
709 echo " --noconfirm do not ask for any confirmation"
712 if [[ "${operation}" = "none" ]]; then
714 elif [[ "${_pacman_help}" = true ]]; then
715 "${pacman_command}" -h --${operation}
716 elif [[ "$(type -t "_wfa_usage_${operation}" )" = "function" ]]; then
717 _wfa_usage_${operation}
719 msg_error "Help for this operation is not implemented"
725 if [[ "${operation}" = "none" ]]; then
727 add_args pacman "--${operation}"
729 msg_error "only one operation may be used at a time"
735 if (( ${UID} == 0 )); then
743 run_sudo "${pacman_command}" ${@}
751 # https://github.com/FascodeNet/aptpac/blob/master/aptpac のADD_OPTION関数を参考
752 # Usage: add_args [pacman/makepkg/git/gpg/sudo/curl] <args1> <args2>...
760 _args_array=(${makepkg_args})
762 makepkg_args=${_args_array[@]}
763 msg_debug "makepkg ARGS: ${makepkg_args}"
767 _args_array=(${pacman_args})
769 pacman_args=${_args_array[@]}
770 msg_debug "pacman ARGS: ${pacman_args}"
773 _args_array=(${mpg_args})
775 git_args=${_args_array[@]}
776 msg_debug "git ARGS: ${git_args}"
779 _args_array=(${gpg_args})
781 gpg_args=${_args_array[@]}
782 msg_debug "gpg ARGS: ${gpg_args}"
785 _args_array=(${sudo_args})
787 sudo_args=${_args_array[@]}
788 msg_debug "sudo ARGS: ${sudo_args}"
791 _args_array=(${curl_args})
793 curl_args=${_args_array[@]}
794 msg_debug "curl ARGS: ${curl_args}"
797 msg_error "Failed to set the argument of %s" "${_target}"
798 msg_error "Setting that command is not currently supported"
804 # 引数で指定されたパッケージがAUR以外の場所に存在しない場合にのみ正常終了します(AURのパッケージの場合に正常終了)
805 check_aur_package() {
806 local _package="${1}"
807 # 参考: https://qiita.com/Hayao0819/items/a8740a17301fafa2fdab
808 if [[ -z "$(pacman -Ssq "${_package}" 2>/dev/null | grep -o ".*${_package}$")" ]]; then
817 # 引数で指定されたパッケージが既にインストールされている場合は正常終了します。
818 check_installed_package() {
819 local _package="${1}"
820 if "${pacman_command}" -Qq "${_package}" > /dev/null 2>&1; then
827 # ~/.cacheに相当するディレクトリを返します
829 local _user_config_dir _cache_dir
830 if [[ -v XDG_CONFIG_HOME ]]; then
831 _user_config_dir="${XDG_CONFIG_HOME}"
833 _use_config_dir="${HOME}/.config"
835 if [[ -f "${_use_config_dir}/user-dirs.dirs" ]]; then
836 source "${_use_config_dir}/user-dirs.dirs"
838 if [[ -v XDG_CACHE_HOME ]]; then
839 _cache_dir="${XDG_CACHE_HOME}"
841 _cache_dir="${HOME}/.cache"
843 echo -n "${_cache_dir}"
846 # Usage: get_srcinfo_data <path> <var>
847 # 参考: https://qiita.com/withelmo/items/b0e1ffba639dd3ae18c0
849 local _srcinfo="${1}" _ver="${2}"
850 local _srcinfo_json=$(python << EOF
851 from srcinfo.parse import parse_srcinfo; import json
855 parsed, errors = parse_srcinfo(text)
856 print(json.dumps(parsed))
859 echo "${_srcinfo_json}" | jq -rc "${2}" | tr '\n' ' '
863 # AURからパッケージをビルドしてインストールします
864 # 現在1つのパッケージしか指定できません
865 install_aur_package() {
866 local _package="${1}"
869 if [[ ! -v wfa_cache_dir ]]; then
870 wfa_cache_dir="$(get_cache_dir)/wfa"
872 mkdir -p "${wfa_cache_dir}/archive"
873 mkdir -p "${wfa_cache_dir}/build/${_package}"
876 msg_info "Searching in AUR ..."
877 local _aur_json=$("${curl_command}" ${curl_args} -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name&arg=${_package}" | jq -r)
878 if (( "$(echo "${_aur_json}" | jq -r ".resultcount")" == 0 )); then
879 msg_error "Could not find all required packages: %s" "${_package}"
883 local _found_packages="$(echo "${_aur_json}" | jq -r --tab '.results[].Name')"
884 #msg_debug "Found package: $(echo ${_found_packages} | tr '\n' ' ')"
886 if [[ -n "$(echo "${_found_packages}" | grep -x "${_package}" )" ]]; then
887 msg_debug "Select a package %s with an exact name match" "${_package}"
889 msg_error "No package with an exact name match was found"
894 msg_info "Download PKGBUILD of %s" "${_package}"
895 _aur_json=$(echo "${_aur_json}" | jq -r ".results[] | select(.Name == \"${_package}\")" )
896 local _aur_snapshot_url="${aururl%/}$(echo "${_aur_json}" | jq -r ".URLPath")"
897 local _aur_version="$(echo "${_aur_json}" | jq -r ".Version")"
898 msg_debug "Get PKGBUILD from %s" "${_aur_snapshot_url}"
900 local _pkgbuild_archive_path="${wfa_cache_dir}/archive/${_package}-${_aur_version}"
901 local _download_pkgbuild=true
902 if [[ -f "${_pkgbuild_archive_path}" ]]; then
903 msg_warn "PKGBUILD has already been downloaded"
904 msg_warn -n "Do you want to overwrite and download? [n] :"
906 if [[ "${noconfirm}" = true ]]; then
912 case "${_yes_or_no}" in
913 "y" | "Y" | "yes" | "Yes" | "YES" ) _download_pkgbuild=true ;;
914 * ) _download_pkgbuild=false ;;
917 if [[ "${_download_pkgbuild}" = true ]]; then
918 remove "${_pkgbuild_archive_path}"
919 "${curl_command}" ${curl_args} -L -C - -f -o "${_pkgbuild_archive_path}" "${_aur_snapshot_url}"
923 msg_info "Unpacking the tarball of PKGBUILD ..."
924 tar -xv -f "${_pkgbuild_archive_path}" -C "${wfa_cache_dir}/build/" > /dev/null 2>&1
927 local _build_dir="${wfa_cache_dir}/build/${_package}"
928 if [[ ! -f "${_build_dir}/.SRCINFO" ]]; then
929 msg_warn ".SRCINFO was not found.\nGenerating it using makepkg"
932 "${makepkg_command}" --printsrcinfo > "${_build_dir}/.SRCINFO"
936 local _makedepends="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".makedepends[]?")"
937 local _depends="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".depends[]?")"
938 local _conflicts="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".conflicts[]?")"
939 msg_debug "makedepends: %s" "${_makedepends}"
940 msg_debug "depends: %s" "${_depends}"
941 msg_debug "conflicts: %s " "${_conflicts}"
945 local _pkg _conflicts_found=false
946 for _pkg in ${_conflicts[@]}; do
947 if "${pacman_command}" -Qq "${_pkg}" > /dev/null 2>&1 ; then
948 _conflicts_found=true
949 msg_error "${_package} is colliding with ${_pkg}"
952 if "${pacman_command}" -Qq "${_package}" > /dev/null 2>&1 && [[ ! "$("${pacman_command}" -Qq "${_package}" 2> /dev/null)" = "${_package}" ]]; then
953 msg_error "${_package} is colliding with $("${pacman_command}" -Qq "${_package}")"
954 _conflicts_found=true
956 if [[ "${_conflicts_found}" = true ]]; then
957 msg_error "Conflict(s) was found"
963 if [[ "${nodeps}" = false ]]; then
964 msg_info "Install dependent packages..."
965 local _force_aur="${force_aur}"
967 install_package "${_depends}"
968 force_aur="${_force_aur}"
974 if [[ -d "${_build_dir}/src" ]]; then
975 msg_info "Found %s" "${_build_dir}/src"
976 msg_info -n "Packages to cleanBuild? [n] :"
979 if [[ "${noconfirm}" = true ]]; then
985 case "${_yes_or_no}" in
986 "y" | "Y" | "yes" | "Yes" | "YES" ) add_args makepkg "--clean" ;;
992 add_args "makepkg" "-sf"
995 "${makepkg_command}" "${makepkg_args}"
1002 "${makepkg_command}" --printsrcinfo > "${_build_dir}/.SRCINFO"
1004 local _pkgnames=($(get_srcinfo_data "${_build_dir}/.SRCINFO" ".packages | keys[]"))
1005 local _pkgver="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".pkgver" | sed 's/ //g')"
1006 local _pkgrel="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".pkgrel" | sed 's/ //g')"
1007 local _arch_array=($(get_srcinfo_data "${_build_dir}/.SRCINFO" ".arch[]"))
1008 local _arch _pkgname
1009 if [[ "${_arch_array[*]}" = "any" ]]; then
1015 source "${makepkg_config}"
1018 local _pkgfilelist=()
1019 for _pkgname in ${_pkgnames[@]}; do
1020 _pkgfilelist+=("${_build_dir}/${_pkgname}-${_pkgver}-${_pkgrel}-${_arch}${_PKGEXT}")
1024 run_pacman -U --noconfirm ${_pkgfilelist[@]}
1028 search_aur_package() {
1029 local _package="${1}"
1030 #msg_info "Searching in AUR ..."
1031 local _aur_json=$("${curl_command}" ${curl_args} -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name-desc&arg=${_package}" | jq -r )
1032 local _found_result_count="$(echo "${_aur_json}" | jq -r ".resultcount")"
1033 if (( "${_found_result_count}" == 0 )); then
1034 msg_error "Could not find all required packages: %s" "${_package}"
1037 _aur_json=$(echo "${_aur_json}" | jq -r ".results[]")
1039 local _found_pkgname=($(echo "${_aur_json}" | jq -r ".Name" ))
1041 if [[ "${quiet}" = true ]]; then
1044 echo "${_found_pkgname[*]}"
1047 local _found_package __pkgver __popularity __vote __pkgdesc __orphaned __installed __output_text=()
1048 for _found_package in ${_found_pkgname[@]}; do
1051 _found_json="$(echo ${_aur_json} | jq "select(.Name == \"${_found_package}\")")"
1053 #echo "${_found_json}"
1054 __pkgver="$(echo "${_found_json}" | jq -r ".Version" )"
1055 __popularity="$(echo "${_found_json}" | jq -r ".Popularity" )"
1056 __vote="$(echo "${_found_json}" | jq -r ".NumVotes" )"
1057 __pkgdesc="$(echo "${_found_json}" | jq -r ".Description" )"
1060 # 参考: http://www.rivhiro-weather.com/knowledge/?p=536
1061 msg_debug "Row popularity: %s" "${__popularity}"
1062 __popularity="$(printf "%g\n" "${__popularity}" | awk '{printf("%4.2f", $1)}')"
1065 #参考: https://www.366service.com/jp/qa/7c95f46e5236039134ff5b862ae2cd13
1066 if ! echo "${_found_json}" | jq -r --exit-status ".Maintainer" 1> /dev/null 2> /dev/null ; then
1071 if check_installed_package "${_found_package}"; then
1076 "$(text -c blue -b "aur")/$(text -b "${_found_package}") $(text -c cyan "${__pkgver}") (+$(text -b "${__vote} ${__popularity}"))"
1079 if [[ "${__orphaned}" = true ]]; then
1080 __output_text+=("$(text -bc red "(Orphaned)")")
1083 if [[ "${__installed}" = true ]]; then
1084 __output_text+=("$(text -bc cyan "[Installed]")")
1086 echo "${__output_text[*]}"
1087 echo " ${__pkgdesc}"
1088 unset __pkgver __popularity __vote __pkgdesc _found_json __orphaned __installed __output_text
1094 operation_version() {
1095 # Pyalpmからlibalpmの値を取得
1096 # 参考: https://pyalpm.readthedocs.io/en/latest/pyalpm/pyalpm.html
1097 local _libalpm_version="$(python3 -c 'import pyalpm; print(pyalpm.alpmversion())')"
1098 local _pacman_version="$("${pacman_command}" -Q pacman | cut -d ' ' -f 2)"
1099 echo "wfa v${wfa_version} - pacman v${_pacman_version} - libalpm v${_libalpm_version}"
1102 operation_remove() {
1103 run_pacman ${pacman_args} "${specified_packages[@]}"
1106 # Usage: install_package <package1> <package2>...
1108 local _package _repo_packages=() _aur_packages=()
1109 for _package in ${@}; do
1110 if ! check_installed_package "${_package}"; then
1111 if ! check_aur_package "${_package}"; then
1112 # 公式パッケージなのでpacmanでそのままインストール
1113 _repo_packages+=("${_package}")
1116 _aur_packages+=("${_package}")
1121 if (( "${#_repo_packages[@]}" > 0 )); then
1122 run_pacman --asdeps ${pacman_args} "${_repo_packages[@]}"
1125 if (( "${#_aur_packages[@]}" > 0 )); then
1127 for _package in ${_aur_packages[@]}; do
1128 install_aur_package "${_package}"
1133 upgrade_aur_package() {
1135 msg_error "This is a feature that has not been implemented yet"
1140 if (( "${sync_clean_count}" >= 1 )); then
1141 remove "$(get_cache_dir)/wfa"
1142 run_pacman ${pacman_args} $(
1144 for _count in $(seq 1 ${sync_clean_count}); do
1151 if [[ "${sync_search}" = true ]]; then
1152 for _package in ${specified_packages[@]}; do
1153 search_aur_package "${_package}"
1155 "${pacman_command}" ${pacman_args} ${specified_packages[@]} || :
1157 if [[ "${sync_upgrade}" = true ]]; then
1159 run_pacman ${pacman_args} --sysupgrade
1161 for _package in ${specified_packages[@]}; do
1162 if ! check_aur_package "${_package}" && [[ "${force_aur}" = false ]]; then
1163 # 公式パッケージなのでpacmanでそのままインストール
1164 run_pacman ${pacman_args} "${_package}"
1167 install_aur_package "${_package}"
1168 #msg_error "Getting the AUR package has not been implemented yet."
1179 if ! type aurvote 1> /dev/null 2> /dev/null; then
1180 msg_error "There is no aurvote"
1181 msg_error "Please install with %s" "\"wfa -S aurvote\""
1185 local _package _aur_json _found_result_count _pkgver _before_popularity _before_vote
1186 for _package in ${specified_packages[@]}; do
1189 _aur_json=$("${curl_command}" ${curl_args} -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name-desc&arg=${_package}" | jq -r)
1190 _found_result_count="$(echo "${_aur_json}" | jq -r ".resultcount")"
1191 _aur_json=$(echo "${_aur_json}" | jq -r ".results[] | select(.Name == \"${_package}\")")
1192 if (( "${_found_result_count}" == 0 )) || [[ -z "${_aur_json}" ]]; then
1193 msg_error "Package not found on AUR: %s" "${_package}"
1198 _pkgver="$(echo "${_aur_json}" | jq -r ".Version" )"
1199 _before_popularity="$(printf "%g\n" "$(echo "${_aur_json}" | jq -r ".Popularity" )" | awk '{printf("%4.2f", $1)}')"
1200 _before_vote="$(echo "${_aur_json}" | jq -r ".NumVotes" )"
1203 if [[ "$(aurvote --check "${_package}")" = "not voted" ]]; then
1204 msg_info "Voted for %s" "${_package}"
1205 aurvote --vote "${_package}" 1> /dev/null
1207 msg_info "Unvoted for %s" "${_package}"
1208 aurvote --unvote "${_package}" 1> /dev/null
1212 _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}\")")
1213 _after_popularity="$(printf "%g\n" "$(echo "${_aur_json}" | jq -r ".Popularity" )" | awk '{printf("%4.2f", $1)}')"
1214 _after_vote="$(echo "${_aur_json}" | jq -r ".NumVotes" )"
1217 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}")"
1221 unavailable_in_this_operation() {
1222 msg_error "This option is not available in the current operation"
1228 local _operation="${1}"
1229 msg_debug "Operation: ${_operation}"
1231 msg_warn "This program is an alpha version that is not yet stable\nIf you find a bug, please share it on GitHub\nhttps://github.com/hayao0819/wfa/issues"
1235 operation_${_operation}
1240 _opt_short="AQRShVdb:aysucq"
1241 _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:,unneeded,puella"
1243 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT})
1244 [[ ${?} != 0 ]] && exit 1
1245 unset _opt_short _opt_long
1247 eval set -- "${OPT}"
1248 msg_debug "Argument: ${OPT}"
1253 set_operation "vote"
1257 set_operation "query"
1261 set_operation "remove"
1265 set_operation "sync"
1269 set_operation "version"
1282 eval set -- "${OPT}"
1288 msg_debug "Assume targets are from the AUR"
1293 add_args pacman "--debug"
1298 add_args pacman "--nodeps"
1302 add_args pacman "--dbpath '${2}'"
1306 option_y_count=$(( option_y_count + 1 ))
1310 add_args pacman "--search"
1314 -u | --sysupgrade | --unneeded)
1317 if [[ "${operation}" = "sync" ]]; then
1320 unavailable_in_this_operation
1324 if [[ "${operation}" = "remove" ]]; then
1325 add_args pacman "--unneeded"
1327 unavailable_in_this_operation
1331 case "${operation}" in
1336 add_args pacman "--unneeded"
1342 unavailable_in_this_operation
1350 sync_clean_count=$(( sync_clean_count + 1 ))
1355 add_args pacman "--quiet"
1360 add_args pacman "--arch ${2}"
1368 add_args pacman "--noconfirm"
1373 pacman_config="${2}"
1374 add_args pacman "--config ${2}"
1378 makepkg_command="${2}"
1382 #makepkg_args="${2}"
1383 add_args makepkg "${2}"
1387 pacman_command="${2}"
1400 if [[ "${nomakepkgconf}" = false ]]; then
1401 makepkg_config="${2}"
1403 msg_warn "--nomakepkgconf is specified.\n--makepkgconf has been ignored."
1408 makepkg_config="/etc/makepkg.conf"
1425 add_args pacman "--color never"
1429 add_args pacman "--color always"
1432 msg_error "auto is not currently supported."
1433 add_args pacman "--color auto"
1439 add_args pacman "--color never"
1446 --disable-download-timeout)
1447 add_args curl "--max-time 0"
1448 add_args pacman "--disable-download-timeout"
1456 add_args curl "${2}"
1460 text -flb "Please make a contract with me and become a Puella Magi !"
1480 specified_packages=(${@})
1482 # Run database update
1483 if (( "${option_y_count}" == 1 )); then
1485 elif (( "${option_y_count}" >= 2 )); then
1489 # set_operationで設定された操作を実行
1490 case "${operation}" in
1491 "version" | "sync" | "remove" | "vote")
1492 run_operation "${operation}"
1498 msg_error "Undefined operation"