mirror of
https://github.com/standardebooks/web.git
synced 2025-07-10 00:30:28 -04:00
Add --bare option, default to working directory clones
This commit is contained in:
parent
e27c63b41e
commit
24e8d1cec5
1 changed files with 24 additions and 7 deletions
|
@ -3,7 +3,7 @@ set -e
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
usage(){
|
usage(){
|
||||||
fmt <<EOF
|
cat <<EOF
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
Syncs books from standardebooks.org GitHub org to specified folder.
|
Syncs books from standardebooks.org GitHub org to specified folder.
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ USAGE
|
||||||
With -v or --verbosity 1, display general progress updates.
|
With -v or --verbosity 1, display general progress updates.
|
||||||
With -vv or --verbosity 2, display general progress updates and verbose git output.
|
With -vv or --verbosity 2, display general progress updates and verbose git output.
|
||||||
With --update-only, only sync existing repositories, do not download new repositories.
|
With --update-only, only sync existing repositories, do not download new repositories.
|
||||||
|
With -b or --bare, clone a bare repository (for a server) instead of a working directory
|
||||||
With --token TOKEN, specify a GitHub access token to use for request. Useful for when you hit the rate limit.
|
With --token TOKEN, specify a GitHub access token to use for request. Useful for when you hit the rate limit.
|
||||||
|
|
||||||
DIRECTORY should be where the repositories should go.
|
DIRECTORY should be where the repositories should go.
|
||||||
|
@ -48,6 +49,7 @@ verbosity=0
|
||||||
updateOnly="false"
|
updateOnly="false"
|
||||||
githubToken=""
|
githubToken=""
|
||||||
target=""
|
target=""
|
||||||
|
bare=""
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
@ -75,6 +77,10 @@ while [ $# -gt 0 ]; do
|
||||||
githubToken="$2"
|
githubToken="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
-b|--bare)
|
||||||
|
bare="--bare"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
break ;;
|
break ;;
|
||||||
esac
|
esac
|
||||||
|
@ -164,13 +170,21 @@ fi
|
||||||
repoUrls=$(printf "%s" "${repoUrls}" | grep -v -e "/tools.git\$" -e "/web.git\$" -e "/manual.git\$" | awk 'NF')
|
repoUrls=$(printf "%s" "${repoUrls}" | grep -v -e "/tools.git\$" -e "/web.git\$" -e "/manual.git\$" | awk 'NF')
|
||||||
|
|
||||||
printf "%s\n" "${repoUrls}" | while IFS= read -r repoUrl; do
|
printf "%s\n" "${repoUrls}" | while IFS= read -r repoUrl; do
|
||||||
|
# make sure it's not an empty string
|
||||||
[ -n "${repoUrl}" ] || continue
|
[ -n "${repoUrl}" ] || continue
|
||||||
[ -d "${repoUrl##*/}" ] && continue
|
|
||||||
|
|
||||||
|
# strip everything prior to the last segment of the name
|
||||||
repoName="${repoUrl##*/}"
|
repoName="${repoUrl##*/}"
|
||||||
|
if [ "${bare}" = "" ]; then
|
||||||
|
repoName="${repoName%.git}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if the repo already exists, skip it (handled in the update above)
|
||||||
|
[ -d "${repoName}" ] && continue
|
||||||
|
|
||||||
repoNameLength=$(printf "%s" "${repoName}" | wc -m)
|
repoNameLength=$(printf "%s" "${repoName}" | wc -m)
|
||||||
if [ "${repoNameLength}" -ge 100 ]; then
|
if [ "${repoNameLength}" -ge 100 ]; then
|
||||||
if dirs=( "${repoName%%.git}"*/ ) && [[ -d ${dirs[0]} ]]; then
|
if dirs=( "${repoName}"*/ ) && [[ -d ${dirs[0]} ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -180,9 +194,9 @@ printf "%s\n" "${repoUrls}" | while IFS= read -r repoUrl; do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${verbosity}" -lt 2 ]; then
|
if [ "${verbosity}" -lt 2 ]; then
|
||||||
git clone -q --bare "${repoUrl}"
|
git clone -q ${bare} "${repoUrl}"
|
||||||
else
|
else
|
||||||
git clone -v --bare "${repoUrl}"
|
git clone -v ${bare} "${repoUrl}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -d "${repoName}" ]; then
|
if ! [ -d "${repoName}" ]; then
|
||||||
|
@ -196,8 +210,11 @@ printf "%s\n" "${repoUrls}" | while IFS= read -r repoUrl; do
|
||||||
sed -E "s/<[^>]+?>//g" |
|
sed -E "s/<[^>]+?>//g" |
|
||||||
sed -E "s|url:https://standardebooks.org/ebooks/||g" |
|
sed -E "s|url:https://standardebooks.org/ebooks/||g" |
|
||||||
sed -E "s|/|_|g").git"
|
sed -E "s|/|_|g").git"
|
||||||
|
if [ "${bare}" = "" ]; then
|
||||||
|
properName="${properName%.git}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "${repoUrl##*/}" != "${properName}" ]; then
|
if [ "${repoName}" != "${properName}" ]; then
|
||||||
if [ "${verbosity}" -gt 0 ]; then
|
if [ "${verbosity}" -gt 0 ]; then
|
||||||
printf "Moving %s to %s\n" "${repoName}" "${properName}"
|
printf "Moving %s to %s\n" "${repoName}" "${properName}"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue