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 pkgwant [PKG] -- print a list of packages that depend on PKG
24 pkgrepo [PKG] <t> -- print the source repo location of PKG
25 with optional 2nd arg non-nil, also print
27 pkgsu [PKGUSR] -- switch to user PKGUSR.
28 pkg_install [DESCRIPTION] [USER] [GROUP]
29 -- install a new package, DESCRIPTION must be quoted.
30 pkg_ldconfig -- Run ldconfig.
32 xtar [FILE] -- extract tarball FILE. sets tar(1) options
34 vtar [FILE] -- view the contents of tarball FILE. sets tar(1)
35 options based on file type.
36 ctar [FILE] [DIRECTORY]
37 -- create a tarball FILE of DIRECTORY. Compression
38 is automatically chosen from the filename.
46 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
47 echo Invalid or missing argument >&2
48 echo "Usage: $0 [REGEXP]" >&2
51 sed -n '/^install:/,$p' /etc/group|cut -d: -f1| \
52 grep -i --colour ${argv[1]}
58 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
59 echo Invalid or missing argument >&2
60 echo "Usage: $0 [NAME]" >&2
63 pinky -l $argv[1]|less
69 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
70 echo Invalid or missing argument >&2
71 echo "Usage: $0 [CMD]" >&2
74 find $path -type f -regex "^.*/$argv[1].*$" \
75 -printf "%f -- (%u:%g)\n"|grep --colour '(.*)'
81 sed -n '/^install/p' /etc/group|cut -d: -f4|tr ',' '\n'|less
86 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
87 echo Invalid or missing argument >&2
88 echo "Usage: $0 [PKG]" >&2
91 grep --colour 'Last_Updated:.*' ~$argv[1]/.project
97 for pkg in $(sed -n '/^install/p' /etc/group|cut -d: -f4|tr ',' '\n'); do
98 printf "${pkg}\t\t\t$(upkg ${pkg}|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 grep --colour 'Version: ' ~$argv[1]/.project
115 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
116 echo Invalid or missing argument >&2
117 echo "Usage: $0 [PKG]" >&2
120 local top=$(grep -n "Install Notes" ~$argv[1]/.project|cut -d: -f1)
121 local bot=$(grep -n "General Notes" ~$argv[1]/.project|cut -d: -f1)
122 sed -n ${top},${bot}p ~$argv[1]/.project|less
128 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
129 echo Invalid or missing argument >&2
130 echo "Usage: $0 [PKG]" >&2
133 local top=$(grep -n "General Notes" ~$argv[1]/.project|cut -d: -f1)
134 local bot=$(grep -n "CONTENTS" ~$argv[1]/.project|cut -d: -f1)
135 sed -n ${top},${bot}p ~$argv[1]/.project|less
141 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
142 echo Invalid or missing argument >&2
143 echo "Usage: $0 [PKG]" >&2
146 grep --colour 'Deps: ' ~$argv[1]/.project
152 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
153 echo Invalid or missing argument >&2
154 echo "Usage: $0 [PKG]" >&2
157 grep --colour 'Web_Site: ' ~$argv[1]/.project
163 if [[ $ARGC -lt 1 || $ARGC -gt 2 ]]; then
164 echo Invalid or missing argument >&2
165 echo "Usage: $0 [PKG] <t>" >&2
168 grep --colour 'Repo_Location: ' ~$argv[1]/.project
169 [[ -n "$argv[2]" ]] && grep --colour 'Repo_Type: ' ~$argv[1]/.project
175 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
176 echo Invalid or mission argument >&2
177 echo "Usage: $0 [PKG]" >&2
182 dpkg ${p} | grep -wq $argv[1] && print ${p}
188 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
189 echo Invalid or missing argument >&2
190 echo "Usage: $0 [FILE]" >&2
198 type=$(file ${fname}|cut -d' ' -f2)
207 if lzmainfo ${fname} &>/dev/null; then
210 printf "Unknown file type: %s\n" $type >&2
221 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
222 echo Invalid or missing argument >&2
223 echo "Usage: $0 [FILE]" >&2
231 type=$(file ${fname}|cut -d' ' -f2)
235 (gzip) opts=ztvvvf ;;
236 (bzip2) opts=jtvvvf ;;
237 (xz|XZ) opts=Jtvvvf ;;
239 # lzma. Here because lzmainfo is too stupid
240 if lzmainfo ${fname} &>/dev/null; then
243 printf "Unknown file type: %s\n" $type >&2
249 tar ${opts} ${fname}|less
254 if [[ $ARGC -ne 2 ]]; then
255 echo Invalid or missing argument >&2
256 echo "Usage: $0 [FILE] [DIRECTORY]" >&2
261 opts=(--create --owner=0 --group=0 --auto-compress --file)
268 if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then
269 echo Invalid or missing argument >&2
270 echo "Usage: $0 [PKGUSR]" >&2
273 ssh -l root localhost -t su - $argv[1]
279 if [[ $ARGC -lt 3 || $ARGC -gt 3 ]]; then
280 echo Invalid or missing argument >&2
281 echo "Usage: $0 [DESCRIPTION] [USER] [GROUP]" >&2
284 ssh -l root localhost -t install_package \
285 ${argv[1]} $argv[2] $argv[3]
289 alias pkg_ldconfig='ssh -l root localhost ldconfig'