# \ \_\ \ \_\
# \/_/ \/_/
# a pacman wrapper with syntax based on debian's apt
-# (c) arcetera 2015 - wtfpl
-# maintained by alefir
-
-SYNTAX=$1
-INPUT=$2
-
-case $SYNTAX in
- install) sudo pacman -S $INPUT;;
- search) pacman -Ss $INPUT;;
- remove) sudo pacman -Rs $INPUT;;
- upgrade) sudo pacman -Syu;;
- update) sudo padman -Sy;
- echo "Run aptpac upgrade *immediately*. pacman does not support partial upgrades. running merely 'upgrade' would suffice. failure to do this could result in a broken installation.";;
- download) sudo pacman -Sw $INPUT;;
- autoremove) sudo pacman -Qdtq | pacman -Rs -;;
- show) padman -Qi $INPUT;;
- clean) sudo pacman -Sc;;
- autoclean) sudo pacman -Sc;;
- policy) less /etc/pacman.d/mirrorlist;;
- list) pacman -Q;;
- listmore) pacman -Qi;;
- listless) pacman -Q | wc -l;;
- build) makepkg -sri;;
- *)
- echo "aptpac: a pacman wrapper with apt syntax";
- echo "no argument/invalid argument - print this help";
- echo "install - installs a package";
- echo "search - searches for a package in the repos";
- echo "remove - removes a package";
- echo "upgrade - upgrades the system fully, refreshing repos and upgrading packages";
- echo "update - only refreshes the repos (bad practice, do not run this without running 'upgrade' immediately after";
- echo "download - only download a package into pacman's cache without installing it";
- echo "autoremove - remove dependencies that are no longer needed (usually should not be needed as 'remove' should remove dependencies along with the package)";
- echo "show - shows information about the package";
- echo "clean/autoclean - clears pacman's cache";
- echo "policy - prints mirrorlist";
- echo "list - lists all installed packages";
- echo "listmore - lists all installed packages with all info";
- echo "listless - lists how many packages are installed";
- echo "build - builds package from PKGBUILD";
+# (c) 2019-2020 Fascode Network.
+# maintained by Yamada Hayao
+
+set -e
+
+OPTIONS=
+AURHELP=
+
+if [[ ${UID} = 0 ]]; then
+ pacman=pacman
+elif [[ -n ${AURHELP} ]]; then
+ pacman=${AURHELP}
+else
+ pacman=pacman
+fi
+
+# List option
+installed=false
+
+_usage () {
+ echo "usage ${0} [options] [command] [packages]"
+ echo " commands: "
+ echo " install Install the specified package."
+ echo " remove Remove the specified package."
+ echo " purge Permanently remove the package."
+ echo " update Update the package database."
+ echo " upgrade Update the package."
+ echo " search Search for a package."
+ echo " autoremove Remove unnecessary packages."
+ echo " list Displays a list of packages."
+ echo
+ echo " general options: "
+ echo " -y | --yes | --assume-yes Do not check."
+ echo " -d | --download-only Only download the package."
+ echo " -c <file> Config file for pacman."
+ echo " -h | --help Display this help."
+ echo " -v Displays the version of pacman."
+ echo " --purge Delete the entire configuration file."
+}
+
+_exit () {
+ exit ${1}
+}
+
+_msg_error () {
+ echo -e "${@}" >&2
+}
+
+ADD_OPTION () {
+ OPTIONS="${OPTIONS} ${@}"
+}
+
+while getopts 'ydf-:c:hv' arg; do
+ case "${arg}" in
+ y) ADD_OPTION "--noconfirm" ;;
+ d) ADD_OPTION "-w" ;;
+ f) : ;;
+ c) ADD_OPTION "--config ${OPTARG}" ;;
+ h) _usage; _exit 0 ;;
+ v) _version; _exit 0 ;;
+ -)
+ case "${OPTARG}" in
+ download-only) ADD_OPTION "-w" ;;
+ fix-broken) :;;
+ yes) ADD_OPTION "--noconfirm" ;;
+ assume-yes) ADD_OPTION "--noconfirm" ;;
+ installed) installed=true;;
+ purge) ADD_OPTION "-n" ;;
+ help) _usage; _exit 0 ;;
+ esac
+ esac
+done
+
+shift $((OPTIND - 1))
+
+if [[ $# -lt 1 ]]; then
+ _msg_error "No command specified"
+ _usage
+ _exit 1
+fi
+COMMAND="${1}"
+
+shift 1
+
+PACKAGE="${@}"
+
+case "${COMMAND}" in
+ install) ADD_OPTION "-S" ;;
+ remove) ADD_OPTION "-Rsc" ;;
+ purge) ADD_OPTION "-Rsnc" ;;
+ update) ADD_OPTION "-Syy" ;;
+ upgrade) ADD_OPTION "-Syu" ;;
+ search) ADD_OPTION "-Ss" ;;
+ full-upgrade) ADD_OPTION "-Syu" ;;
+ edit-sources) sudo nano /etc/pacman.conf; _exit 0 ;;
+ dist-upgrade) ADD_OPTION "-Syu" ;;
+ autoremove) ADD_OPTION "-Qttdq | pacman -Rsnc -" ;;
+ list)
+ if ${installed}; then
+ ADD_OPTION "-Q | grep"
+ else
+ ADD_OPTION "-Ss"
+ fi
+ ;;
+ *)
+ _msg_error "Invalid comman '${COMMAND}'"
+ _exit 1
+ ;;
esac
+
+# echo "${pacman} ${OPTIONS} ${PACKAGE}"
+${pacman} ${OPTIONS} ${PACKAGE}
\ No newline at end of file