5 # __ _____\ \ ,_\ _____ __ ___
6 # /'__`\ /\ '__`\ \ \//\ '__`\ /'__`\ /'___\
7 #/\ \L\.\\ \ \L\ \ \ \\ \ \L\ /\ \L\.\_/\ \__/
8 #\ \__/.\_\ \ ,__/\ \__\ \ ,__\ \__/.\_\ \____\
9 # \/__/\/_/\ \ \/ \/__/\ \ \/ \/__/\/_/\/____/
12 # a pacman wrapper with syntax based on debian's apt
13 # (c) 2019-2020 Fascode Network.
14 # License: Do What The Fuck You Want To Public License
15 # maintained by Yamada Hayao
17 # Enter the path to the AUR helper you want to use here.
18 # If it is empty, the corresponding AUR helper will be searched automatically.
25 APTPAC_VERSION="3.3.0"
28 PACMAN_PACKAGE_FILE=()
44 DEFAULT_PACMAN_COMMAND="/usr/bin/pacman"
45 PACMAN_COMMAND="${DEFAULT_PACMAN_COMMAND}"
46 PACMAN_CONFIG="/etc/pacman.conf"
49 DEBTAP_WORK="/tmp/aptpac-debtap"
72 INSTALLED_PKGLIST=false
75 echo "usage ${0} [options] [command] [packages]"
78 echo " install Install the specified package"
79 echo " remove Remove the specified package"
80 echo " purge Permanently remove the package"
81 echo " update Update package database"
82 echo " upgrade | full-upgrade Update packages"
83 echo " edit-sources Edit config file of pacman"
84 echo " search Search for a package"
85 echo " autoremove Remove unnecessary packages"
86 echo " clean Remove the package cache"
87 echo " list Display a list of packages"
88 echo " show | showpkg Display the package records"
89 echo " rdepends Display the dependencies"
92 echo " -y | --yes | --assume-yes Do not check"
93 echo " -d | --download-only Only download the package"
94 echo " -c | --config-file <file> Config file for pacman"
95 echo " -h | --help Display this help"
96 echo " -v | --version Display the version of aptpac and pacman"
97 echo " --auto-remove | --autoremove Remove unnecessary packages with other command"
98 echo " --purge Delete the entire configuration file"
100 echo " pacapt options:"
101 echo " --aur-helper <command> Specifies the command to use as the AUR helper"
102 echo " Ignored if pacapt is run as root"
103 echo " Specify AUR helper that supports common command line options with pacman"
104 echo " --pflags <flags> Pass arguments to pacman"
107 echo " - aptpac supports not only above options but also options of pacman"
108 echo " - If you specify the deb file, you can install using debtap"
117 aptpac ${APTPAC_VERSION} - A pacman wrapper with syntax based on debian's apt
118 License: Do What The Fuck You Want To Public License
119 (c) 2019-2020 Fascode Network. Yamada Hayao
126 _msg_debug "Added pacman option '${*}'"
127 PACMAN_OPTIONS+=("${@}")
131 if "${RUN_WITH_SUDO}"; then
132 _msg_debug "Run sudo ${*}"
135 _msg_debug "Run ${*}"
141 _sudo "${PACMAN_COMMAND}" "${PACMAN_OPTIONS[@]}" --config "${PACMAN_CONFIG}" "${@}"
144 _run_detect_aur_helper(){
145 if [[ ! "${UID}" = 0 ]]; then
146 if [[ -z "${AURHELPER+SET}" ]]; then
147 for AURHELPER in "${HELPERS[@]}"; do
148 if [[ -f "${AURHELPER}" ]]; then
149 PACMAN_COMMAND="${AURHELPER}"
151 elif hash "$(basename "${AURHELPER}")" 2> /dev/null; then
152 PACMAN_COMMAND="$(basename "${AURHELPER}")"
157 if [[ -f "${AURHELPER}" ]]; then
158 PACMAN_COMMAND="${AURHELPER}"
159 elif hash "$(basename "${AURHELPER}")" 2> /dev/null; then
160 PACMAN_COMMAND="$(basename "${AURHELPER}")"
162 _msg_error "${AURHELPER} is not installed"
170 if [[ ! "${PACMAN_COMMAND}" = "${DEFAULT_PACMAN_COMMAND}" ]] && [[ ! "$(basename "${PACMAN_COMMAND}")" = "$(basename "${DEFAULT_PACMAN_COMMAND}")" ]]; then
171 _msg_debug "Use AUR helper ${PACMAN_COMMAND}"
178 if "${AUTOREMOVE}"; then
179 if [[ -n $(${PACMAN_COMMAND} -Qttdq) ]]; then
180 "${PACMAN_COMMAND}" -Qttdq | _sudo "${PACMAN_COMMAND}" -Rsc --config "${PACMAN_CONFIG}" -
182 echo "No packages to remove"
188 _run_distinguish_package(){
190 for pkg in "${PACKAGE[@]}"; do
191 if [[ ! -f "${pkg}" ]]; then
192 PACMAN_PACKAGE+=("${pkg}")
193 elif [[ "$(file -b --mime-type "${pkg}" 2> /dev/null)" = "application/vnd.debian.binary-package" ]]; then
194 DEB_PACKAGE_FILE+=("${pkg}")
196 PACMAN_PACKAGE_FILE+=("${pkg}")
202 if [[ "${INSTALL}" = true ]]; then
203 _pacman -S "${PACMAN_PACKAGE[@]}"
205 _pacman "${PACMAN_PACKAGE[@]}"
210 _msg_warn "It is not recommended to install deb package"
211 _msg_warn "The package conversion is not perfect and can lead to errors in some cases"
213 if (( "${#DEB_PACKAGE_FILE[@]}" != 0 )) && ! hash "debtap"; then
214 _msg_error "debtap was not found"
218 if [[ -z "$(find "/var/cache/pkgfile" -maxdepth 1 -mindepth 1 -name "*.files" 2> /dev/null)" ]] || [[ -z "$(find "/var/cache/debtap" -maxdepth 1 -mindepth 1 -name "*-packages" 2> /dev/null)" ]] || [[ -z "$(find "/var/cache/debtap" -maxdepth 1 -mindepth 1 -name "*-files" 2> /dev/null)" ]]; then
219 _msg_debug "Updating debtap datebase"
224 sudo mkdir -p "${DEBTAP_WORK}"
226 for pkg in "${DEB_PACKAGE_FILE[@]}"; do
227 work="${DEBTAP_WORK}/$(basename "${pkg}")/"
228 file="${work}/$(basename "${pkg}")"
229 _msg_debug "Work dir: ${work}"
230 _msg_debug "Deb file:${work}"
231 sudo mkdir -p "${work}"
232 sudo cp "${pkg}" "${file}"
234 sudo debtap --Quiet "${file}"
235 while read -r archpkg; do
236 _msg_debug "Install ${archpkg} with pacman"
237 _pacman -U "${archpkg}"
238 done < <(find "${work}" -maxdepth 1 -mindepth 1 -type f -name "*.pkg.tar.*")
244 # Argument analysis and processing
246 PACAPT_ARGUMENTS=("${@}")
247 _opt_short="ydfc:hvVDFQRSTU"
248 _opt_long="yes,assume-yes,download-only,fix-broken,purse,installed,debug,help,version,config-file:,auto-remove,autoremove,aur-helper:,pflags:"
249 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}" 2> /dev/null)
251 #if [[ ${?} != 0 ]]; then
256 #echo "Argument is \"${OPT}\""
257 unset OPT _opt_short _opt_long
261 -y | --yes | --assume-yes)
262 ADD_OPTION "--noconfirm"
265 -d | --download-only)
281 INSTALLED_PKGLIST=true
298 --autoremove | --auto-remove)
303 if [[ ! "${UID}" = 0 ]] && [[ -f "${2}" ]]; then
304 PACMAN_COMMAND="${2}"
305 elif [[ "${UID}" = 0 ]]; then
306 _msg_warn "The specified AUR helper is not used because pacapt is running on the root."
307 elif hash "$(basename "${2}")" 2> /dev/null; then
308 PACMAN_COMMAND="$(basename "${2}")"
310 _msg_error "${2} is not installed"
316 # shellcheck disable=SC2086
320 -V | -D | -F | -Q | -R | -S | -T | -U)
322 ADD_OPTION "${PACAPT_ARGUMENTS[@]}"
330 _msg_error "Invalid argument '${1}'"
337 if [[ "${DIRECT_PACMAN}" = false ]]; then
338 if [[ $# -lt 1 ]]; then
339 _msg_error "No command specified"
379 if [[ -n "${EDITOR}" ]]; then
380 sudo "${EDITOR}" "${PACMAN_CONFIG}"
382 sudo nano "${PACMAN_CONFIG}"
387 # shellcheck disable=SC1091
388 if [[ "$(source "/etc/locale.conf" 2> /dev/null; echo -n "${LANG}")" = "ja_JP.UTF-8" ]]; then
389 echo "(ง •ᴗ•)ว ⁾⁾ファーウェイでウェイウェイ"
392 _msg_error "Invalid command '${COMMAND}'"
403 echo "....\"Have you mooed today?\"..."
407 if [[ -n "$(${PACMAN_COMMAND} -Qttdq)" ]]; then
409 while read -r pkg; do
411 done < <(${PACMAN_COMMAND} -Qttdq)
413 echo "No packages to remove"
418 if [[ "${INSTALLED_PKGLIST}" = true ]]; then
419 ADD_OPTION "-Q | grep"
425 for pkg in "${PACKAGE[@]}"; do
426 if pacman -Qq "${pkg}" 2> /dev/null 1>&2; then
427 "${PACMAN_COMMAND}" "${PACMAN_OPTIONS[@]}" -Qi --config "${PACMAN_CONFIG}" "${pkg}"
429 "${PACMAN_COMMAND}" "${PACMAN_OPTIONS[@]}" -Si --config "${PACMAN_CONFIG}" "${pkg}"
443 _msg_error "Invalid command '${COMMAND}'"
450 _run_detect_aur_helper
452 _run_distinguish_package
454 if [[ "${INSTALL}" = true ]]; then