mirror of
https://github.com/standardebooks/web.git
synced 2025-07-08 07:40:39 -04:00
Update sync-ebooks code style
This commit is contained in:
parent
66dfebed19
commit
c779f72d3b
1 changed files with 69 additions and 44 deletions
|
@ -1,6 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
set -u
|
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
usage(){
|
usage(){
|
||||||
|
@ -9,11 +8,11 @@ DESCRIPTION
|
||||||
Syncs books from standardebooks.org GitHub org to specified folder.
|
Syncs books from standardebooks.org GitHub org to specified folder.
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
${0##*/} [-h] [-v|-vv] [-u] DIRECTORY
|
${0##*/} [-v,-vv,--verbosity=INTEGER] [-u,--update-only] DIRECTORY
|
||||||
|
|
||||||
-h displays this message
|
With -v or --verbosity=1, display general progress updates.
|
||||||
-v displays general progress updates
|
With -vv or --verbosity=2, display general progress updates and verbose git output.
|
||||||
-vv displays progress updates and verbose git output
|
With --update-only, only sync existing repositories, do not download new repositories.
|
||||||
|
|
||||||
DIRECTORY should be where the repositories should go.
|
DIRECTORY should be where the repositories should go.
|
||||||
|
|
||||||
|
@ -22,64 +21,84 @@ EXAMPLE
|
||||||
EOF
|
EOF
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
die(){ printf "\033[0;7;31mError:\033[0m %s\n" "${1}" 1>&2; exit 1; }
|
||||||
|
if [ $# -eq 1 ]; then if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then usage; fi fi
|
||||||
|
# End boilerplate
|
||||||
|
|
||||||
# Terminate on CTRL-C
|
# Terminate on CTRL-C
|
||||||
trap ctrl_c INT
|
trap ctrl_c INT
|
||||||
ctrl_c() {
|
ctrl_c() {
|
||||||
printf "** Trapped CTRL-C\n"
|
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
verbosity=0
|
if [[ $# -lt 1 ]]; then
|
||||||
update_only="false"
|
|
||||||
while getopts ":hvu" option; do
|
|
||||||
case "${option}" in
|
|
||||||
h) usage ;;
|
|
||||||
v) verbosity=$((verbosity + 1)) ;;
|
|
||||||
u) update_only="true" ;;
|
|
||||||
?) usage ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
shift "$((OPTIND -1))"
|
|
||||||
|
|
||||||
if [ -z "$*" ]; then
|
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -d "$*" ]; then
|
verbosity=0
|
||||||
>&2 printf "%s does not exist.\n" "$*"
|
updateOnly="false"
|
||||||
exit
|
target=""
|
||||||
|
|
||||||
|
for i in "$@"
|
||||||
|
do
|
||||||
|
case $i in
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
-v)
|
||||||
|
verbosity=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-vv)
|
||||||
|
verbosity=2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--verbosity=*)
|
||||||
|
verbosity=${i//[-a-zA-Z0-9]*=/}
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-u|--update-only)
|
||||||
|
updateOnly="true"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
target="${i}"
|
||||||
|
shift
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if ! [ -d "${target}" ]; then
|
||||||
|
die "${target} is not a directory."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! cd "$*"; then
|
if ! cd "${target}"; then
|
||||||
>&2 printf "Couldn't cd into %s.\n" "$*"
|
die "Couldn’t cd into ${target}"
|
||||||
exit
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${verbosity}" -gt 0 ]; then
|
if [ "${verbosity}" -gt 0 ]; then
|
||||||
printf "** Updating local repositories. **\n"
|
printf "Updating local repositories ... \n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for item in ./*; do
|
for item in ./*; do
|
||||||
[ -e "${item}" ] || break
|
[ -e "${item}" ] || break
|
||||||
if [ "${verbosity}" -gt 0 ]; then
|
|
||||||
printf "Updating %s\n" "${item}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${verbosity}" -gt 1 ]; then
|
if [ "${verbosity}" -eq 1 ]; then
|
||||||
git -C "${item}" fetch -v
|
printf "Updating %s ... " "${item}"
|
||||||
else
|
|
||||||
git -C "${item}" fetch -q
|
git -C "${item}" fetch -q
|
||||||
|
printf "Done.\n"
|
||||||
|
elif [ "${verbosity}" -gt 1 ]; then
|
||||||
|
printf "Updating %s ... \n" "${item}"
|
||||||
|
git -C "${item}" fetch -v
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "${update_only}" = "true" ]; then
|
if [ "${updateOnly}" = "true" ]; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${verbosity}" -gt 0 ]; then
|
if [ "${verbosity}" -gt 0 ]; then
|
||||||
printf "** Cloning remote repositories. **\n"
|
printf "Cloning remote repositories ... \n"
|
||||||
printf "Fetching repository urls"
|
printf "Fetching repository urls ..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
page=1
|
page=1
|
||||||
|
@ -97,7 +116,7 @@ while [ -n "${pageurls}" ]; do
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "${verbosity}" -gt 0 ]; then
|
if [ "${verbosity}" -gt 0 ]; then
|
||||||
printf "\n"
|
printf " Done.\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
urls=$(printf "%s\n" "${urls}" | grep -v -e "/tools.git\$" -e "/web.git\$" -e "/manual.git\$" | awk 'NF')
|
urls=$(printf "%s\n" "${urls}" | grep -v -e "/tools.git\$" -e "/web.git\$" -e "/manual.git\$" | awk 'NF')
|
||||||
|
@ -106,17 +125,23 @@ printf "%s\n" "${urls}" | while IFS= read -r repourl; do
|
||||||
[ -n "${repourl}" ] || continue
|
[ -n "${repourl}" ] || continue
|
||||||
[ -d "${repourl##*/}" ] && continue
|
[ -d "${repourl##*/}" ] && continue
|
||||||
|
|
||||||
if [ "${verbosity}" -gt 0 ]; then
|
|
||||||
printf "Cloning %s\n" "${repourl}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${verbosity}" -gt 1 ]; then
|
if [ "${verbosity}" -gt 1 ]; then
|
||||||
|
printf "Cloning %s ... \n" "${repourl}"
|
||||||
git clone -v --bare "${repourl}"
|
git clone -v --bare "${repourl}"
|
||||||
else
|
|
||||||
git clone -q --bare "${repourl}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! [ -d "${repourl##*/}" ]; then
|
if ! [ -d "${repourl##*/}" ]; then
|
||||||
>&2 printf "%s wasn't cloned." "${repourl}"
|
printf "Failed.\n"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ "${verbosity}" -gt 0 ]; then
|
||||||
|
printf "Cloning %s ... " "${repourl}"
|
||||||
|
fi
|
||||||
|
git clone -q --bare "${repourl}"
|
||||||
|
if [ "${verbosity}" -gt 0 ]; then
|
||||||
|
if ! [ -d "${repourl##*/}" ]; then
|
||||||
|
printf "Failed.\n"
|
||||||
|
else
|
||||||
|
printf "Done.\n"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue