make the plugin definition more verbose, and less strict.
stop script from cloning if there are no new commits. make the code a tiny bit cleaner. bit of a kitchen sink :(
This commit is contained in:
@ -16,8 +16,7 @@ curl -L https://git.squi.bid/eat-it/plain/eatit-cfg.lua -o ~/.config/mpv/eatit-c
|
|||||||
```
|
```
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
- move opts to a separate file
|
- define multple files to be saved to different directories
|
||||||
- use the present git repos instead of relying on downloading every time
|
|
||||||
- git not outputting to the logfile
|
- git not outputting to the logfile
|
||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
|
@ -3,7 +3,10 @@
|
|||||||
|
|
||||||
plugins = { -- the plugins you want to load
|
plugins = { -- the plugins you want to load
|
||||||
-- link to repo file dest dir
|
-- link to repo file dest dir
|
||||||
{ 'https://git.squi.bid/eat-it', 'eatit.lua', 'scripts' },
|
{ 'https://git.squi.bid/eat-it',
|
||||||
|
file = 'eatit.lua',
|
||||||
|
dir = 'scripts',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
-- options for eat it
|
-- options for eat it
|
||||||
|
74
eatit.lua
74
eatit.lua
@ -8,21 +8,22 @@ local function tablelength(T)
|
|||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function fileexists(name)
|
||||||
|
local f = io.open(name, 'r')
|
||||||
|
if f ~= nil then io.close(f) return true else return false end
|
||||||
|
end
|
||||||
|
|
||||||
local function logwrite(string)
|
local function logwrite(string)
|
||||||
if opts.logging.log then
|
if opts.logging.log then
|
||||||
io.write(os.date(opts.logging.logdate) .. ' ' .. string .. '\n')
|
io.write(os.date(opts.logging.logdate) .. ' ' .. string .. '\n')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getgit()
|
local function clonegit(pluginlink)
|
||||||
os.execute('mkdir -p ' .. opts.dl.dir)
|
logwrite('downloading ' .. pluginlink)
|
||||||
|
|
||||||
logwrite('Starting Download...')
|
|
||||||
for i in pairs(plugins) do
|
|
||||||
logwrite('downloading ' .. plugins[i][1])
|
|
||||||
|
|
||||||
-- construct the git cmd
|
-- construct the git cmd
|
||||||
local cmd = 'git -C ' .. opts.dl.dir .. ' clone ' .. plugins[i][1]
|
local cmd = 'git -C ' .. opts.dl.dir .. ' clone ' .. pluginlink
|
||||||
|
|
||||||
-- run the command and get the result for logging
|
-- run the command and get the result for logging
|
||||||
local run = io.popen(cmd)
|
local run = io.popen(cmd)
|
||||||
@ -30,16 +31,66 @@ local function getgit()
|
|||||||
-- (commented out for now)
|
-- (commented out for now)
|
||||||
-- logwrite(run:read('*a'))
|
-- logwrite(run:read('*a'))
|
||||||
run:close()
|
run:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function checkupdates(i, pluginfile, pluginlink)
|
||||||
|
local plugdir = opts.dl.dir .. '/' ..
|
||||||
|
string.match(pluginlink, '/([^/]+)$')
|
||||||
|
|
||||||
|
local localhashcmd = 'cd ' .. plugdir ..
|
||||||
|
'; git log -1 --format=format:"%H"'
|
||||||
|
|
||||||
|
local remotehashcmd = 'cd ' .. plugdir ..
|
||||||
|
'; git log -n 1 $(git 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
|
||||||
|
logwrite(plugins[i]['file'] .. ' is updating.')
|
||||||
|
clonegit(pluginlink)
|
||||||
|
else
|
||||||
|
logwrite(plugins[i]['file'] .. ' is up to date!')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function startinstall()
|
||||||
|
logwrite('Starting Download...')
|
||||||
|
for i = 1, tablelength(plugins) do
|
||||||
|
-- check if the user has defined a file for the current plugin
|
||||||
|
if not plugins[i]['file'] then
|
||||||
|
logwrite('WARNING! Git repo "' .. plugins[i][1] ..
|
||||||
|
'" doesn\'t have a specified file. Skipping download')
|
||||||
|
-- FIXME: this results in the last plugin being downloaded & copied twice
|
||||||
|
i = i + 1 -- if not we go to the next plugin
|
||||||
|
end
|
||||||
|
|
||||||
|
-- if no destdir defined we set it to the root of the mpv config dir
|
||||||
|
if not plugins[i]['dir'] then
|
||||||
|
plugins[i]['dir'] = '~~/'
|
||||||
|
end
|
||||||
|
|
||||||
-- get the file's dir
|
-- get the file's dir
|
||||||
local pluginfile = opts.dl.dir .. '/' ..
|
local pluginfile = opts.dl.dir .. '/' ..
|
||||||
string.match(plugins[i][1], '/([^/]+)$') ..
|
string.match(plugins[i][1], '/([^/]+)$') ..
|
||||||
'/' .. plugins[i][2]
|
'/' .. plugins[i]['file']
|
||||||
|
|
||||||
-- get the dest dir
|
-- get the dest dir
|
||||||
local destfile = mp.command_native({'expand-path', '~~/'}) ..
|
local destfile = mp.command_native({'expand-path', '~~/'}) ..
|
||||||
'/' .. plugins[i][3] ..
|
'/' .. plugins[i]['dir'] ..
|
||||||
'/' .. plugins[i][2]
|
'/' .. plugins[i]['file']
|
||||||
|
|
||||||
|
if fileexists(pluginfile) then
|
||||||
|
checkupdates(i, pluginfile, plugins[i][1])
|
||||||
|
else
|
||||||
|
clonegit(plugins[i][1])
|
||||||
|
end
|
||||||
|
|
||||||
-- copy the file contents over to the desired location
|
-- copy the file contents over to the desired location
|
||||||
local infile = io.open(pluginfile, 'r')
|
local infile = io.open(pluginfile, 'r')
|
||||||
@ -61,7 +112,8 @@ local function init()
|
|||||||
end
|
end
|
||||||
|
|
||||||
logwrite('# of plugins defined in table: ' .. tablelength(plugins))
|
logwrite('# of plugins defined in table: ' .. tablelength(plugins))
|
||||||
getgit()
|
os.execute('mkdir -p ' .. opts.dl.dir) -- make download dir
|
||||||
|
startinstall()
|
||||||
|
|
||||||
-- closing/removing everything
|
-- closing/removing everything
|
||||||
if opts.dl.powerwash == true then
|
if opts.dl.powerwash == true then
|
||||||
|
Reference in New Issue
Block a user