OSDN Git Service

[update] : Refactored and supported options.
authorhayao <shun819.mail@gmail.com>
Thu, 5 Mar 2020 05:08:55 +0000 (14:08 +0900)
committerhayao <shun819.mail@gmail.com>
Thu, 5 Mar 2020 05:08:55 +0000 (14:08 +0900)
aptpac

diff --git a/aptpac b/aptpac
index d7a1b1c..b25e987 100755 (executable)
--- a/aptpac
+++ b/aptpac
 #           \ \_\        \ \_\                 
 #            \/_/         \/_/    
 # 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=
+
+# List option
+installed=false
+
+_usage () {
+    :
+}
+
+_exit () {
+    exit ${1}
+}
+
+_msg_error () {
+    echo -e "${@}" >&2
+}
+
+ADD_OPTION () {
+    OPTIONS="${OPTIONS} ${@}"
+}
+
+while getopts 'ydf-:' arg; do
+    case "${arg}" in
+        y) ADD_OPTION "--noconfirm" ;;
+        d) ADD_OPTION "-w" ;;
+        f) : ;;
+        -)
+            case "${OPTARG}" in
+                download-only) ADD_OPTION "-w" ;;
+                fix-broken) :;;
+                yes) ADD_OPTION "--noconfirm" ;;
+                assume-yes) ADD_OPTION "--noconfirm" ;;
+                installed) installed=true;
+            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" ;;
+    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}"
\ No newline at end of file