-d now more or less complete
This commit is contained in:
38
git-tool.lua
38
git-tool.lua
@@ -86,7 +86,7 @@ local function makeDirIfNotExists(target)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- todo: pcall and catch errors
|
--- todo: pcall and catch errors
|
||||||
local function downloadRepo(repository, remote, autoOverride)
|
local function downloadRepo(repository, remote, autoOverride, targetDownloadPath)
|
||||||
|
|
||||||
local function validateRepositoryIdentifier(repository)
|
local function validateRepositoryIdentifier(repository)
|
||||||
if not repository.RepoIdentifier:match("^[%w-.]*/[%w-.]*$") then
|
if not repository.RepoIdentifier:match("^[%w-.]*/[%w-.]*$") then
|
||||||
@@ -98,7 +98,6 @@ local function downloadRepo(repository, remote, autoOverride)
|
|||||||
validateRepositoryIdentifier(repository)
|
validateRepositoryIdentifier(repository)
|
||||||
|
|
||||||
--- FIXME: If download only mode is enabled, set this to /home. still todo
|
--- FIXME: If download only mode is enabled, set this to /home. still todo
|
||||||
local targetDownloadPath = DefaultTemporaryDownloadPath..repository.RepoIdentifier
|
|
||||||
repository.CurrentLocalPath = targetDownloadPath.."/"
|
repository.CurrentLocalPath = targetDownloadPath.."/"
|
||||||
local success, res = pcall(makeDirIfNotExists, targetDownloadPath)
|
local success, res = pcall(makeDirIfNotExists, targetDownloadPath)
|
||||||
if not success then error("the download failed because of filesystem errors.") end
|
if not success then error("the download failed because of filesystem errors.") end
|
||||||
@@ -205,7 +204,6 @@ local function downloadRepo(repository, remote, autoOverride)
|
|||||||
|
|
||||||
success, res = pcall(downloadFiles, files, targetDownloadPath, replaceMode)
|
success, res = pcall(downloadFiles, files, targetDownloadPath, replaceMode)
|
||||||
if success then print("All files downloaded successfully.") return res else error(res) end
|
if success then print("All files downloaded successfully.") return res else error(res) end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function installFiles(downloadedFiles, downloadTargetDir, installTargetDir)
|
local function installFiles(downloadedFiles, downloadTargetDir, installTargetDir)
|
||||||
@@ -215,12 +213,13 @@ local function installFiles(downloadedFiles, downloadTargetDir, installTargetDir
|
|||||||
local replace = true
|
local replace = true
|
||||||
makeDirIfNotExists(installTargetDir)
|
makeDirIfNotExists(installTargetDir)
|
||||||
for idx, file in pairs(downloadedFiles) do
|
for idx, file in pairs(downloadedFiles) do
|
||||||
print(idx..": Installing File "..downloadTargetDir..file:sub(2,-1).." to target directory "..installTargetDir..file)
|
local absoluteDownloadFilePath = downloadTargetDir.."/"..file:sub(2,-1)
|
||||||
|
print(idx..": Installing File "..absoluteDownloadFilePath.." to target directory "..installTargetDir..file)
|
||||||
local fileExists = filesystem.exists(installTargetDir..file)
|
local fileExists = filesystem.exists(installTargetDir..file)
|
||||||
if fileExists and replace then filesystem.remove(installTargetDir..file) end
|
if fileExists and replace then filesystem.remove(installTargetDir..file) end
|
||||||
if replace or (replace == nil) then
|
if replace or (replace == nil) then
|
||||||
--- TODO @Freddy: Coole Animation hinzufügen
|
--- TODO @Freddy: Coole Animation hinzufügen
|
||||||
os.execute("cp "..downloadTargetDir..file:sub(2,-1).." "..installTargetDir..file)
|
os.execute("cp "..absoluteDownloadFilePath.." "..installTargetDir..file)
|
||||||
table.insert(installedFiles, installTargetDir..file)
|
table.insert(installedFiles, installTargetDir..file)
|
||||||
else error("file not removed, but installation was cancelled - This might result in a broken install.") end
|
else error("file not removed, but installation was cancelled - This might result in a broken install.") end
|
||||||
end
|
end
|
||||||
@@ -230,7 +229,9 @@ end
|
|||||||
local function installShortcut(currentRepoPath, shortcutName, targetDir)
|
local function installShortcut(currentRepoPath, shortcutName, targetDir)
|
||||||
print("installing shortcut...")
|
print("installing shortcut...")
|
||||||
makeDirIfNotExists(targetDir)
|
makeDirIfNotExists(targetDir)
|
||||||
os.execute("mv "..currentRepoPath.."shortcut.lua "..targetDir..shortcutName..".lua")
|
local shortcutInstallTarget = currentRepoPath.."shortcut.lua "..targetDir..shortcutName..".lua"
|
||||||
|
os.execute("mv "..shortcutInstallTarget)
|
||||||
|
return {shortcutInstallTarget}
|
||||||
end
|
end
|
||||||
|
|
||||||
--- todo: automatic read of dependency list (txt file containing lines with <link> <dst> or somethink like it)
|
--- todo: automatic read of dependency list (txt file containing lines with <link> <dst> or somethink like it)
|
||||||
@@ -241,6 +242,8 @@ local function legacyInstallDependencies()
|
|||||||
os.execute("wget -f https://github.com/kevinkk525/OC-GUI-API/raw/master/GUI.lua /lib/GUI.lua")
|
os.execute("wget -f https://github.com/kevinkk525/OC-GUI-API/raw/master/GUI.lua /lib/GUI.lua")
|
||||||
os.execute("wget -f https://github.com/kevinkk525/OC-GUI-API/raw/master/term_mod.lua /lib/term_mod.lua")
|
os.execute("wget -f https://github.com/kevinkk525/OC-GUI-API/raw/master/term_mod.lua /lib/term_mod.lua")
|
||||||
os.execute("wget -f https://github.com/kevinkk525/OC-GUI-API/raw/master/tech_demo.lua /home/GUI_tech_demo.lua")
|
os.execute("wget -f https://github.com/kevinkk525/OC-GUI-API/raw/master/tech_demo.lua /home/GUI_tech_demo.lua")
|
||||||
|
local installedDependencies = {"/lib/shapes_default.lua", "/lib/GUI.lua", "/lib/term_mod.lua", "/home/GUI_tech_demo.lua"}
|
||||||
|
return installedDependencies
|
||||||
end
|
end
|
||||||
|
|
||||||
local function removeDownloads(downloadTargetDir, downloadedFiles)
|
local function removeDownloads(downloadTargetDir, downloadedFiles)
|
||||||
@@ -253,7 +256,11 @@ local function removeDownloads(downloadTargetDir, downloadedFiles)
|
|||||||
print("cleaned temporary files.")
|
print("cleaned temporary files.")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function createManifest(installedFiles, installedShortcuts, manifestTarget, repoName)
|
local function removeFilesViaManifest(manifestTarget)
|
||||||
|
--- todo
|
||||||
|
end
|
||||||
|
|
||||||
|
local function createManifest(installedDependencies, installedFiles, installedShortcuts, manifestTarget, repoName)
|
||||||
makeDirIfNotExists(manifestTarget)
|
makeDirIfNotExists(manifestTarget)
|
||||||
local manifest = ""
|
local manifest = ""
|
||||||
for idx, file in pairs(installedFiles) do
|
for idx, file in pairs(installedFiles) do
|
||||||
@@ -262,8 +269,11 @@ local function createManifest(installedFiles, installedShortcuts, manifestTarget
|
|||||||
for idy, shortcut in pairs(installedShortcuts) do
|
for idy, shortcut in pairs(installedShortcuts) do
|
||||||
manifest = manifest..shortcut.."\n"
|
manifest = manifest..shortcut.."\n"
|
||||||
end
|
end
|
||||||
print("writing manifest to "..manifestTarget.."/"..repoName)
|
for idz, dependency in pairs(installedDependencies) do
|
||||||
local file=io.open(manifestTarget.."/"..repoName,"w")
|
manifest = manifest..dependency.."\n"
|
||||||
|
end
|
||||||
|
print("writing manifest to "..manifestTarget..repoName)
|
||||||
|
local file=io.open(manifestTarget..repoName,"w")
|
||||||
if file then -- might be nil under wierd circumstances
|
if file then -- might be nil under wierd circumstances
|
||||||
file:write(manifest)
|
file:write(manifest)
|
||||||
file:close()
|
file:close()
|
||||||
@@ -277,16 +287,18 @@ local function runFullInstallTask(repository, shortcutName)
|
|||||||
--- then, install the actual program
|
--- then, install the actual program
|
||||||
local installTargetDir = "/usr/"..repository.Name
|
local installTargetDir = "/usr/"..repository.Name
|
||||||
local shortcutTargetDir = "/usr/bin/"
|
local shortcutTargetDir = "/usr/bin/"
|
||||||
local downloadTargetDir = DefaultTemporaryDownloadPath
|
local downloadTargetDir = DefaultTemporaryDownloadPath..repository.RepoIdentifier
|
||||||
local manifestTarget = "/etc/manifest/"
|
local manifestTarget = "/etc/manifest/"
|
||||||
|
|
||||||
legacyInstallDependencies() --only for testing while new version not implemented yet
|
local installedDependencies = legacyInstallDependencies() --only for testing while new version not implemented yet
|
||||||
print("downloading "..repository.RepoIdentifier)
|
print("downloading "..repository.RepoIdentifier)
|
||||||
local downloadedFiles = downloadRepo(repository, repository.Remote, false) --enable auto-overwrite in other situations still todo
|
local downloadedFiles = downloadRepo(repository, repository.Remote, false, downloadTargetDir) --enable auto-overwrite in other situations still todo
|
||||||
local installedFiles = installFiles(downloadedFiles, downloadTargetDir, installTargetDir)
|
local installedFiles = installFiles(downloadedFiles, downloadTargetDir, installTargetDir)
|
||||||
local installedShortcuts = installShortcut(repository.CurrentLocalPath, shortcutName, shortcutTargetDir)
|
local installedShortcuts = installShortcut(repository.CurrentLocalPath, shortcutName, shortcutTargetDir)
|
||||||
|
|
||||||
|
--- remove temporary files and create manifest for later uninstall
|
||||||
removeDownloads(downloadTargetDir, downloadedFiles)
|
removeDownloads(downloadTargetDir, downloadedFiles)
|
||||||
createManifest(installedFiles, installedShortcuts, manifestTarget, repository.Name)
|
createManifest(installedDependencies, installedFiles, installedShortcuts, manifestTarget, repository.Name)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function printHelpText()
|
local function printHelpText()
|
||||||
|
|||||||
Reference in New Issue
Block a user