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 | |
parent | 7bc1627859461cddbedd9317bd729356f001b868 (diff) | |
download | gists-97ae6428b95aeed473cebb0d007d2059ae1545d6.tar.gz gists-97ae6428b95aeed473cebb0d007d2059ae1545d6.zip |
improved and changed name of script
-rw-r--r-- | cgit-backup.sh | 34 | ||||
-rw-r--r-- | clone-all-cgit-repos.sh | 11 |
2 files changed, 34 insertions, 11 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}" diff --git a/clone-all-cgit-repos.sh b/clone-all-cgit-repos.sh deleted file mode 100644 index 1fdf658..0000000 --- a/clone-all-cgit-repos.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -cgit="https://cgit.heqnx.com" - -repos=$(curl -sSL "${cgit}" | grep -o "<a href='/[^']*/'>" | sed -E "s/^<a href='([^']*)'>/\1/" | sort -u) - -mkdir repos &>/dev/null -while IFS= read -r i; do - printf "%s\n" "[inf] ${cgit}${i}" - git -C repos clone "${cgit}${i}" -done <<< "${repos}" |