diff options
author | heqnx <root@heqnx.com> | 2025-05-27 22:06:29 +0300 |
---|---|---|
committer | heqnx <root@heqnx.com> | 2025-05-27 22:06:29 +0300 |
commit | 97ae6428b95aeed473cebb0d007d2059ae1545d6 (patch) | |
tree | 98f2a63ded02996297fe0a81a3f7c4db120f6720 /cgit-backup.sh | |
parent | 7bc1627859461cddbedd9317bd729356f001b868 (diff) | |
download | gists-97ae6428b95aeed473cebb0d007d2059ae1545d6.tar.gz gists-97ae6428b95aeed473cebb0d007d2059ae1545d6.zip |
improved and changed name of script
Diffstat (limited to 'cgit-backup.sh')
-rw-r--r-- | cgit-backup.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/cgit-backup.sh b/cgit-backup.sh new file mode 100644 index 0000000..276dce5 --- /dev/null +++ b/cgit-backup.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +cgit="https://cgit.heqnx.com" + +mkdir -p repos + +repos=$(curl -sSL "${cgit}" | grep -o "<a href='/[^']*/'>" | sed -E "s/^<a href='([^']*)'>/\1/" | sort -u) + +while IFS= read -r repo_path; do + repo_name=$(basename "${repo_path}") + repo_url="${cgit}${repo_path}" + repo_dir="repos/${repo_name}" + + printf "%s\n" "[inf] processing ${repo_url}" + + if test -d "${repo_dir}"; then + if test -d "${repo_dir}/.git.bak"; then + printf "%s\n" "[inf] restoring .git from .git.bak for ${repo_name}" + mv "${repo_dir}/.git.bak" "${repo_dir}/.git" + fi + printf "%s\n" "[inf] fetching updates for ${repo_name}" + git -C "${repo_dir}" fetch origin + git -C "${repo_dir}" reset --hard origin/HEAD + else + printf "%s\n" "[inf] cloning ${repo_name}" + git -C repos clone "${repo_url}" + fi + + if test -d "${repo_dir}/.git"; then + printf "%s\n" "[inf] moving .git to .git.bak for ${repo_name}" + mv "${repo_dir}/.git" "${repo_dir}/.git.bak" + fi + +done <<< "${repos}" |