diff --git a/homebrew.sh b/homebrew.sh index 9e2abfb..d195977 100755 --- a/homebrew.sh +++ b/homebrew.sh @@ -1,17 +1,25 @@ #!/bin/bash -if [ ! -d "$TUNASYNC_WORKING_DIR" ]; then - echo "Directory not exists, fail" - exit 1 -fi +function repo_init() { + UPSTREAM=$1 + WORKING_DIR=$2 + git clone --mirror $UPSTREAM $WORKING_DIR +} function update_homebrew_git() { repo_dir="$1" cd $repo_dir echo "==== SYNC $repo_dir START ====" /usr/bin/timeout -s INT 3600 git remote -v update + git repack -a -b -d echo "==== SYNC $repo_dir DONE ====" } -update_homebrew_git "$TUNASYNC_WORKING_DIR/homebrew.git" -update_homebrew_git "$TUNASYNC_WORKING_DIR/homebrew-python.git" -update_homebrew_git "$TUNASYNC_WORKING_DIR/homebrew-science.git" +brews=("brew" "homebrew-core" "homebrew-python" "homebrew-science") + +for brew in ${brews[@]}; do + if [[ ! -d "$TUNASYNC_WORKING_DIR/${brew}.git" ]]; then + echo "Initializing ${brew}.git" + repo_init "https://github.com/Homebrew/${brew}.git" "$TUNASYNC_WORKING_DIR/${brew}.git" + fi + update_homebrew_git "$TUNASYNC_WORKING_DIR/${brew}.git" +done diff --git a/linux.sh b/linux.sh index dca5e3c..0985746 100755 --- a/linux.sh +++ b/linux.sh @@ -1,12 +1,21 @@ #!/bin/bash -if [ ! -d "$TUNASYNC_WORKING_DIR" ]; then - echo "Directory not exists, fail" - exit 1 -fi +UPSTREAM=${TUNASYNC_UPSTREAM_URL:-"git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git"} + +function repo_init() { + git clone --mirror $UPSTREAM $TUNASYNC_WORKING_DIR +} function update_linux_git() { cd $TUNASYNC_WORKING_DIR + echo "==== SYNC linux.git START ====" /usr/bin/timeout -s INT 3600 git remote -v update + git repack -a -b -d + echo "==== SYNC linux.git DONE ====" } +if [[ ! -d "$TUNASYNC_WORKING_DIR" ]]; then + echo "Initializing Linux.git mirror" + repo_init +fi + update_linux_git