From 3054f253e8b452a9dd0fe05e6095dfe23435b448 Mon Sep 17 00:00:00 2001 From: bursa-pastoris Date: Sat, 2 Apr 2022 14:46:10 +0200 Subject: [PATCH] First commit --- LICENSE | 19 ++++++++++++++++ README.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 17 ++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100755 main.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..88e31b9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright 2022 bursa-pastoris + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..77c6886 --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ +`yagrmm` (Yet Another Git Remote Mirror Manager) is a simple script to +automatically update remote mirrors or git repositories. At the moment +`yagrmm` only works only if push and pull can be done without SSH keys without +passphrase or without authentication at all. + +Whenever `yagrmm` is run, it will pull new commits from the original repo and +push them to the mirror. It can be run manually or periodically - e.g. with +`crontab`. + +## Notice - Please read this + +Some software provide the option to configure mirroring from the web interface, +so that the server automatically pulls commits from the original repo - that's +the case for +[GitLab](https://docs.gitlab.com/ee/user/project/repository/mirror/) and +[Gitea](https://docs.gitea.io/en-us/repo-mirror/#pulling-from-a-remote-repository). +If your provider uses one of these softwares but has disabled such function, he +probably has good reasons for doing so - usually limited server resources. If +your run `yagrmm` periodically, please limit yourself to the strictly necessary +and do not hoard your provider's resources. + +## How-to + +To use `yagrmm`, follow these steps. + +1. Create a local mirror of the repository to mirror with `git clone --mirror + `. +2. Add the path of the mirror to `~/.config/yagrmm/repolist`. `~` can be used + to refer to `/home/` and is always expanded. +3. In the copy of the repository, edit `config` and in the section `[remote + "origin"]` add the following line below the one beginning with `URL = `: + + pushUrl = + + so that the resulting section looks like + + [remote "origin"] + url = + pushUrl = + fetch = +refs/*:refs/* + mirror = true + + +If - as you should - you push to the mirror with a key different from the one +you use to manual pushes to other repos (such as +[GitLab](https://docs.gitlab.com/ee/user/project/deploy_keys/) and Gitea's +deploy keys), you may find useful a trick to make SSH use the right one. You +must configure SSH adding a paragraph like the following to `~/.ssh/config`: + + Host mirror. + HostName + IdentityFile + +For example: + + Host mirror.disroot.org + HostName disroot.org + IdentityFile ~/.ssh/mirror_push_key + +And then you can use `mirror.` as the domain name +for the `pushUrl`, for example + + pushUrl = git@mirror.disroot.org:username/disroot-howto-mirror.git + +# License + +`yagrmm` is distributed under the [Expat (aka MIT) license](./LICENSE). diff --git a/main.py b/main.py new file mode 100755 index 0000000..efffccf --- /dev/null +++ b/main.py @@ -0,0 +1,17 @@ +#!/usr/bin/python3 + +from pathlib import Path as path +from subprocess import run + +home = str(path.home()) + +with open(home+"/.config/yagrmm/repolist") as repolist_file: + repolist = repolist_file.read().splitlines() + +for i in range(len(repolist)): + repolist[i] = repolist[i].replace("~", home) + +for repo in repolist: + print(repo) + run(["git", "-C", repo, "pull"]) + run(["git", "-C", repo, "push"])