1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-08-18 20:30:09 +02:00
fdroidserver/completion/bash-completion
Hans-Christoph Steiner 2162703a1a mirror: new command to make a mirror of a repo
This creates a mirror of a full repo by downloading all files listed in
the index, and the ones that are generated based on that data, e.g. icons
of different resolutions.  This could be useful for setting up mirrors of
small repositories, instead of having to learn and manage rsync or
something else for mirroring.  This just needs a working repo.

It uses wget in a batch mode with the aim as being as efficient as
possible.  wget mirroring over HTTP is always going to be less efficient
than rsync, but it shouldn't be so bad since it uses --continue to check
whether it has already downloaded a file.  I suppose it could be extended
to use ETags for a little more efficiency.

I developed this creating a test mirror of f-droid.org, which is now a bit
ironic, since I added a specific check to prevent people from using this
on f-droid.org.
2017-11-29 12:40:04 +01:00

363 lines
6.3 KiB
Bash

# fdroid(1) completion -*- shell-script -*-
#
# bash-completion - part of the FDroid server tools
#
# Copyright (C) 2013-2017 Hans-Christoph Steiner <hans@eds.org>
# Copyright (C) 2013, 2014 Daniel Martí <mvdan@mvdan.cc>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
__fdroid_init() {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
(( $# >= 1 )) && __complete_${1}
}
__by_ext() {
local ext="$1"
files=( metadata/*.$ext )
files=( ${files[@]#metadata/} )
files=${files[@]%.$ext}
echo "$files"
}
__package() {
files="$(__by_ext txt) $(__by_ext yaml) $(__by_ext json) $(__by_ext xml)"
COMPREPLY=( $( compgen -W "$files" -- $cur ) )
}
__apk_package() {
files=( ${1}/*.apk )
[ -f "${files[0]}" ] || return
files=( ${files[@]#*/} )
files=${files[@]%_*}
COMPREPLY=( $( compgen -W "$files" -- $cur ) )
}
__apk_vercode() {
local p=${cur:0:-1}
files=( ${1}/${p}_*.apk )
[ -f "${files[0]}" ] || return
files=( ${files[@]#*_} )
files=${files[@]%.apk}
COMPREPLY=( $( compgen -P "${p}:" -W "$files" -- $cur ) )
}
__vercode() {
local p v
echo $cur | IFS=':' read p v
COMPREPLY=( $( compgen -P "${p}:" -W "$( while read line; do
if [[ "$line" == "Build Version:"* ]]
then
line="${line#*,}"
printf "${line%%,*} "
elif [[ "$line" == "Build:"* ]]
then
line="${line#*,}"
printf "${line%%,*} "
fi
done < "metadata/${p}.txt" )" -- $cur ) )
}
__complete_options() {
case "${cur}" in
--*)
COMPREPLY=( $( compgen -W "--help --version ${lopts}" -- $cur ) )
return 0;;
*)
COMPREPLY=( $( compgen -W "-h ${opts} --help --version ${lopts}" -- $cur ) )
return 0;;
esac
}
__complete_build() {
opts="-v -q -l -s -t -f -a -w"
lopts="--verbose --quiet --latest --stop --test --server --resetserver
--on-server --skip-scan --no-tarball --force --all --wiki --no-refresh"
case "${cur}" in
-*)
__complete_options
return 0;;
*:*)
__vercode
return 0;;
*)
__package
return 0;;
esac
}
__complete_dscanner() {
opts="-v -q -l"
lopts="--verbose --quiet --clean-after --clean-before --clean-only --init-only --latest --repo-path"
case "${cur}" in
-*)
__complete_options
return 0;;
*:)
__vercode
return 0;;
*)
__package
return 0;;
esac
}
__complete_gpgsign() {
opts="-v -q"
lopts="--verbose --quiet"
__complete_options
}
__complete_install() {
opts="-v -q"
lopts="--verbose --quiet --all"
case "${cur}" in
-*)
__complete_options
return 0;;
*:)
__apk_vercode repo
return 0;;
*)
__apk_package repo
return 0;;
esac
}
__complete_update() {
opts="-c -v -q -b -i -I -e -w"
lopts="--create-metadata --verbose --quiet --buildreport
--interactive --icons --editor --wiki --pretty --clean --delete-unknown
--nosign --rename-apks --use-date-from-apk"
case "${prev}" in
-e|--editor)
_filedir
return 0;;
esac
__complete_options
}
__complete_publish() {
opts="-v -q"
lopts="--verbose --quiet"
case "${cur}" in
-*)
__complete_options
return 0;;
*:)
__apk_vercode unsigned
return 0;;
*)
__apk_package unsigned
return 0;;
esac
}
__complete_checkupdates() {
opts="-v -q"
lopts="--verbose --quiet --auto --autoonly --commit --gplay"
case "${cur}" in
-*)
__complete_options
return 0;;
*)
__package
return 0;;
esac
}
__complete_import() {
opts="-u -s -q"
lopts="--url --subdir --rev --quiet"
case "${prev}" in
-u|--url|-s|--subdir|--rev) return 0;;
esac
__complete_options
}
__complete_readmeta() {
opts="-v -q"
lopts="--verbose --quiet"
__complete_options
}
__complete_rewritemeta() {
opts="-v -q -l"
lopts="--verbose --quiet --list"
case "${cur}" in
-*)
__complete_options
return 0;;
*)
__package
return 0;;
esac
}
__complete_lint() {
opts="-v -q"
lopts="--verbose --quiet"
case "${cur}" in
-*)
__complete_options
return 0;;
*)
__package
return 0;;
esac
}
__complete_scanner() {
opts="-v -q"
lopts="--verbose --quiet"
case "${cur}" in
-*)
__complete_options
return 0;;
*:)
__vercode
return 0;;
*)
__package
return 0;;
esac
}
__complete_verify() {
opts="-v -q -p"
lopts="--verbose --quiet"
case "${cur}" in
-*)
__complete_options
return 0;;
*:)
__vercode
return 0;;
*)
__package
return 0;;
esac
}
__complete_btlog() {
opts="-u"
lopts="--git-remote --git-repo --url"
__complete_options
}
__complete_mirror() {
opts="-v"
lopts="--archive --output-dir"
__complete_options
}
__complete_nightly() {
opts="-v -q"
lopts="--show-secret-var"
__complete_options
}
__complete_stats() {
opts="-v -q -d"
lopts="--verbose --quiet --download"
__complete_options
}
__complete_server() {
opts="-i -v -q"
lopts="--identity-file --local-copy-dir --sync-from-local-copy-dir
--verbose --quiet --no-checksum update"
__complete_options
}
__complete_signatures() {
opts="-v -q"
lopts="--verbose --no-check-https"
case "${cur}" in
-*)
__complete_options
return 0;;
esac
}
__complete_signindex() {
opts="-v -q"
lopts="--verbose"
__complete_options
}
__complete_init() {
opts="-v -q -d"
lopts="--verbose --quiet --distinguished-name --keystore
--repo-keyalias --android-home --no-prompt"
__complete_options
}
__cmds=" \
btlog \
build \
checkupdates \
dscanner \
gpgsign \
import \
init \
install \
lint \
mirror \
nightly \
publish \
readmeta \
rewritemeta \
scanner \
server \
signatures \
signindex \
stats \
update \
verify \
"
for c in $__cmds; do
eval "_fdroid_${c} () {
local cur prev opts lopts
__fdroid_init ${c}
}"
done
_fdroid() {
local cmd
cmd=${COMP_WORDS[1]}
[[ $__cmds == *\ $cmd\ * ]] && _fdroid_${cmd} || {
(($COMP_CWORD == 1)) && COMPREPLY=( $( compgen -W "${__cmds}" -- $cmd ) )
}
}
_fd-commit() {
__package
}
complete -F _fdroid fdroid
complete -F _fd-commit fd-commit
return 0