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"
68 INSTALLED_PKGLIST=false
71 echo "usage ${0} [options] [command] [packages]"
74 echo " install Install the specified package"
75 echo " remove Remove the specified package"
76 echo " purge Permanently remove the package"
77 echo " update Update package database"
78 echo " upgrade | full-upgrade Update packages"
79 echo " edit-sources Edit config file of pacman"
80 echo " search Search for a package"
81 echo " autoremove Remove unnecessary packages"
82 echo " clean Remove the package cache"
83 echo " list Display a list of packages"
84 echo " show | showpkg Display the package records"
85 echo " rdepends Display the dependencies"
88 echo " -y | --yes | --assume-yes Do not check"
89 echo " -d | --download-only Only download the package"
90 echo " -c | --config-file <file> Config file for pacman"
91 echo " -h | --help Display this help"
92 echo " -v | --version Display the version of aptpac and pacman"
93 echo " --auto-remove | --autoremove Remove unnecessary packages with other command"
94 echo " --purge Delete the entire configuration file"
96 echo " pacapt options:"
97 echo " --aur-helper <command> Specifies the command to use as the AUR helper"
98 echo " Ignored if pacapt is run as root"
99 echo " Specify AUR helper that supports common command line options with pacman"
102 echo " - aptpac supports not only above options but also options of pacman"
103 echo " - If you specify the deb file, you can install using debtap"
112 aptpac ${APTPAC_VERSION} - A pacman wrapper with syntax based on debian's apt
113 License: Do What The Fuck You Want To Public License
114 (c) 2019-2020 Fascode Network. Yamada Hayao
121 PACMAN_OPTIONS+=("${@}")
125 if "${RUN_WITH_SUDO}"; then
133 _sudo "${PACMAN_COMMAND}" "${PACMAN_OPTIONS[@]}" --config "${PACMAN_CONFIG}" "${@}"
136 _run_detect_aur_helper(){
137 if [[ ! "${UID}" = 0 ]]; then
138 if [[ -z "${AURHELPER+SET}" ]]; then
139 for AURHELPER in "${HELPERS[@]}"; do
140 if [[ -f "${AURHELPER}" ]]; then
141 PACMAN_COMMAND="${AURHELPER}"
143 elif hash "$(basename "${AURHELPER}")" 2> /dev/null; then
144 PACMAN_COMMAND="$(basename "${AURHELPER}")"
149 if [[ -f "${AURHELPER}" ]]; then
150 PACMAN_COMMAND="${AURHELPER}"
151 elif hash "$(basename "${AURHELPER}")" 2> /dev/null; then
152 PACMAN_COMMAND="$(basename "${AURHELPER}")"
154 _msg_error "${AURHELPER} is not installed"
162 if [[ ! "${PACMAN_COMMAND}" = "${DEFAULT_PACMAN_COMMAND}" ]] && [[ ! "$(basename "${PACMAN_COMMAND}")" = "$(basename "${DEFAULT_PACMAN_COMMAND}")" ]]; then
163 _msg_debug "Use AUR helper ${PACMAN_COMMAND}"
170 if "${AUTOREMOVE}"; then
171 if [[ -n $(${PACMAN_COMMAND} -Qttdq) ]]; then
172 "${PACMAN_COMMAND}" -Qttdq | _sudo "${PACMAN_COMMAND}" -Rsc --config "${PACMAN_CONFIG}" -
174 echo "No packages to remove"
180 _run_distinguish_package(){
182 for pkg in "${PACKAGE[@]}"; do
183 if [[ ! -f "${pkg}" ]]; then
184 PACMAN_PACKAGE+=("${pkg}")
185 elif [[ "$(file -b --mime-type "${pkg}" 2> /dev/null)" = "application/vnd.debian.binary-package" ]]; then
186 DEB_PACKAGE_FILE+=("${pkg}")
188 PACMAN_PACKAGE_FILE+=("${pkg}")
194 if [[ "${INSTALL}" = true ]]; then
195 _pacman -S "${PACMAN_PACKAGE[@]}"
197 _pacman "${PACMAN_PACKAGE[@]}"
202 if (( "${#DEB_PACKAGE_FILE[@]}" != 0 )) && ! hash "debtap"; then
203 _msg_error "debtap was not found"
207 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
212 sudo mkdir -p "${DEBTAP_WORK}"
214 for pkg in "${DEB_PACKAGE_FILE[@]}"; do
215 work="${DEBTAP_WORK}/$(basename "${pkg}")/"
216 file="${work}/$(basename "${pkg}")"
217 sudo mkdir -p "${work}"
219 sudo cp "${pkg}" "${file}"
220 sudo debtap --Quiet "${file}"
221 while read -r archpkg; do
222 _pacman -U "${archpkg}"
223 done < <(find "${work}" -maxdepth 1 -mindepth 1 -type f -name "*.pkg.tar.*")
229 # Argument analysis and processing
231 PACAPT_ARGUMENTS=("${@}")
232 _opt_short="ydfc:hvVDFQRSTU"
233 _opt_long="yes,assume-yes,download-only,fix-broken,purse,installed,debug,help,version,config-file:,auto-remove,autoremove,aur-helper:,pflags:"
234 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}" 2> /dev/null)
236 #if [[ ${?} != 0 ]]; then
241 #echo "Argument is \"${OPT}\""
242 unset OPT _opt_short _opt_long
246 -y | --yes | --assume-yes)
247 ADD_OPTION "--noconfirm"
250 -d | --download-only)
266 INSTALLED_PKGLIST=true
283 --autoremove | --auto-remove)
288 if [[ ! "${UID}" = 0 ]] && [[ -f "${2}" ]]; then
289 PACMAN_COMMAND="${2}"
290 elif [[ "${UID}" = 0 ]]; then
291 _msg_warn "The specified AUR helper is not used because pacapt is running on the root."
292 elif hash "$(basename "${2}")" 2> /dev/null; then
293 PACMAN_COMMAND="$(basename "${2}")"
295 _msg_error "${2} is not installed"
301 # shellcheck disable=SC2086
305 -V | -D | -F | -Q | -R | -S | -T | -U)
307 ADD_OPTION "${PACAPT_ARGUMENTS[@]}"
315 _msg_error "Invalid argument '${1}'"
322 if [[ "${DIRECT_PACMAN}" = false ]]; then
323 if [[ $# -lt 1 ]]; then
324 _msg_error "No command specified"
364 if [[ -n "${EDITOR}" ]]; then
365 sudo "${EDITOR}" "${PACMAN_CONFIG}"
367 sudo nano "${PACMAN_CONFIG}"
372 if [[ "$(source "/etc/locale.conf" 2> /dev/null; echo -n "${LANG}")" = "ja_JP.UTF-8" ]]; then
373 echo "(ง •ᴗ•)ว ⁾⁾ファーウェイでウェイウェイ"
376 _msg_error "Invalid command '${COMMAND}'"
387 echo "....\"Have you mooed today?\"..."
391 if [[ -n "$(${PACMAN_COMMAND} -Qttdq)" ]]; then
393 while read -r pkg; do
395 done < <(${PACMAN_COMMAND} -Qttdq)
397 echo "No packages to remove"
402 if [[ "${INSTALLED_PKGLIST}" = true ]]; then
403 ADD_OPTION "-Q | grep"
409 for pkg in "${PACKAGE[@]}"; do
410 if pacman -Qq "${pkg}" 2> /dev/null 1>&2; then
411 "${PACMAN_COMMAND}" "${PACMAN_OPTIONS[@]}" -Qi --config "${PACMAN_CONFIG}" "${pkg}"
413 "${PACMAN_COMMAND}" "${PACMAN_OPTIONS[@]}" -Si --config "${PACMAN_CONFIG}" "${pkg}"
427 _msg_error "Invalid command '${COMMAND}'"
434 _run_detect_aur_helper
436 _run_distinguish_package
438 if [[ "${INSTALL}" = true ]]; then