OSDN Git Service

[fix] : lang config
[alterlinux/aptpac.git] / aptpac
diff --git a/aptpac b/aptpac
index 547994c..c5338ef 100755 (executable)
--- a/aptpac
+++ b/aptpac
 # (c) 2019-2020 Fascode Network.
 # maintained by Yamada Hayao
 
-APTPAC_VERSION="2.2.0"
+APTPAC_VERSION="3.0.0"
 
 set -e
 
-OPTIONS=
-AURHELPER="/usr/bin/hoge"
+PACMAN_OPTIONS=
+AURHELPER=
 HELPERS=(
     "/usr/bin/yay"
     "/usr/bin/yaourt"
@@ -91,7 +91,7 @@ _usage () {
     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 "    -v | --version                Displays the version of aptpac and pacman."
     echo "    --purge                       Delete the entire configuration file."
 }
 
@@ -104,37 +104,78 @@ cat << EOF
 aptpac ${APTPAC_VERSION} - A pacman wrapper with syntax based on debian's apt
 (c) 2019-2020 Fascode Network. Yamada Hayao
 EOF
+echo
+pacman --version
 }
 
 
 ADD_OPTION () {
-    OPTIONS="${OPTIONS} ${@}"
+    PACMAN_OPTIONS="${PACMAN_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" ;;
-                debug) debug=true ;;
-                help) _usage; _exit 0 ;;
-            esac
+# Argument analysis and processing
+_opt_short="ydfc:hv"
+_opt_long="yes,assume-yes,download-only,fix-broken,purse,installed,debug,help,version"
+OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
+if [[ ${?} != 0 ]]; then
+    exit 1
+fi
+
+eval set -- "${OPT}"
+#echo "Argument is \"${OPT}\""
+unset OPT _opt_short _opt_long
+
+while true; do
+    case ${1} in
+        -y | --yes | --assume-yes)
+            ADD_OPTION "--noconfirm"
+            shift 1
+            ;;
+        -d | --download-only)
+            ADD_OPTION "-w"
+            shift 1
+            ;;
+        -f | --fix-broken)
+            shift 1
+            ;;
+        -c)
+            ADD_OPTION "--config ${2}"
+            shift 2
+            ;;
+        --purge)
+            ADD_OPTION "-n"
+            shift 1
+            ;;
+        --installed)
+            installed=true
+            shift 1
+            ;;
+        --debug)
+            debug=true
+            shift 1
+            ;;
+        -h | --help)
+            _usage
+            shift 1
+            exit 0
+            ;;
+        -v | --version)
+            _version
+            shift 1
+            exit 0
+            ;;
+        --)
+            shift 1
+            break
+            ;;
+        *)
+            _msg_error "Invalid argument '${1}'"
+            _help
+            exit 1
+            ;;
     esac
 done
 
-shift $((OPTIND - 1))
-
 if [[ $# -lt 1 ]]; then
     _msg_error "No command specified"
     _usage
@@ -157,6 +198,7 @@ case "${COMMAND}" in
     edit-sources) sudo nano /etc/pacman.conf; _exit 0 ;;
     dist-upgrade) ADD_OPTION "-Syu" ;;
     huawei) 
+        source "/etc/locale.conf"
         if [[ "${LANG}" = "ja_JP.UTF-8" ]]; then
             echo "(ง •ᴗ•)ว ⁾⁾ファーウェイでウェイウェイ"
             _exit 0
@@ -205,5 +247,5 @@ if [[ ! "${PACMAN_COMMAND}" = "pacman" ]] && [[ ! "${PACMAN_COMMAND}" = "sudo pa
     _msg_debug "Use AUR helper ${PACMAN_COMMAND}."
 fi
 
-# echo "${PACMAN_COMMAND} ${OPTIONS} ${PACKAGE}"
-${PACMAN_COMMAND} ${OPTIONS} ${PACKAGE}
+# echo "${PACMAN_COMMAND} ${PACMAN_OPTIONS} ${PACKAGE}"
+${PACMAN_COMMAND} ${PACMAN_OPTIONS} ${PACKAGE}