#compdef reprepro # This is a zsh completion script for reprepro. # To make use of it make sure it is stored as _reprepro in your # zsh's fpath (like /usr/local/share/zsh/site-functions/). # # to install as user: # # mkdir ~/.zshfiles # cp reprepro.zsh_completion ~/.zshfiles/_reprepro # echo 'fpath=(~/.zshfiles $fpath)' >> ~/.zshrc # echo 'autoload -U ~/.zshfiles*(:t)' >> ~/.zshrc # # make sure compinit is called after those lines in .zshrc local context state line confdir distfile incomingfile incomingdir outdir basedir confdirset basedirset typeset -A opt_args local -a codenames architectures list commands hiddencommands function _reprepro_calcbasedir () { if [[ -n "$opt_args[-b]" ]]; then basedir=${opt_args[-b]} basedirset=true elif [[ -n "$opt_args[--basedir]" ]]; then basedir=${opt_args[--basedir]} basedirset=true elif [[ -n "$REPREPRO_BASE_DIR" ]]; then basedir=${REPREPRO_BASE_DIR} basedirset=true else basedir=$PWD basedirset=false fi if [[ -n "$opt_args[--confdir]" ]]; then confdir=${opt_args[--confdir]} elif [[ -n "$REPREPRO_CONFIG_DIR" ]]; then confdir=${REPREPRO_CONFIG_DIR} else confdir=$basedir/conf fi if [[ -e "$confdir/options" ]] ; then if [ "$basedirset" != "true" ] && grep -q '^basedir ' -- "$confdir/options" 2>/dev/null ; then basedir="$(grep '^basedir ' -- "$confdir/options" 2>/dev/null | sed -e 's/^basedir *//')" fi fi } function _reprepro_filekeys () { _reprepro_calcbasedir if [[ -n "$opt_args[--outdir]" ]]; then outdir=${opt_args[--outdir]} else outdir=$basedir fi list=( $outdir ) _files -W list } function _reprepro_calcconfdir () { if [[ -n "$opt_args[--confdir]" ]]; then confdir=${opt_args[--confdir]} confdirset=direct elif [[ -n "$REPREPRO_CONFIG_DIR" ]]; then confdir=${REPREPRO_CONFIG_DIR} confdirset=direct elif [[ -n "$opt_args[-b]" ]]; then confdir=${opt_args[-b]}/conf confdirset=basedir basedirset=true elif [[ -n "$opt_args[--basedir]" ]]; then confdir=${opt_args[--basedir]}/conf confdirset=basedir basedirset=true elif [[ -n "$REPREPRO_BASE_DIR" ]]; then confdir=${REPREPRO_BASE_DIR}/conf confdirset=basedir basedirset=true else confdir=$PWD/conf confdirset=default basedirset=false fi if [ "$confdirset" != "direct" ] && [[ -e "$confdir/options" ]] ; then if grep -q '^confdir ' -- "$confdir/options" 2>/dev/null ; then confdir="$(grep '^confdir ' -- "$confdir/options" 2>/dev/null | sed -e 's/^confdir *//')" elif [ "$basedirset" = "false" ] \ && grep -q '^basedir ' -- "$confdir/options" 2>/dev/null ; then confdir="$(grep '^basedir ' -- "$confdir/options" 2>/dev/null | sed -e 's/^basedir *//')/conf" fi fi } function _reprepro_finddistributions () { _reprepro_calcconfdir distfile="$confdir"/distributions test -e "$distfile" } function _reprepro_findincoming () { _reprepro_calcconfdir incomingfile="$confdir"/incoming test -e "$incomingfile" } function _reprepro_grepdistfile () { _reprepro_finddistributions && if test -d "$distfile" ; then sed -n -e 's#^'"$1"': \(.*\)#\1#p' "$distfile"/*.conf else sed -n -e 's#^'"$1"': \(.*\)#\1#p' "$distfile" fi } function _reprepro_architectures () { architectures=($(_reprepro_grepdistfile '[Aa][Rr][Cc][Hh][Ii][Tt][Ee][Cc][Tt][Uu][Rr][Ee][Ss]')) \ || architectures=(i386 m68k sparc alpha powerpc arm mips mipsel hppa ia64 s390 amd64 ppc64 sh armeb m32r hurd-i386 netbsd-i386 netbsd-alpha kfreebsd-gnu) _wanted -V 'architectures' expl 'architecture' compadd -a architectures } function _reprepro_components () { components=($(_reprepro_grepdistfile '[Cc][Oo][Mm][Pp][Oo][Nn][Ee][Nn][Tt][Ss]')) \ || components=(main contrib non-free bad) _wanted -V 'components' expl 'component' compadd -a components } function _reprepro_codenames () { codenames=($(_reprepro_grepdistfile '[Cc][Oo][Dd][Ee][Nn][Aa][Mm][Ee]')) \ || codenames=(sid lenny etch sarge unstable testing stable local) _wanted -V 'codenames' expl 'codename' compadd -a codenames } function _reprepro_identifiers () { _reprepro_finddistributions \ && list=($(if test -d "$distfile" ; then set -- "$distfile"/*.conf ; else set -- "$distfile" ; fi && awk ' /^$/ {for(a=2;a<=acount;a++){ for(c=2;c<=ccount;c++){ print codename "|" components[c] "|" architectures[a] } if( architectures[a] != "source" ) { for(c=2;c<=uccount;c++){ print "u|" codename "|" ucomponents[c] "|" architectures[a] } } }; acount=0;ccount=0;ucount=0} /^[Cc][Oo][Mm][Pp][Oo][Nn][Ee][Nn][Tt][Ss]: / {ccount = split($0,components); next} /^[Uu][Dd][Ee][Bb][Cc][Oo][Mm][Pp][Oo][Nn][Ee][Nn][Tt][Ss]: / {uccount = split($0,ucomponents); next} /^[Aa][Rr][Cc][Hh][Ii][Tt][Ee][Cc][Tt][Uu][Rr][Ee][Ss]: / {acount = split($0,architectures); next} /^[Cc][Oo][Dd][Ee][Nn][Aa][Mm][Ee]: / {codename = $2; next} END {for(a=2;a<=acount;a++){ for(c=2;c<=ccount;c++){ print codename "|" components[c] "|" architectures[a] } if( architectures[a] != "source" ) { for(c=2;c<=uccount;c++){ print "u|" codename "|" ucomponents[c] "|" architectures[a] } } }; acount=0;ccount=0;ucount=0} {next} ' "$@" )) \ || list=(identifier) _wanted -V 'identifiers' expl 'identifier' compadd -a list } function _reprepro_incomings () { _reprepro_findincoming \ && list=($(if test -d "$incomingfile" ; then set -- "$incomingfile"/*.conf ; else set -- "$incomingfile" ; fi && awk '/^[Nn][Aa][Mm][Ee]: / {print $2}' "$@")) \ || list=(rule-name) _wanted -V 'rule names' expl 'rule name' compadd -a list } function _reprepro_incomingdir () { local rulename=$1 shift _reprepro_findincoming \ && incomingdir=($(if test -d "$incomingfile" ; then set -- "$incomingfile"/*.conf ; else set -- "$incomingfile" ; fi && awk ' /^[Ii][Nn][Cc][Oo][Mm][Ii][Nn][Gg][Dd][Ii][Rr]: / {dir=$2; next} /^[Nn][Aa][Mm][Ee]: / {name=$2; next} /^$/ { if( name="'"$rulename"'" ) { print dir } ; next } END { if( name="'"$rulename"'" ) { print dir }} {next} ' "$@")) # needs to be an array, as it might not be absolute... list=( $incomingdir ) } function _reprepro_package_names () { #todo get package names?... _wanted -V 'package names' expl 'package name' compadd name } function _reprepro_source_package_names () { #todo get package names?... _wanted -V 'source package names' expl 'source package name' compadd name } commands=( build-needing:"list packages likely needing a build" check:"check if all references are correct" checkpool:"check if all files are still there and correct" checkpull:"check what would be pulled" checkupdate:"check what would be updated" cleanlists:"clean unneeded downloaded list files" clearvanished:"remove empty databases" collectnewchecksums:"calculate missing file hashes" copy:"copy a package from one distribution to another" copyfilter:"copy packages from one distribution to another" copymatched:"copy packages from one distribution to another" copysrc:"copy packages belonging to a specific source from one distribution to another" createsymlinks:"create suite symlinks" deleteunreferenced:"delete files without reference" dumpreferences:"dump reference information" dumppull:"dump what would be pulled" dumptracks:"dump tracking information" dumpupdate:"dump what would be updated" dumpunreferenced:"dump files without reference (i.e. unneded)" export:"export index files" forcerepairdescriptions:"forcefully readd lost long descriptions from .deb file" flood:"copy architecture all packages within a distribution" generatefilelists:"pre-prepare filelist caches for all binary packages" gensnapshot:"generate a snapshot" includedeb:"include a .deb file" includedsc:"include a .dsc file" include:"include a .changes file" includeudeb:"include a .udeb file" listfilter:"list packages matching filter" listmatched:"list packages matching filter" list:"list packages" ls:"list versions of package" lsbycomponent:"list versions of package (grouped by component)" predelete:"delete what would be removed or superseded by an update" processincoming:"process files from an incoming directory" pull:"update from another local distribtuion" removealltracks:"remove tracking information" remove:"remove packages" removefilter:"remove packages matching a formula" removematched:"remove packages matching a glob" removesrc:"remove packages belonging to a source package" removesrcs:"remove packages belonging to names source packages" removetrack:"remove a single tracking data" reoverride:"apply override information to already existing packages" repairdescriptions:"readd lost long descriptions from .deb file" reportcruft:"report source packages without binaries and vice versa" rereference:"recreate references" rerunnotifiers:"call notificators as if all packages were just included" restore:"restore a package from a distribution's snapshot" restorefilter:"restore packages matching a filter from a snapshot" restorematched:"restore packages matching a glob from a snapshot" restoresrc:"restore packages belonging to a specific source from a snapshot" retrack:"refresh tracking information" sourcemissing:"list binary packages with no source package" tidytracks:"look for files referened by tracks but no longer needed" translatefilelists:"translate pre-3.0.0 contents.cache.db into new format" translatelegacychecksums:"get rid of obsolete files.db" unreferencesnapshot:"no longer mark files used by an snapshot" unusedsources:"list source packages with no binary packages" update:"update from external source" ) hiddencommands=( __dumpuncompressors:"list what external uncompressors are available" __extractcontrol:"extract the control file from a .deb file" __extractfilelist:"extract the filelist from a .deb file" __extractsourcesection:"extract source and priority from a .dsc" __uncompress:"uncompress a file" _addchecksums:"add checksums to database" _addmd5sums:"add checksums to database" _addreference:"mark a filekey needed by an identifier" _addreferences:"mark multiple filekeys needed by an identifier" _detect:"look if the file belonging to a filekey exists and add to the database." _dumpcontents:"output contents of a part of the repository" _fakeemptyfilelist:"create an empty fake filelist cache item for a filekey" _forget:"forget a file specified by filekey." _listchecksums:"print a list of filekeys and their checksums" _listcodenames:"list configured codenames" _listconfidentifiers:"list parts of the repository in the configuration" _listdbidentifiers:"list parts of the repository in the database" _listmd5sums:"print a list of filekeys and their md5 hashes" _removereference:"manuall remove a reference" _removereferences:"remove all references by an identifier" ) _arguments \ '*'{-v,-V,--verbose}'[be more verbose]' \ '*--silent[be less verbose]' \ '*--delete[Delete files after inclusion]' \ '(-b --basedir)'{-b,--basedir}'[Base drectory]:basedir:_files -/' \ '--outdir[Directory where pool and dist are in]:out dir:_files -/' \ '--confdir[Directory where config files are]:config dir:_files -/' \ '--distdir[Directory where index files will be exported to]:dist dir:_files -/' \ '--logdir[Directory where log files will be generated]:log dir:_files -/' \ '--morguedir[Directory where files removed from the pool are stored]:morgue dir:_files -/' \ '--dbdir[Directory where the database is stored]:database dir:_files -/' \ '--listdir[Directory where downloaded index files will be stored]:list dir:_files -/' \ '--methoddir[Directory to search apt methods in]:method dir:_files -/' \ '(-C --component)'{-C,--component}'[Override component]:component:{_reprepro_components}' \ '(-A --architecture)'{-A,--architecture}'[Limit to a specific architecture]:architecture:{_reprepro_architectures}' \ '(-T --type)'{-T,--type}'[Limit to a specific type]:file type:(dsc deb udeb)' \ '(-S --section)'{-S,--section}'[Override section]:section:(admin base comm contrib devel doc editors electronics embedded games gnome graphics hamradio interpreters kde libs libdevel mail math misc net news non-free oldlibs otherosfs perl python science shells sound tex text utils web x11 contrib/admin contrib/base contrib/comm contrib/contrib contrib/devel contrib/doc contrib/editors contrib/electronics contrib/embedded contrib/games contrib/gnome contrib/graphics contrib/hamradio contrib/interpreters contrib/kde contrib/libs contrib/libdevel contrib/mail contrib/math contrib/misc contrib/net contrib/news contrib/non-free contrib/oldlibs contrib/otherosfs contrib/perl contrib/python contrib/science contrib/shells contrib/sound contrib/tex contrib/text contrib/utils contrib/web contrib/x11 non-free/admin non-free/base non-free/comm non-free/contrib non-free/devel non-free/doc non-free/editors non-free/electronics non-free/embedded non-free/games non-free/gnome non-free/graphics non-free/hamradio non-free/interpreters non-free/kde non-free/libs non-free/libdevel non-free/mail non-free/math non-free/misc non-free/net non-free/news non-free/non-free non-free/oldlibs non-free/otherosfs non-free/perl non-free/python non-free/science non-free/shells non-free/sound non-free/tex non-free/text non-free/utils non-free/web non-free/x11)' \ '(-P --priority)'{-P,--priority}'[Override priority]:priority:(required important standard optional extra)' \ '--export=[]:when:(silent-never never changed lookedat force)' \ '*--ignore=[Do ignore errors of some type]:error type:((\ ignore\:"ignore unknown ignore tags"\ flatandnonflat\:"ignore warnings about flat and non-flat distribution"\ forbiddenchar\:"allow more 7bit characters for names and versions"\ 8bit\:"allow 8 bit characters"\ emptyfilenamepart\:"allow strings used to construct filenames to be empty"\ spaceonlyline\:"do not warn about lines containing only spaces"\ malformedchunk\:"ignore lines without colons"\ unknownfield\:"ignore unknown fields"\ wrongdistribution\:"put .changes files in distributed they were not made for"\ wrongarchitecture\:"do not warn about wrong Architecture fields in downloaded Packages files"\ missingfield\:"allow missing fields"\ brokenold\:"ignore broken packages in database"\ brokenversioncmp\:"ignore versions not parseable"\ extension\:"ignore unexpected suffixes of files"\ unusedarch\:"allow changes files to list architectures not used"\ unusedoption\:"ignore command line options not used by an action"\ undefinedtarget\:"allow unspecified package databases"\ undefinedtracking\:"allow unspecified tracking databases"\ surprisingarch\:"do not protest when a changes file does not list a architecture it has files for"\ surprisingbinary\:"do not demand a .changes Binaries header to list all binaries"\ wrongsourceversion\:"do not demand coherent source versions in a .changes"\ wrongversion\:"do not demand coherent version of source packages in a .changes"\ dscinbinnmu\:"do not reject source files in what looks like a binMNU"\ brokensignatures\:"ignore corrupted signatures if there is a valid one"\ uploaders\:"allow even when forbidden by uploaders file"\ missingfile\:"include commands search harder for missing files like .orig.tar.gz"\ expiredkey\:"allow signatures with expired keys"\ expiredsignature\:"allow expired signatures"\ revokedkey\:"allow signatures with revoked keys"\ oldfile\:"silence warnings about strange old files in dists"\ longkeyid\:"do not warn about keyid in uploaders files gpgme might not accept"\ ))' \ '*--unignore=[Do not ignore errors of type]:error type:( ignore flatandnonflat forbiddenchar 8bit emptyfilenamepart\ spaceonlyline malformedchunk unknownfield unusedoption\ wrongdistribution missingfield brokenold brokenversioncmp\ extension unusedarch surprisingarch surprisingbinary\ wrongsourceversion wrongversion brokensignatures\ missingfile uploaders undefinedtarget undefinedtracking\ expiredkey expiredsignature revokedkey wrongarchitecture)' \ '--waitforlock=[Time to wait if database is locked]:count:(0 3600)' \ '--spacecheck[Mode for calculating free space before downloading packages]:behavior:(full none)' \ '--dbsafetymargin[Safety margin for the partition with the database]:bytes count:' \ '--safetymargin[Safety margin per partition]:bytes count:' \ '--gunzip[external Program to extract .gz files]:gunzip binary:_files' \ '--bunzip2[external Program to extract .bz2 files]:bunzip binary:_files' \ '--unlzma[external Program to extract .lzma files]:unlzma binary:_files' \ '--unxz[external Program to extract .xz files]:unxz binary:_files' \ '--lunzip[external Program to extract .lz files]:lunzip binary:_files' \ '--list-format[Format for list output]:listfilter format:' \ '--list-skip[Number of packages to skip in list output]:list skip:' \ '--list-max[Maximum number of packages in list output]:list max:' \ '(--nonothingiserror)--nothingiserror[Return error code when nothing was done]' \ '(--listsdownload --nonolistsdownload)--nolistsdownload[Do not download Release nor index files]' \ '(--nokeepunneededlists)--keepunneededlists[Do not delete list/ files that are no longer needed]' \ '(--nokeepunreferencedfiles)--keepunreferencedfiles[Do not delete files that are no longer used]' \ '(--nokeepunusednewfiles)--keepunusednewfiles[Do not delete newly added files that later were found to not be used]' \ '(--nokeepdirectories)--keepdirectories[Do not remove directories when they get empty]' \ '(--nokeeptemporaries)--keeptemporaries[When exporting fail do not remove temporary files]' \ '(--noask-passphrase)--ask-passphrase[Ask for passphrases (insecure)]' \ '(--nonoskipold --skipold)--noskipold[Do not ignore parts where no new index file is available]' \ '(--guessgpgtty --nonoguessgpgtty)--noguessgpgtty[Do not set GPG_TTY variable even when unset and stdin is a tty]' \ ':reprepro command:->commands' \ '2::arguments:->first' \ '3::arguments:->second' \ '4::arguments:->third' \ '*::arguments:->argument' && return 0 case "$state" in (commands) if [[ -prefix _* ]] ; then _describe "reprepro command" hiddencommands else _describe "reprepro command" commands fi ;; (first argument|second argument|third argument|argument) case "$words[1]" in (export|update|checkupdate|predelete|pull|checkpull|check|reoverride|repairdescriptions|forcerepairdescriptions|rereference|dumptracks|retrack|removealltracks|tidytracks|dumppull|dumpupdate|rerunnotifiers|unusedsources|sourcemissing|reportcruft) _reprepro_codenames ;; (checkpool) if [[ "$state" = "first argument" ]] ; then _wanted -V 'modifiers' expl 'modifier' compadd fast fi ;; (cleanlists|clearvanished|dumpreferences|dumpunreferened|deleteunreferenced|_listmd5sums|_listchecksums|_addmd5sums|_addchecksums|__dumpuncompressors|transatelegacychecksums|_listcodenames) ;; (_dumpcontents|_removereferences) if [[ "$state" = "first argument" ]] ; then _reprepro_identifiers fi ;; (_removereference) if [[ "$state" = "first argument" ]] ; then _reprepro_identifiers elif [[ "$state" = "second argument" ]] ; then _reprepro_filekeys fi ;; (list|listfilter|listmatched) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames fi ;; (remove) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames else _reprepro_package_names "$words[2]" fi ;; # removesrcs might be improveable... (removesrc|removesrcs) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames else _reprepro_source_package_names "$words[2]" fi ;; (removefilter|removematched) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames fi ;; (gensnapshot|unreferencesnapshot) # TODO: for unreferencesnapshot get instead a list of existing ones if [[ "$state" = "first argument" ]] ; then _reprepro_codenames elif [[ "$state" = "second argument" ]] ; then _wanted -V 'snapshot names' expl 'snapshot name' compadd $(date -I) fi ;; (removetrack) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames elif [[ "$state" = "second argument" ]] ; then _reprepro_source_package_names "$words[2]" elif [[ "$state" = "third argument" ]] ; then #and version... fi ;; (includedeb) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames elif [[ "$state" = "second argument" ]] ; then _files -g "*.deb" fi ;; (includedsc) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames elif [[ "$state" = "second argument" ]] ; then _files -g "*.dsc" fi ;; (__extractsourcesection) if [[ "$state" = "first argument" ]] ; then _files -g "*.dsc" fi ;; (copy|copysrc|copyfilter|copymatched) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames elif [[ "$state" = "second argument" ]] ; then _reprepro_codenames fi ;; (restore|restoresrc|restorefilter|restorematched) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames # TODO: # elif [[ "$state" = "second argument" ]] ; then # _reprepro_codenames fi ;; (include) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames elif [[ "$state" = "second argument" ]] ; then _files -g "*.changes" fi ;; (__extractfilelist|__extractcontrol) _files -g "*.deb" ;; (processincoming) if [[ "$state" = "first argument" ]] ; then _reprepro_incomings elif [[ "$state" = "second argument" ]] ; then _reprepro_incomingdir "$words[2]" \ && _files -g "*.changes" -W list \ || _files -g "*.changes" fi ;; (_detect|_forget) _reprepro_filekeys ;; (_fakeemptyfilelist) if [[ "$state" = "first argument" ]] ; then _reprepro_filekeys fi ;; (_addreference) if [[ "$state" = "first argument" ]] ; then _reprepro_filekeys elif [[ "$state" = "second argument" ]] ; then _reprepro_identifiers fi ;; (_addreferences) if [[ "$state" = "first argument" ]] ; then _reprepro_identifiers else _reprepro_filekeys fi ;; (__uncompress) if [[ "$state" = "first argument" ]] ; then uncompressions=(.gz .bz2 .lzma .xz .lz) _wanted -V 'uncompressions' expl 'uncompression' compadd -a uncompressions elif [[ "$state" = "second argument" ]] ; then _files elif [[ "$state" = "third argument" ]] ; then _files fi ;; (build-needing) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames elif [[ "$state" = "second argument" ]] ; then _reprepro_architectures ##TODO elif [[ "$state" = "third argument" ]] ; then ##TODO _reprepro_glob fi ;; (flood) if [[ "$state" = "first argument" ]] ; then _reprepro_codenames elif [[ "$state" = "second argument" ]] ; then _reprepro_architectures fi ;; (*) _files ;; esac ;; esac