瀏覽代碼

aptq v1 functional

George Jones 3 年之前
父節點
當前提交
2cc5e248b4
共有 1 個文件被更改,包括 45 次插入69 次删除
  1. 45 69
      rc.local/aptq

+ 45 - 69
rc.local/aptq

@@ -1,16 +1,14 @@
 #! /bin/bash
 # Wrap apt queries in a common memorable syntax
-#
-# Usage: aptq QUERY PACKAGE|FILE
-#
-# where QUERY is one of
-#
-#  installed	- is PACKAGE installed?
-#  provdes	- what files does PACKAGE provide?
-#  owns		- what pacakge owns FILE?
+# Because I keep looking this stuff up do to differing comands and syntax.
 #
 
-set -e; #set -u
+set -e; set -u
+
+ARGV=("$@")
+ARGC=("$#")
+#ARGV=("${ARGV[@]:1}") # shift ARGV
+#ARGC=${#ARGV[@]} # get count
 
 # Helper functions
 PROG=`basename "$0" | tr -d '\n'`
@@ -23,29 +21,18 @@ function die()   { echo `date +%c` ${PROG}\: fatal: "$@" 1>&2 && exit 1; }
 
 
 function usage() {
-    debug "in ${FUNCNAME[0]}"
-
     if [[ "$#" -gt 0 ]]; then
         warn $@
     fi
 
     cat <<END 1>&2
-Usage: PROG [options] [args]
-
-   arguments
-     arg1               describe arg1
-
-   options
-
-    Group 1
-
-    -a|--abc            what does --abc do?
+Usage: aptq QUERY PACKAGE|FILE
 
-    Other
+where QUERY is one of
 
-    -d|--debug         debug output
-    -h|--help          print usage
-    -v|--verbose       verbose output
+ installed	- is PACKAGE installed?
+ list           - list the files a package provides
+ provides	- what pacakge owns FILE?
 END
     exit 1
 }
@@ -53,31 +40,19 @@ END
 
 query=""
 
-while [ ! -z "$1" ];do
-   case "$1" in
+while [ "$ARGC" != "0" ];do
+   case "${ARGV[0]}" in
         -h|--help)
           usage
           ;;
-        # -f|--fetch)
-          # fetch="true"
-          # ;;
-        # -s|--sleep)
-          # status="true"
-        # ;;
         installed)
-            debug instlled
             query="installed"
-            shift
             ;;
-        owns)
-            debug instlled
-            query="owns"
-            shift
+        list)
+            query="list"
             ;;
         provides)
-            debug instlled
             query="provides"
-            shift
             ;;
 
         *)
@@ -89,47 +64,48 @@ while [ ! -z "$1" ];do
             fi
    esac
 shift
+ARGV=("${ARGV[@]:1}") # shift ARGV
+ARGC=${#ARGV[@]} # get count
 done
 
+debug ARGV ${ARGV[*]}
+debug ARGC ${ARGC}
+
 if [ "$query" == "" ]; then
     warn "no known query given"
     usage
 fi
 
-debug query $query
-debug args are $*
-exit 0
+if [ "$query" == "installed" ]; then
 
-ARGC=$#
+    if [[ "$ARGC" != "0" ]]; then
+        warn "extra arguments"
+        usage
+    fi
 
-if [ "$ARGC" == "0" ]; then
-    set -- `pwd` "$@" # add pwd if no args
-fi
+    apt list --installed
 
-for i in $* ; do
+elif [ "$query" == "list" ]; then
 
-    if [ "$i" == "-f" ]; then
-        fetch=true
-        continue
+    if [[ "$ARGC" < "1" ]]; then
+        warn "need a PACKAGE name or FILE"
+        usage
+    elif [[ "$ARGC" > "1" ]]; then
+        warn "extra arguments"
+        usage
     fi
 
-    if [ "$i" == "-s" ]; then
-        status=true
-        continue
-    fi
+    dpkg -L ${ARGV[0]}
 
-    if [ "$fetch" == "true" ]; then
-        git fetch
-    fi
+elif [ "$query" == "provides" ]; then
 
-    \pushd $i > /dev/null;
-    echo $i;
-
-    if [ "$status" == "true" ]; then
-        git status -s
-    else
-        git branch -vv;
+    if [[ "$ARGC" < "1" ]]; then
+        warn "need a PACKAGE name or FILE"
+        usage
+    elif [[ "$ARGC" > "1" ]]; then
+        warn "extra arguments"
+        usage
     fi
-    echo;
-    \popd > /dev/null;
-done
+
+    dpkg -S ${ARGV[0]}
+fi