From 27afb3eade4994b4f56fc05877f4968266937922 Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Sun, 19 May 2024 13:22:34 +0200 Subject: [PATCH] refactor: better install script --- install.lua | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/install.lua b/install.lua index a9768ef..e4fb731 100644 --- a/install.lua +++ b/install.lua @@ -1,9 +1,13 @@ local LIST_FILES = { 'miner.lua', 'simple-harvester.lua', + 'inferium-upgrader.lua' +}; + +local LIST_LIBS_FILES = { 'libs/turtle-utils.lua', 'libs/robot.lua' -}; +} local LIST_CONFIG_FILES = { 'startup.lua', @@ -13,21 +17,38 @@ local LIST_CONFIG_FILES = { local REPO_PREFIX = 'https://git.trapcloud.fr/guillaumearm/minecraft-cc-tools/raw/branch/master/' -local previousDir = shell.dir() -fs.makeDir('/libs') -fs.makeDir('/config') - -for _, filePath in pairs(LIST_FILES) do - fs.delete(filePath) - shell.execute('wget', REPO_PREFIX .. filePath, filePath) +local prepareDirs = function() + fs.makeDir('/libs') + fs.makeDir('/config') end --- do not override existing config files -for _, filePath in pairs(LIST_CONFIG_FILES) do - if not fs.exists(filePath) then +local installFiles = function(list) + for _, filePath in pairs(list) do + fs.delete(filePath) shell.execute('wget', REPO_PREFIX .. filePath, filePath) end end -shell.setDir(previousDir) +local installConfig = function() + -- do not override existing config files + for _, filePath in pairs(LIST_CONFIG_FILES) do + if not fs.exists(filePath) then + shell.execute('wget', REPO_PREFIX .. filePath, filePath) + end + end +end + +local function mainSetup = function() + local previousDir = shell.dir() + + prepareDirs() + installFiles(LIST_LIBS_FILES) + installFiles(LIST_FILES) + installConfig() + + shell.setDir(previousDir) +end + +mainSetup() +