modify helper functions...
1. modified fileexists now works on both files and directories 2. added test for slash to return the last part of a string before / 3. added run function to make running commands easier 4. modified clonegit to stop using all the crappy shell script stuff and make it use new helper functions 5. modified check for updates to stop using the crappy shell stuff and actually work
This commit is contained in:
77
eatit.lua
77
eatit.lua
@ -27,16 +27,31 @@ local function tablelength(T)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function fileexists(name)
|
local function fileexists(name)
|
||||||
local f = io.open(name, 'r')
|
local ok, err, code = os.rename(name, name)
|
||||||
if f ~= nil then io.close(f) return true else return false end
|
if not ok then
|
||||||
|
if code == 13 then
|
||||||
|
-- Permission denied, but it exists
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ok, err
|
||||||
end
|
end
|
||||||
|
|
||||||
local function logwrite(string)
|
local function testforslash(str)
|
||||||
if opts.logging.log then
|
if string.match(str, '/') then
|
||||||
io.write(os.date(opts.logging.logdate) .. ' ' .. string .. '\n')
|
return string.match(str, '/([^/]+)$')
|
||||||
|
else
|
||||||
|
return str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function run(cmd)
|
||||||
|
local x = io.popen(cmd)
|
||||||
|
local y = x:read("*a")
|
||||||
|
x:close()
|
||||||
|
return y
|
||||||
|
end
|
||||||
|
|
||||||
local function openlog()
|
local function openlog()
|
||||||
if opts.logging.log then -- log if asked to
|
if opts.logging.log then -- log if asked to
|
||||||
-- get our logfile's full path
|
-- get our logfile's full path
|
||||||
@ -47,6 +62,12 @@ local function openlog()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function logwrite(string)
|
||||||
|
if opts.logging.log then
|
||||||
|
io.write(os.date(opts.logging.logdate) .. ' ' .. string .. '\n')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function closelog()
|
local function closelog()
|
||||||
if opts.logging.log then
|
if opts.logging.log then
|
||||||
io.close(f)
|
io.close(f)
|
||||||
@ -54,45 +75,21 @@ local function closelog()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- get the requested git repos
|
-- get the requested git repos
|
||||||
local function clonegit(i)
|
local function clonegit(plugdir, i)
|
||||||
logwrite('downloading ' .. plugins[i][1])
|
logwrite('downloading ' .. plugins[i][1])
|
||||||
|
|
||||||
-- construct the git cmd
|
-- clone the repo
|
||||||
local cmd = 'git -C ' .. opts.dl.dir .. ' clone ' .. plugins[i][1]
|
-- BUG: logwriting the git command doens't actually log the output
|
||||||
|
run('git -C ' .. opts.dl.dir .. ' clone ' .. plugins[i][1])
|
||||||
-- run the command and get the result for logging
|
run('git -C ' .. plugdir .. ' checkout -q ' .. plugins[i]['branch'])
|
||||||
local run = io.popen(cmd)
|
|
||||||
-- BUG: logwriting the git command doens't actually log the output
|
|
||||||
-- (commented out for now)
|
|
||||||
-- logwrite(run:read('*a'))
|
|
||||||
run:close()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check for updates
|
-- check for updates
|
||||||
local function checkupdates(i)
|
local function checkupdates(plugdir)
|
||||||
local plugdir = opts.dl.dir .. '/' ..
|
local localhash = run('git -C ' .. plugdir .. ' log -1 --format=format:"%H"')
|
||||||
string.match(plugins[i][1], '/([^/]+)$'):gsub('.git', '')
|
local remotehash = run('git -C ' .. plugdir .. ' rev-parse $(git -C ' ..
|
||||||
|
plugdir .. ' branch -r) | tail -1')
|
||||||
local localhashcmd = 'git -C ' .. plugdir .. ' log -1 --format=format:"%H"'
|
if localhash ~= remotehash then return true else return false end
|
||||||
|
|
||||||
local remotehashcmd = 'git -C ' .. plugdir ..
|
|
||||||
' log -n 1 $(git -C ' .. plugdir ..
|
|
||||||
' branch -r | head -1 | cut -d " " -f 3)' ..
|
|
||||||
' | head -1 | cut -d " " -f 2'
|
|
||||||
|
|
||||||
local a = io.popen(localhashcmd)
|
|
||||||
local localhash = string.gsub(a:read("*a"), '[\n\r]', '')
|
|
||||||
a:close()
|
|
||||||
|
|
||||||
a = io.popen(remotehashcmd)
|
|
||||||
local remotehash = string.gsub(a:read("*a"), '[\n\r]', '')
|
|
||||||
a:close()
|
|
||||||
|
|
||||||
if localhash ~= remotehash then
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- start install
|
-- start install
|
||||||
|
Reference in New Issue
Block a user