#!/usr/bin/env bash
+#
+# 1. Author info
+#
+# Yamada Hayao
+# Twitter: @Hayao0819
+# Email : hayao@fascode.net
+#
+# (c) 2019-2020 Fascode Network.
+#
+# 2. Overview
+#
+# Wfa is a multilingual AUR helper written in bash that is being developed to replace yaourt
+#
+# 3. License
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+#
+# Everyone is permitted to copy and distribute verbatim or modified
+# copies of this license document, and changing it is allowed as long
+# as the name is changed.
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#
+#
set -eu
["only one operation may be used at a time"]="一度に使用できるオペレーションは1つだけです"
["Failed to set the argument of %s"]="%sの引数の設定に失敗しました"
["Setting that command is not currently supported"]="そのコマンドの設定は現在サポートされていません"
- ["Install dependent packages..."]="依存パッケージをインストールします..."
+ ["Searching in AUR ..."]="AUR内を検索しています..."
["No package with an exact name match was found"]="完全に一致する名前のパッケージが見つかりませんでした"
["Select a package %s with an exact name match"]="名前が完全に一致するパッケージ %s を選択します"
["Download PKGBUILD of %s"]="%s のPKGBUILDをダウンロード"
["PKGBUILD has already been downloaded"]="PKGBUILDは既にダウンロードされています"
["Do you want to overwrite and download? [n] :"]="上書きダウンロードしますか? [n] :"
["Unpacking the tarball of PKGBUILD ..."]="PKGBUILDを展開しています ..."
+ [".SRCINFO was not found.\nGenerating it using makepkg"]=".SCRINFOが見つかりませんでした。makepkgを使用して生成しています"
+ ["Conflict(s) was found"]="衝突が見つかりました"
+ ["Install dependent packages..."]="依存パッケージをインストールします..."
+ ["Found %s"]="%s を見つけました"
+ ["Packages to cleanBuild? [n] :"]="パッケージをクリーンビルドしますか? [n] :"
+ ["Could not find all required packages:\n %s"]="必要なすべてのパッケージが見つかりませんでした %s"
+ ["This is a feature that has not been implemented yet"]="まだ実装されていない機能です"
+ ["(Orphaned)"]="(メンテナ不在)"
+ ["[Installed]"]="[インストール済み]"
["This is a feature that has not been implemented yet"]="まだ実装されていない機能です"
)
######################################################################################
#-- options (int) --#
option_y_count=0
+sync_clean_count=0
#-- options (str) --#
aururl="https://aur.archlinux.org/"
local _output="stdout"
_help() {
- echo "usage ${0} [option] [type] [message]"
+ echo "usage msg [option] [type] [message]"
echo
echo "Display a message with a colored app name and message type label"
echo
_main="${1}"
fi
shift 1
- echo "$(printf "${_main}" ${@})"
+ echo "$(printf "${_main}" "${@}")"
}
_msg_translate "${@}"
}
fi
}
+text() {
+ local OPTIND OPTARG arg _textcolor _decotypes=() _message
+ while getopts "c:b" arg; do
+ case ${arg} in
+ c)
+ case "${OPTARG}" in
+ "black")
+ _textcolor="30"
+ ;;
+ "red")
+ _textcolor="31"
+ ;;
+ "green")
+ _textcolor="32"
+ ;;
+ "yellow")
+ _textcolor="33"
+ ;;
+ "blue")
+ _textcolor="34"
+ ;;
+ "magenta")
+ _textcolor="35"
+ ;;
+ "cyan")
+ _textcolor="36"
+ ;;
+ "white")
+ _textcolor="37"
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+ ;;
+ b)
+ _decotypes+=(1)
+ ;;
+ esac
+ done
+ shift $((OPTIND - 1))
+
+ _message="${@}"
+ _message="$(translate "${@}")"
+ if [[ "${nocolor}" = true ]]; then
+ echo -ne "${@}"
+ else
+ echo -ne "\e[$([[ -v _textcolor ]] && echo -n ";${_textcolor}"; [[ -v _decotypes ]] && echo -n ";${_decotypes}")m${_message}\e[m"
+ fi
+}
+
######################################################################################
# ここから実際の処理開始
# ここから下のメッセージは翻訳可能です
fi
}
+# ~/.cacheに相当するディレクトリを返します
get_cache_dir() {
- local _user_config_dir
+ local _user_config_dir _cache_dir
if [[ -v XDG_CONFIG_HOME ]]; then
_user_config_dir="${XDG_CONFIG_HOME}"
else
source "${_use_config_dir}/user-dirs.dirs"
fi
if [[ -v XDG_CACHE_HOME ]]; then
- echo -n "${XDG_CACHE_HOME}"
- return 0
+ _cache_dir="${XDG_CACHE_HOME}"
else
- echo -n "${HOME}/.cache"
- return 0
+ _cache_dir="${HOME}/.cache"
fi
+ echo -n "${_cache_dir}"
}
# Usage: get_srcinfo_data <path> <var>
mkdir -p "${wfa_cache_dir}/build/${_package}"
# AurJsonから値を取得
+ msg_info "Searching in AUR ..."
local _aur_json=$(curl -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name&arg=${_package}" | jq -r)
if (( "$(echo "${_aur_json}" | jq -r ".resultcount")" == 0 )); then
msg_error "Could not find all required packages:\n ${_package}"
fi
# PKGBUILDを展開
- msg_info "Unpacking the tarball of PKGBUILD ..." #ここまで翻訳
+ msg_info "Unpacking the tarball of PKGBUILD ..."
tar -xv -f "${_pkgbuild_archive_path}" -C "${wfa_cache_dir}/build/" > /dev/null 2>&1
# .SRCINFOを解析
local _build_dir="${wfa_cache_dir}/build/${_package}"
if [[ ! -f "${_build_dir}/.SRCINFO" ]]; then
- msg_warn ".SRCINFO was not found.\nGenerate it using makepkg."
+ msg_warn ".SRCINFO was not found.\nGenerating it using makepkg"
(
cd "${_build_dir}"
"${makepkg_command}" --printsrcinfo > "${_build_dir}/.SRCINFO"
local _makedepends="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".makedepends[]?")"
local _depends="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".depends[]?")"
local _conflicts="$(get_srcinfo_data "${_build_dir}/.SRCINFO" ".conflicts[]?")"
- msg_debug "makedepends: ${_makedepends}"
- msg_debug "depends: ${_depends}"
- msg_debug "conflicts: ${_conflicts}"
+ msg_debug "makedepends: %s" "${_makedepends}"
+ msg_debug "depends: %s" "${_depends}"
+ msg_debug "conflicts: %s " "${_conflicts}"
# 衝突を確認
_conflicts_found=true
fi
if [[ "${_conflicts_found}" = true ]]; then
- msg_error "A conflict was found."
+ msg_error "Conflict(s) was found"
exit 1
fi
# ビルド準備
# srcdirの確認
if [[ -d "${_build_dir}/src" ]]; then
- msg_info "Found ${_build_dir}/src"
- msg_info "Packages to cleanBuild? [n] :"
+ msg_info "Found %s" "${_build_dir}/src"
+ msg_info -n "Packages to cleanBuild? [n] :"
local _yes_or_no
unset _yes_or_no
if [[ "${noconfirm}" = true ]]; then
# AURのパッケージを検索
search_aur_package() {
local _package="${1}"
+ #msg_info "Searching in AUR ..."
local _aur_json=$(curl -sL "https://aur.archlinux.org/rpc/?v=5&type=search&by=name-desc&arg=${_package}" | jq -r )
local _found_result_count="$(echo "${_aur_json}" | jq -r ".resultcount")"
if (( "${_found_result_count}" == 0 )); then
- msg_error "Could not find all required packages:\n ${_package}"
+ msg_error "Could not find all required packages:\n %s" "${_package}"
exit 1
fi
_aur_json=$(echo "${_aur_json}" | jq -r ".results[]")
- #echo ${_aur_json}
-
local _found_pkgname=($(echo "${_aur_json}" | jq -r ".Name" ))
-
-
-
- local _found_package __pkgver __popularity __vote __pkgdesc
+ local _found_package __pkgver __popularity __vote __pkgdesc __orphaned __installed __output_text=()
for _found_package in ${_found_pkgname[@]}; do
+ __orphaned=false
+ __installed=false
_found_json="$(echo ${_aur_json} | jq "select(.Name == \"${_found_package}\")")"
+
+ #echo "${_found_json}"
__pkgver="$(echo "${_found_json}" | jq -r ".Version" )"
__popularity="$(echo "${_found_json}" | jq -r ".Popularity" )"
__vote="$(echo "${_found_json}" | jq -r ".NumVotes" )"
__pkgdesc="$(echo "${_found_json}" | jq -r ".Description" )"
-
- echo "aur/${_found_package} ${__pkgver} (+${__vote} ${__popularity})"
+
+ # 人気度の少数2位以下を四捨五入
+ # 参考: http://www.rivhiro-weather.com/knowledge/?p=536
+ msg_debug "Row popularity: %s" "${__popularity}"
+ __popularity="$(printf "%g\n" "${__popularity}" | awk '{printf("%4.2f", $1)}')"
+
+ # 孤児判定
+ #参考: https://www.366service.com/jp/qa/7c95f46e5236039134ff5b862ae2cd13
+ if ! echo "${_found_json}" | jq -r --exit-status ".Maintainer" 1> /dev/null 2> /dev/null ; then
+ __orphaned=true
+ fi
+
+ # インストール済み判定
+ if check_installed_package "${_found_package}"; then
+ __installed=true
+ fi
+
+ __output_text+=(
+ "$(text -c blue -b "aur")/$(text -b "${_found_package}") $(text -c cyan "${__pkgver}") (+$(text -b "${__vote} ${__popularity}"))"
+ )
+
+ if [[ "${__orphaned}" = true ]]; then
+ __output_text+=("$(text -bc red "(Orphaned)")")
+ fi
+
+ if [[ "${__installed}" = true ]]; then
+ __output_text+=("$(text -bc cyan "[Installed]")")
+ fi
+ echo "${__output_text[*]}"
echo " ${__pkgdesc}"
- unset __pkgver __popularity __vote __pkgdesc _found_json
+ unset __pkgver __popularity __vote __pkgdesc _found_json __orphaned __installed __output_text
done
}
}
upgrade_aur_package() {
+ #ここまで翻訳
msg_error "This is a feature that has not been implemented yet"
}
operation_sync(){
local _package
+ if (( "${sync_clean_count}" >= 1 )); then
+ remove "$(get_cache_dir)/wfa"
+ run_pacman ${pacman_args} $(
+ local _count
+ for _count in $(seq 1 ${sync_clean_count}); do
+ echo -n "-c "
+ done
+ )
+ fi
+
+
if [[ "${sync_search}" = true ]]; then
for _package in ${specified_packages[@]}; do
search_aur_package "${_package}"
done
- "${pacman_command}" ${pacman_args} ${specified_packages[@]}
+ "${pacman_command}" ${pacman_args} ${specified_packages[@]} || :
else
if [[ "${sync_upgrade}" = true ]]; then
upgrade_aur_package
# Parse options
ARGUMENT="${@}"
-_opt_short="QRShVdb:aysu"
-_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"
+_opt_short="QRShVdb:aysuc"
+_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"
OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT})
[[ ${?} != 0 ]] && exit 1
sync_upgrade=true
shift 1
;;
+ -c | --clean)
+ sync_clean_count=$(( sync_clean_count + 1 ))
+ shift 1
+ ;;
--aururl)
aururl="${2}"
shift 2
;;
--config)
pacman_config="${2}"
- add_args pacman "--config \"${2}\""
+ add_args pacman "--config ${2}"
shift 2
;;
--makepkg)
msgdebug=true
shift 1
;;
+ --color)
+ case "${2}" in
+ "never")
+ nocolor=true
+ add_args pacman "--color never"
+ ;;
+ "always")
+ nocolor=false
+ add_args pacman "--color always"
+ ;;
+ "auto")
+ msg_error "auto is not currently supported."
+ add_args pacman "--color auto"
+ ;;
+ esac
+ ;;
+ --nocolor)
+ nocolor=true
+ add_args pacman "--color never"
+ shift 1
+ ;;
-h | --help)
usage
shift 1