-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbulk-update-github-auth-token.py
29 lines (22 loc) · 1.01 KB
/
bulk-update-github-auth-token.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
#################################################################
### This file can be used to bulk update ###
### all repositories with new auth token ###
### Because Gitea Currently Dose not provide a option for it. ###
### Usage : python3 bulk-update-github-auth-token.py ###
#################################################################
import glob
from pathlib import Path
BASEPATH = "/var/lib/gitea/gitea-repositories/"
SEARCH_PATH = "*/*/config"
SEARCH_TOKEN = "OLD_GITHUB_AUTH_TOKEN"
REPLACE_TOKEN = "NEW_GITHUB_AUTH_TOKEN"
for path in glob.glob("{0}{1}".format(BASEPATH,SEARCH_PATH), recursive=True):
LOG_HEAD = path.replace(BASEPATH,"")
print("Updating : {0}".format(LOG_HEAD.replace(".git/config","")))
with open(path, 'r') as file :
filedata = file.read()
filedata = filedata.replace("{0}@".format(SEARCH_TOKEN),"{0}@".format(REPLACE_TOKEN))
with open(path, 'w') as file:
file.write(filedata)
print(" ")