Skip to content

Commit

Permalink
Add script to update token (#8)
Browse files Browse the repository at this point in the history
* Add script to update token

* docs(README): Update README
  • Loading branch information
brighteyed authored May 21, 2022
1 parent b188646 commit 3064a16
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ docker run --rm -e GITHUB_USENAME="changeme" \
--name=gh-mirror \
ghcr.io/brighteyed/gh-mirror:latest
```
To update Github token execute `update_token.py`:
```
docker run --rm -v "/path/to/gitea/data/git/repositories:/repositories" ghcr.io/brighteyed/gh-mirror:latest update_token.py --old-token="<old_token>" --new-token="<new_token>"
```

## Clone starred repositories

Expand Down
6 changes: 5 additions & 1 deletion docker/mirror/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ RUN apk update && apk add gcc libc-dev libffi-dev \
&& apk del gcc libc-dev libffi-dev

COPY gh_mirror.py ./
COPY update_token.py ./

CMD [ "python", "./gh_mirror.py" ]
VOLUME [ "/repositories" ]

ENTRYPOINT [ "python" ]
CMD [ "gh_mirror.py" ]
22 changes: 22 additions & 0 deletions update_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python

import glob
import argparse

if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Replace tokens')
parser.add_argument("--old-token", help="Old token", required=True)
parser.add_argument("--new-token", help="New token", required=True)
args = parser.parse_args()

for path in glob.glob("/repositories/*/*.git/config", recursive=True):
repo_name = path.replace("/repositories/", "").replace(".git/config", "")
print(f"Updating: {repo_name}")

with open(path, 'r', encoding="utf-8") as file:
filedata = file.read()

filedata = filedata.replace(f"{args.old_token}", f"{args.new_token}")

with open(path, 'w', encoding="utf-8") as file:
file.write(filedata)

0 comments on commit 3064a16

Please sign in to comment.