2 # Copyright (C) 2007 - 2010 Steve Youngs <steve@steveyoungs.com>
4 # A collection of Zsh functions that I use day to day for maintaining
5 # and administering my machines. These come in very handy if you set up
6 # one of your users as a "package manager". There is a corresponding
7 # _zsh-pkgtools file that provides completion for most of what is here.
12 fpkg [REGEXP] -- finds pkg names matching REGEXP.
13 ppkg [NAME] -- print pkg NAME pkg info.
14 cpkg [CMD] -- find what package provides CMD.
15 lpkg -- list installed packages.
16 Lpkg -- list installed packages with dates last updated.
17 upkg [PKG] -- date/time the last time PKG was updated.
18 vpkg [PKG] -- print the version of PKG.
19 ipkg [PKG] -- print install notes of PKG.
20 gpkg [PKG] -- print general notes of PKG.
21 wpkg [PKG] -- print PKG website URL.
22 pkgrepo [PKG] <t> -- print the source repo location of PKG
23 with optional 2nd arg non-nil, also print
25 pkgsu [PKGUSR] -- switch to user PKGUSR.
26 pkg_install [DESCRIPTION] [USER] [GROUP]
27 -- install a new package, DESCRIPTION must be quoted.
28 pkg_ldconfig -- Run ldconfig.
30 xtar [FILE] -- extract tarball FILE. sets tar(1) options
32 vtar [FILE] -- view the contents of tarball FILE. sets tar(1)
33 options based on file type.
34 ctar [FILE] [DIRECTORY]
35 -- create a tarball FILE of DIRECTORY. Compression
36 is automatically chosen from the filename.
44 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
45 echo Invalid or missing argument >&2
46 echo "Usage: $0 [REGEXP]" >&2
49 sed -n '/^install:/,$p' /etc/group|cut -d: -f1| \
50 grep -i --colour ${argv[1]}
56 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
57 echo Invalid or missing argument >&2
58 echo "Usage: $0 [NAME]" >&2
61 pinky -l $argv[1]|less
67 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
68 echo Invalid or missing argument >&2
69 echo "Usage: $0 [CMD]" >&2
72 find $path -type f -regex "^.*/$argv[1].*$" \
73 -printf "%f -- (%u:%g)\n"|grep --colour '(.*)'
79 sed -n '/^install/p' /etc/group|cut -d: -f4|tr ',' '\n'|less
84 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
85 echo Invalid or missing argument >&2
86 echo "Usage: $0 [PKG]" >&2
89 echo -n "$argv[1]... "
90 pinky -l $argv[1]|grep 'Last_Updated:.*'| \
91 sed 's/^ //'|grep --colour '.*'
97 for pkg in $(sed -n '/^install/p' /etc/group|cut -d: -f4|tr ',' '\n'); do
98 printf "${pkg}\t\t\t$(pinky -l ${pkg}|grep Last_Updated|cut -d' ' -f3-)\n"
104 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
105 echo Invalid or missing argument >&2
106 echo "Usage: $0 [PKG]" >&2
109 echo -n "$argv[1]... "
110 pinky -l $argv[1]|grep 'Version:.*'| \
111 sed 's/^ //'|grep --colour '.*'
117 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
118 echo Invalid or missing argument >&2
119 echo "Usage: $0 [PKG]" >&2
122 local top=$(pinky -l $argv[1]|grep -n "Install Notes"|cut -d: -f1)
123 local bot=$(pinky -l $argv[1]|grep -n "General Notes"|cut -d: -f1)
124 pinky -l $argv[1]|sed -n ${top},${bot}p
130 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
131 echo Invalid or missing argument >&2
132 echo "Usage: $0 [PKG]" >&2
135 local top=$(pinky -l $argv[1]|grep -n "General Notes"|cut -d: -f1)
136 local bot=$(pinky -l $argv[1]|grep -n "CONTENTS"|cut -d: -f1)
137 pinky -l $argv[1]|sed -n ${top},${bot}p
143 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
144 echo Invalid or missing argument >&2
145 echo "Usage: $0 [PKG]" >&2
148 pinky -l $argv[1]|grep --colour 'Web_Site:.*$'
154 if [[ $ARGC -lt 1 || $ARGC -gt 2 ]]; then
155 echo Invalid or missing argument >&2
156 echo "Usage: $0 [PKG] <t>" >&2
159 pinky -l $argv[1]|grep --colour 'Repo_Location:.*$'
160 [[ -n "$argv[2]" ]] && pinky -l $argv[1]|grep --colour 'Repo_Type:.*$'
166 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
167 echo Invalid or missing argument >&2
168 echo "Usage: $0 [FILE]" >&2
176 type=$(file ${fname}|cut -d' ' -f2)
185 if lzmainfo ${fname} &>/dev/null; then
188 printf "Unknown file type: %s\n" $type >&2
199 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
200 echo Invalid or missing argument >&2
201 echo "Usage: $0 [FILE]" >&2
209 type=$(file ${fname}|cut -d' ' -f2)
213 (gzip) opts=ztvvvf ;;
214 (bzip2) opts=jtvvvf ;;
217 # lzma. Here because lzmainfo is too stupid
218 if lzmainfo ${fname} &>/dev/null; then
221 printf "Unknown file type: %s\n" $type >&2
227 tar ${opts} ${fname}|less
232 if [[ $ARGC -ne 2 ]]; then
233 echo Invalid or missing argument >&2
234 echo "Usage: $0 [FILE] [DIRECTORY]" >&2
239 opts=(--create --owner=0 --group=0 --auto-compress --file)
246 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
247 echo Invalid or missing argument >&2
248 echo "Usage: $0 [PKGUSR]" >&2
251 ssh -l root localhost -t su $argv[1]
257 if [[ $ARGC -lt 3 || $ARGC -gt 3 ]]; then
258 echo Invalid or missing argument >&2
259 echo "Usage: $0 [DESCRIPTION] [USER] [GROUP]" >&2
262 ssh -l root localhost -t install_package \
263 ${argv[1]} $argv[2] $argv[3]
267 alias pkg_ldconfig='ssh -l root localhost -t ldconfig'