Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local repoOwner = "DaikiKaminari"
- local repoName = "NoteBlock"
- local workingTree = "master"
- local downloadDir = "downloads/" .. repoName
- local repoLink = "https://github.com/" .. repoOwner .."/" .. repoName .. "/blob/dev"
- local versionFileName = "version.json"
- if not fs.exists("github") then
- error("[github] does not exist.")
- end
- if not fs.exists("lib/objectJSON") or not fs.exists("lib/json") then
- error("objectJSON or json does not exist.")
- end
- os.loadAPI("lib/objectJSON")
- objectJSON.init()
- local function split(inputstr, sep)
- if sep == nil then sep = "%s" end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- local function rename(path)
- for _,f in pairs(fs.list(path)) do
- if fs.isDir(f) then
- rename(path .. "/" .. f)
- else
- local prog = split(f, ".")[1]
- local ext = split(f, ".")[2]
- if ext ~= nil then
- shell.run("mv " .. path .. "/" .. f .. " " .. path .. "/" .. prog)
- end
- end
- end
- end
- local function delete(where_to_delete, what_to_delete)
- for _,f in pairs(fs.list(what_to_delete)) do
- if fs.isDir(f) then
- delete(where_to_delete .. "/" .. f, what_to_delete .. "/" .. f)
- else
- shell.run("rm " .. where_to_delete .. "/" .. f)
- end
- end
- end
- local function copy(what_to_copy, where_to_copy)
- for _,f in pairs(fs.list(what_to_copy)) do
- if fs.isDir(f) then
- copy(what_to_copy .. "/" .. f, where_to_copy .. "/" .. f)
- else
- if fs.exists(where_to_copy .. "/" .. f) then
- print("[" ..where_to_copy .. "/" .. f .. "] already exist.")
- else
- shell.run("cp " .. what_to_copy .. "/" .. f .. " ".. where_to_copy .. "/" .. f)
- end
- end
- end
- end
- local version = fs.exists("version") and objectJSON.decodeFromFile("version").version or -1
- --local version = objectJSON.decodeFromFile("version").version
- print("Actual version : " .. tostring(version))
- local newVersion
- while true do
- newVersion = objectJSON.decodeHTTP("https://raw.githubusercontent.com/" .. repoOwner .. "/" .. repoName .. "/"
- .. workingTree .."/" .. versionFileName).version
- -- wait for a new version
- if not fs.exists("version") or newVersion ~= nil and version ~= newVersion then
- print("New version : " .. tostring(newVersion))
- -- delete old filed and then old download files
- if fs.exists(downloadDir) then
- delete(".", downloadDir)
- shell.run("rm " .. downloadDir)
- end
- sleep(1)
- shell.run("github " .. repoOwner .. " " .. repoName)
- -- remove extensions
- rename(downloadDir)
- copy(downloadDir, ".")
- return
- end
- sleep(1)
- end
Add Comment
Please, Sign In to add comment