github-gitea-mirror/bulk-update-github-auth-token.py
2020-10-25 20:23:20 +05:30

29 lines
1.0 KiB
Python

#!/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(" ")