• R/O
  • HTTP
  • SSH
  • HTTPS

aptpac: コミット

GitHubのミラーです
https://github.com/FascodeNet/aptpac


コミットメタ情報

リビジョン48b17b9ba30c2413a0f6ebeb0ef3adc81a8359e1 (tree)
日時2021-04-24 15:21:30
作者hayao <hayao@fasc...>
コミッターhayao

ログメッセージ

[clean] : Separation of processing by function

変更サマリ

差分

--- a/aptpac
+++ b/aptpac
@@ -18,8 +18,9 @@
1818 # If it is empty, the corresponding AUR helper will be searched automatically.
1919 #AURHELPER=
2020
21-
2221 set -e
22+
23+
2324 APTPAC_VERSION="3.3.0"
2425 PACMAN_OPTIONS=()
2526 HELPERS=(
@@ -38,7 +39,7 @@ PACMAN_CONFIG="/etc/pacman.conf"
3839 DEBUG=false
3940 RUN_WITH_SUDO=false
4041
41-direct_option=false
42+DIRECT_PACMAN=false
4243 autoremove=false
4344
4445 _msg_error () {
@@ -51,29 +52,6 @@ _msg_debug () {
5152 fi
5253 }
5354
54-if [[ ! "${UID}" = 0 ]]; then
55- if [[ -z "${AURHELPER+SET}" ]]; then
56- for AURHELPER in "${HELPERS[@]}"; do
57- if [[ -f "${AURHELPER}" ]]; then
58- PACMAN_COMMAND="${AURHELPER}"
59- break
60- elif hash "$(basename "${AURHELPER}")" 2> /dev/null; then
61- PACMAN_COMMAND="$(basename "${AURHELPER}")"
62- break
63- fi
64- done
65- else
66- if [[ -f "${AURHELPER}" ]]; then
67- PACMAN_COMMAND="${AURHELPER}"
68- elif hash "$(basename "${AURHELPER}")" 2> /dev/null; then
69- PACMAN_COMMAND="$(basename "${AURHELPER}")"
70- else
71- _msg_error "${AURHELPER} is not installed"
72- exit 1
73- fi
74- fi
75-fi
76-
7755
7856 # List option
7957 installed=false
@@ -109,7 +87,9 @@ _usage () {
10987 echo " Ignored if pacapt is run as root"
11088 echo " Specify AUR helper that supports common command line options with pacman"
11189 echo
112- echo " aptpac supports not only above options but also options of pacman"
90+ echo " Notes:"
91+ echo " - aptpac supports not only above options but also options of pacman"
92+ echo " - If you specify the deb file, you can install using debtap"
11393 }
11494
11595 _exit () {
@@ -122,15 +102,71 @@ aptpac ${APTPAC_VERSION} - A pacman wrapper with syntax based on debian's apt
122102 License: Do What The Fuck You Want To Public License
123103 (c) 2019-2020 Fascode Network. Yamada Hayao
124104 EOF
125-echo
126-pacman --version
105+ echo
106+ pacman --version
127107 }
128108
129-
130109 ADD_OPTION () {
131110 PACMAN_OPTIONS+=("${@}")
132111 }
133112
113+_sudo(){
114+ if "${RUN_WITH_SUDO}"; then
115+ eval sudo "${@}"
116+ else
117+ eval "${@}"
118+ fi
119+}
120+
121+_run_detect_aur_helper(){
122+ if [[ ! "${UID}" = 0 ]]; then
123+ if [[ -z "${AURHELPER+SET}" ]]; then
124+ for AURHELPER in "${HELPERS[@]}"; do
125+ if [[ -f "${AURHELPER}" ]]; then
126+ PACMAN_COMMAND="${AURHELPER}"
127+ break
128+ elif hash "$(basename "${AURHELPER}")" 2> /dev/null; then
129+ PACMAN_COMMAND="$(basename "${AURHELPER}")"
130+ break
131+ fi
132+ done
133+ else
134+ if [[ -f "${AURHELPER}" ]]; then
135+ PACMAN_COMMAND="${AURHELPER}"
136+ elif hash "$(basename "${AURHELPER}")" 2> /dev/null; then
137+ PACMAN_COMMAND="$(basename "${AURHELPER}")"
138+ else
139+ _msg_error "${AURHELPER} is not installed"
140+ exit 1
141+ fi
142+ fi
143+ fi
144+}
145+
146+_run_aur_message(){
147+ if [[ ! "${PACMAN_COMMAND}" = "${DEFAULT_PACMAN_COMMAND}" ]] && [[ ! "$(basename "${PACMAN_COMMAND}")" = "$(basename "${DEFAULT_PACMAN_COMMAND}")" ]]; then
148+ _msg_debug "Use AUR helper ${PACMAN_COMMAND}"
149+ else
150+ RUN_WITH_SUDO=true
151+ fi
152+}
153+
154+_run_autoremove(){
155+ if "${autoremove}"; then
156+ if [[ -n $(${PACMAN_COMMAND} -Qttdq) ]]; then
157+ "${PACMAN_COMMAND}" -Qttdq | _sudo "${PACMAN_COMMAND}" -Rsc --config "${PACMAN_CONFIG}" -
158+ else
159+ echo "No packages to remove"
160+ exit 0
161+ fi
162+ fi
163+}
164+
165+_run_pacman(){
166+ _sudo "${PACMAN_COMMAND}" "${PACMAN_OPTIONS[@]}" --config "${PACMAN_CONFIG}" "${PACKAGE[@]}"
167+}
168+
169+
134170 # Argument analysis and processing
135171 set +e
136172 PACAPT_ARGUMENTS=("${@}")
@@ -203,7 +239,7 @@ while true; do
203239 shift 2
204240 ;;
205241 -V | -D | -F | -Q | -R | -S | -T | -U)
206- direct_option=true
242+ DIRECT_PACMAN=true
207243 ADD_OPTION "${PACAPT_ARGUMENTS[@]}"
208244 break
209245 ;;
@@ -219,7 +255,7 @@ while true; do
219255 esac
220256 done
221257
222-if [[ "${direct_option}" = false ]]; then
258+if [[ "${DIRECT_PACMAN}" = false ]]; then
223259 if [[ $# -lt 1 ]]; then
224260 _msg_error "No command specified"
225261 _usage
@@ -307,9 +343,9 @@ if [[ "${direct_option}" = false ]]; then
307343 show | showpkg)
308344 for pkg in "${PACKAGE[@]}"; do
309345 if pacman -Qq "${pkg}" 2> /dev/null 1>&2; then
310- ${PACMAN_COMMAND} "${PACMAN_OPTIONS[@]}" -Qi --config "${PACMAN_CONFIG}" "${pkg}"
346+ "${PACMAN_COMMAND}" "${PACMAN_OPTIONS[@]}" -Qi --config "${PACMAN_CONFIG}" "${pkg}"
311347 else
312- ${PACMAN_COMMAND} "${PACMAN_OPTIONS[@]}" -Si --config "${PACMAN_CONFIG}" "${pkg}"
348+ "${PACMAN_COMMAND}" "${PACMAN_OPTIONS[@]}" -Si --config "${PACMAN_CONFIG}" "${pkg}"
313349 fi
314350 done
315351 unset pkg
@@ -329,27 +365,8 @@ if [[ "${direct_option}" = false ]]; then
329365 esac
330366 fi
331367
332-if [[ ! "${PACMAN_COMMAND}" = "${DEFAULT_PACMAN_COMMAND}" ]] && [[ ! "$(basename "${PACMAN_COMMAND}")" = "$(basename "${DEFAULT_PACMAN_COMMAND}")" ]]; then
333- _msg_debug "Use AUR helper ${PACMAN_COMMAND}"
334-else
335- RUN_WITH_SUDO=true
336-fi
337-
338-_sudo(){
339- if "${RUN_WITH_SUDO}"; then
340- eval sudo "${@}"
341- else
342- eval "${@}"
343- fi
344-}
345-
346-_sudo "${PACMAN_COMMAND}" "${PACMAN_OPTIONS[@]}" --config "${PACMAN_CONFIG}" "${PACKAGE[@]}"
347368
348-if "${autoremove}"; then
349- if [[ -n $(${PACMAN_COMMAND} -Qttdq) ]]; then
350- "${PACMAN_COMMAND}" -Qttdq | _sudo "${PACMAN_COMMAND}" -Rsc --config "${PACMAN_CONFIG}" -
351- else
352- echo "No packages to remove"
353- exit 0
354- fi
355-fi
369+_run_detect_aur_helper
370+_run_aur_message
371+_run_pacman
372+_run_autoremove
旧リポジトリブラウザで表示