2 # Copyright (C) 2007 - 2013 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 dpkg [PKG] -- print PKG dependencies.
23 pkgrepo [PKG] <t> -- print the source repo location of PKG
24 with optional 2nd arg non-nil, also print
26 pkgsu [PKGUSR] -- switch to user PKGUSR.
27 pkg_install [DESCRIPTION] [USER] [GROUP]
28 -- install a new package, DESCRIPTION must be quoted.
29 pkg_ldconfig -- Run ldconfig.
31 xtar [FILE] -- extract tarball FILE. sets tar(1) options
33 vtar [FILE] -- view the contents of tarball FILE. sets tar(1)
34 options based on file type.
35 ctar [FILE] [DIRECTORY]
36 -- create a tarball FILE of DIRECTORY. Compression
37 is automatically chosen from the filename.
45 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
46 echo Invalid or missing argument >&2
47 echo "Usage: $0 [REGEXP]" >&2
50 sed -n '/^install:/,$p' /etc/group|cut -d: -f1| \
51 grep -i --colour ${argv[1]}
57 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
58 echo Invalid or missing argument >&2
59 echo "Usage: $0 [NAME]" >&2
62 pinky -l $argv[1]|less
68 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
69 echo Invalid or missing argument >&2
70 echo "Usage: $0 [CMD]" >&2
73 find $path -type f -regex "^.*/$argv[1].*$" \
74 -printf "%f -- (%u:%g)\n"|grep --colour '(.*)'
80 sed -n '/^install/p' /etc/group|cut -d: -f4|tr ',' '\n'|less
85 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
86 echo Invalid or missing argument >&2
87 echo "Usage: $0 [PKG]" >&2
90 grep --colour 'Last_Updated:.*' ~$argv[1]/.project
96 for pkg in $(sed -n '/^install/p' /etc/group|cut -d: -f4|tr ',' '\n'); do
97 printf "${pkg}\t\t\t$(upkg ${pkg}|cut -d' ' -f3-)\n"
103 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
104 echo Invalid or missing argument >&2
105 echo "Usage: $0 [PKG]" >&2
108 grep --colour 'Version: ' ~$argv[1]/.project
114 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
115 echo Invalid or missing argument >&2
116 echo "Usage: $0 [PKG]" >&2
119 local top=$(grep -n "Install Notes" ~$argv[1]/.project|cut -d: -f1)
120 local bot=$(grep -n "General Notes" ~$argv[1]/.project|cut -d: -f1)
121 sed -n ${top},${bot}p ~$argv[1]/.project
127 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
128 echo Invalid or missing argument >&2
129 echo "Usage: $0 [PKG]" >&2
132 local top=$(grep -n "General Notes" ~$argv[1]/.project|cut -d: -f1)
133 local bot=$(grep -n "CONTENTS" ~$argv[1]/.project|cut -d: -f1)
134 sed -n ${top},${bot}p ~$argv[1]/.project
140 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
141 echo Invalid or missing argument >&2
142 echo "Usage: $0 [PKG]" >&2
145 grep --colour 'Deps: ' ~$argv[1]/.project
151 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
152 echo Invalid or missing argument >&2
153 echo "Usage: $0 [PKG]" >&2
156 grep --colour 'Web_Site: ' ~$argv[1]/.project
162 if [[ $ARGC -lt 1 || $ARGC -gt 2 ]]; then
163 echo Invalid or missing argument >&2
164 echo "Usage: $0 [PKG] <t>" >&2
167 grep --colour 'Repo_Location: ' ~$argv[1]/.project
168 [[ -n "$argv[2]" ]] && grep --colour 'Repo_Type: ' ~$argv[1]/.project
174 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
175 echo Invalid or missing argument >&2
176 echo "Usage: $0 [FILE]" >&2
184 type=$(file ${fname}|cut -d' ' -f2)
193 if lzmainfo ${fname} &>/dev/null; then
196 printf "Unknown file type: %s\n" $type >&2
207 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
208 echo Invalid or missing argument >&2
209 echo "Usage: $0 [FILE]" >&2
217 type=$(file ${fname}|cut -d' ' -f2)
221 (gzip) opts=ztvvvf ;;
222 (bzip2) opts=jtvvvf ;;
225 # lzma. Here because lzmainfo is too stupid
226 if lzmainfo ${fname} &>/dev/null; then
229 printf "Unknown file type: %s\n" $type >&2
235 tar ${opts} ${fname}|less
240 if [[ $ARGC -ne 2 ]]; then
241 echo Invalid or missing argument >&2
242 echo "Usage: $0 [FILE] [DIRECTORY]" >&2
247 opts=(--create --owner=0 --group=0 --auto-compress --file)
254 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
255 echo Invalid or missing argument >&2
256 echo "Usage: $0 [PKGUSR]" >&2
259 ssh -l root localhost -t su $argv[1]
265 if [[ $ARGC -lt 3 || $ARGC -gt 3 ]]; then
266 echo Invalid or missing argument >&2
267 echo "Usage: $0 [DESCRIPTION] [USER] [GROUP]" >&2
270 ssh -l root localhost -t install_package \
271 ${argv[1]} $argv[2] $argv[3]
275 alias pkg_ldconfig='ssh -l root localhost -t ldconfig'