5 # Email : hayao@fascode.net
7 # (c) 2019-2020 Fascode Network.
11 script_name=$(basename ${0})
13 script_path="$(readlink -f ${0%/*})"
25 echo "usage ${0} [options] [packages] [packages] ..."
27 echo " General options:"
29 echo " -a | --arch <arch> Specify the architecture"
30 echo " -f | --force Overwrite existing directory"
31 echo " -s | --skip Skip if PKGBUILD already exists"
32 echo " -r | --repo <repo> Specify the repository name"
33 echo " -h | --help This help messageExecuted via administrator web and Yama D Saba APIs"
35 if [[ -n "${1:-}" ]]; then
42 # usage: echo_color -b <backcolor> -t <textcolor> -d <decoration> [Text]
65 # You can specify multiple decorations with ;.
66 # 0 => All attributs off (ノーマル)
68 # 4 => Underscore (下線)
70 # 7 => Reverse video on (色反転)
84 while getopts 'b:t:d:n' arg; do
86 b) backcolor="${OPTARG}" ;;
87 t) textcolor="${OPTARG}" ;;
88 d) decotypes="${OPTARG}" ;;
89 n) echo_opts="-n -e" ;;
95 echo ${echo_opts} "\e[$([[ -v backcolor ]] && echo -n "${backcolor}"; [[ -v textcolor ]] && echo -n ";${textcolor}"; [[ -v decotypes ]] && echo -n ";${decotypes}")m${*}\e[m"
99 # Show an INFO message
106 while getopts 'n' arg; do
108 n) echo_opts="${echo_opts} -n" ;;
111 shift $((OPTIND - 1))
112 if [[ "${nocolor}" = true ]]; then
113 echo ${echo_opts} "[${script_name}] Info ${*}"
115 echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]") $( echo_color -t '32' 'Info') ${*}"
120 # Show an Warning message
127 while getopts 'n' arg; do
129 n) echo_opts="${echo_opts} -n" ;;
132 shift $((OPTIND - 1))
133 if [[ "${nocolor}" = true ]]; then
134 echo ${echo_opts} "[${script_name}] Warning ${*}"
136 echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]") $( echo_color -t '33' 'Warning') ${*}" >&2
141 # Show an debug message
148 while getopts 'n' arg; do
150 n) echo_opts="${echo_opts} -n" ;;
153 shift $((OPTIND - 1))
154 if [[ "${debug}" = true ]]; then
155 if [[ "${nocolor}" = true ]]; then
156 echo ${echo_opts} "[${script_name}] Debug ${*}"
158 echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]") $( echo_color -t '35' 'Debug') ${*}"
164 # Show an ERROR message then exit with status
166 # $2: exit code number (with 0 does not exit)
173 while getopts 'n' arg; do
175 n) echo_opts="${echo_opts} -n" ;;
178 shift $((OPTIND - 1))
179 if [[ "${nocolor}" = true ]]; then
180 echo ${echo_opts} "[${script_name}] Error ${1}"
182 echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]") $( echo_color -t '31' 'Error') ${1}" >&2
184 if [[ -n "${2:-}" ]]; then
190 # Delete the file if it exists.
191 # For directories, rm -rf is used.
192 # If the file does not exist, skip it.
193 # remove <file> <file> ...
198 for _file in "${_list[@]}"; do
199 if [[ -f ${_file} ]]; then
200 _msg_debug "Removeing ${_file}"
202 elif [[ -d ${_file} ]]; then
203 _msg_debug "Removeing ${_file}"
210 if [[ -z "${@}" ]]; then
214 _opt_short="h,r:,a:sf"
215 _opt_long="help,repo:,arch:,skip,force,nocolor"
217 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
218 if [[ ${?} != 0 ]]; then
258 _msg_error "Invalid argument '${1}'"
267 if [[ "${force}" = true ]]; then
268 rm -rf "${script_path}/${repo}/${arch}/${pkg}"
269 elif [[ -d "${script_path}/${repo}/${arch}/${pkg}" ]]; then
270 _msg_error "${pkg} has already been added."
271 if [[ "${skip}" = true ]]; then
277 mkdir -p "${script_path}/${repo}/${arch}/${pkg}"
278 git clone "https://aur.archlinux.org/${pkg}.git" "${script_path}/${repo}/${arch}/${pkg}"
279 rm -rf "${script_path}/${repo}/${arch}/${pkg}/.git"