56 lines
1.4 KiB
Lua
56 lines
1.4 KiB
Lua
-- 导入 os 模块
|
|
local os = require("os")
|
|
local io = require("io")
|
|
local fs = require("lua_fs")
|
|
|
|
local url = "https://www.sinxmiao.cn/"
|
|
local backup_name = "gitea_backup"
|
|
|
|
local current_path = fs.get_current_directory()
|
|
print("Current: " .. current_path)
|
|
|
|
local parent_path = fs.get_parent(current_path)
|
|
print("Parent: " .. parent_path)
|
|
|
|
local config_path = current_path .. "/repo_list.txt"
|
|
|
|
if not fs.exists(config_path) then
|
|
print("repo_list.txt not found.")
|
|
os.exit()
|
|
end
|
|
|
|
local backup_path = parent_path .. "/" .. backup_name
|
|
print("Backup Path: " .. backup_path)
|
|
|
|
if not fs.exists(backup_path) then
|
|
fs.mkdir(backup_path) -- 创建备份目录
|
|
end
|
|
|
|
-- 读取 repo_list.txt 文件
|
|
local content = {}
|
|
for line in io.lines(config_path) do
|
|
table.insert(content, line)
|
|
end
|
|
|
|
for _, repo in ipairs(content) do
|
|
local repo_name = repo:match("^(.*)$") -- 去掉换行符
|
|
|
|
if #repo_name == 0 then
|
|
print("Skipping empty repo name")
|
|
goto continue
|
|
end
|
|
|
|
local purpose_dir = backup_path .. "/" .. repo_name
|
|
local cmd
|
|
|
|
if not fs.exists(purpose_dir) then
|
|
fs.mkdir(purpose_dir) -- 创建对应的目录
|
|
cmd = "git clone --recursive " .. url .. repo_name .. ".git \"" .. purpose_dir .. "\""
|
|
else
|
|
cmd = "cd /d \"" .. purpose_dir .. "\" && git pull && git submodule update"
|
|
end
|
|
print(cmd)
|
|
os.execute(cmd) -- 执行命令
|
|
::continue:: -- 跳到下一次循环
|
|
end
|