Move scripts to separate directory
This commit is contained in:
73
src/sclone
Executable file
73
src/sclone
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Clone repository from mirror - recursively with submodules
|
||||
#
|
||||
# Usage:
|
||||
# sclone <main repo url> [ -p <path> ] [ -c <checkout_ref>
|
||||
|
||||
# strict mode
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# Scratch - temp
|
||||
tmpdir=$(mktemp -d -t mirror-recursive-XXXXXXX)
|
||||
function finish {
|
||||
rm -rf "$tmpdir"
|
||||
}
|
||||
trap finish EXIT
|
||||
|
||||
# include config
|
||||
source $(dirname $(realpath $0))/config
|
||||
source $(dirname $(realpath $0))/gen-mirror-path
|
||||
|
||||
# parse arguments
|
||||
function usage(){
|
||||
echo "Usage: $0 [-p <path>] [-c <checkout_ref>]" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ $# -eq 0 ] && usage
|
||||
|
||||
repo=$1
|
||||
|
||||
|
||||
# clone the repo
|
||||
cclone $@ || true
|
||||
# skip url
|
||||
shift
|
||||
|
||||
# parse opts
|
||||
while getopts "c:p:" o; do
|
||||
case "${o}" in
|
||||
c)
|
||||
param_c=${OPTARG}
|
||||
;;
|
||||
p)
|
||||
param_p=${OPTARG}
|
||||
;;
|
||||
\?)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# change dir and examine the commit + submodules
|
||||
oldpwd=$(pwd)
|
||||
submodules=$tmpdir/submodules
|
||||
cd ${param_p:-$(getRepoUniq $repo)}
|
||||
submodule-describe . > $submodules
|
||||
|
||||
while read -r line || [[ -n "$line" ]]
|
||||
do
|
||||
# read -r retypes \t to ' ' (space)
|
||||
commit=$(echo $line | cut -f1 -d' ')
|
||||
directory=$(echo $line | cut -f2 -d' ')
|
||||
url=$(echo $line | cut -f3 -d' ')
|
||||
# recursion ++
|
||||
sclone $url -p $directory -c $commit
|
||||
done < $submodules
|
||||
|
||||
|
||||
|
||||
cd $oldpwd
|
||||
|
||||
Reference in New Issue
Block a user