SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Reactor- und Turbine control by Thor_s_Crafter -- | |
| 2 | -- Init Program Downloader (GitHub) -- | |
| 3 | ||
| 4 | ||
| 5 | --===== Local variables ===== | |
| 6 | ||
| 7 | --Release or beta version? | |
| 8 | local selectInstaller = "" | |
| 9 | ||
| 10 | --Branch & Relative paths to the url and path | |
| 11 | local installLang = "" | |
| 12 | local branch = "" | |
| 13 | local relUrl = "" | |
| 14 | local relPath = "/reactor-turbine-program/" | |
| 15 | ||
| 16 | ||
| 17 | --Select the installer language | |
| 18 | function selectLanguage() | |
| 19 | clearTerm() | |
| 20 | print("Sprache/Language")
| |
| 21 | print("1) Deutsch/German (de)")
| |
| 22 | print("2) English (en)")
| |
| 23 | term.write("Eingabe/Enter (1-2): ")
| |
| 24 | local input = read() | |
| 25 | if input == "1" then installLang = "de" | |
| 26 | elseif input == "2" then installLang = "en" | |
| 27 | else | |
| 28 | print("Ungueltige Eingabe!")
| |
| 29 | print("Invalid input!")
| |
| 30 | sleep(2) | |
| 31 | selectLanguage() | |
| 32 | end | |
| 33 | end | |
| 34 | ||
| 35 | --Select the github branch to download | |
| 36 | function selectBranch() | |
| 37 | clearTerm() | |
| 38 | if installLang == "de" then | |
| 39 | print("Welche Version soll geladen werden?")
| |
| 40 | print("Verfuegbar:")
| |
| 41 | print("1) master (Releases)")
| |
| 42 | print("2) beta (Betaversionen)")
| |
| 43 | term.write("Eingabe (1-2): ")
| |
| 44 | elseif installLang == "en" then | |
| 45 | print("Which version should be downloaded?")
| |
| 46 | print("Available:")
| |
| 47 | print("1) master (Realeases)")
| |
| 48 | print("2) beta (Betaversions)")
| |
| 49 | term.write("Input (1-2): ")
| |
| 50 | end | |
| 51 | local input = read() | |
| 52 | if input == "1" then | |
| 53 | branch = "master" | |
| 54 | - | relUrl = "https://raw.githubusercontent.com/ThorsCrafter/Reactor-and-Turbine-control-program/"..branch.."/turbineControl_v2/src/" |
| 54 | + | relUrl = "https://raw.githubusercontent.com/SoulofSorrow/Reactor-and-Turbine-control-program/"..branch.."/turbineControl_v2/src/" |
| 55 | releaseVersion() | |
| 56 | elseif input == "2" then | |
| 57 | branch = "beta" | |
| 58 | - | relUrl = "https://raw.githubusercontent.com/ThorsCrafter/Reactor-and-Turbine-control-program/"..branch.."/turbineControl_v2/src/" |
| 58 | + | relUrl = "https://raw.githubusercontent.com/SoulofSorrow/Reactor-and-Turbine-control-program/"..branch.."/turbineControl_v2/src/" |
| 59 | betaVersion() | |
| 60 | else | |
| 61 | if installLang == "de" then print("Ungueltige Eingabe!")
| |
| 62 | elseif installLang == "en" then print("Invalid input!") end
| |
| 63 | sleep(2) | |
| 64 | selectBranch() | |
| 65 | end | |
| 66 | end | |
| 67 | ||
| 68 | --Removes old installations | |
| 69 | function removeAll() | |
| 70 | print("Removing old files...")
| |
| 71 | if fs.exists(relPath) then | |
| 72 | shell.run("rm "..relPath)
| |
| 73 | end | |
| 74 | if fs.exists("startup") then
| |
| 75 | shell.run("rm startup")
| |
| 76 | end | |
| 77 | end | |
| 78 | ||
| 79 | --Writes the files to the computer | |
| 80 | function writeFile(url,path) | |
| 81 | local file = fs.open("/reactor-turbine-program/"..path,"w")
| |
| 82 | file.write(url) | |
| 83 | file.close() | |
| 84 | end | |
| 85 | ||
| 86 | --Resolve the right url | |
| 87 | function getURL(path) | |
| 88 | local gotUrl = http.get(relUrl..path) | |
| 89 | if gotUrl == nil then | |
| 90 | clearTerm() | |
| 91 | error("File not found! Please check!\nFailed at "..relUrl..path)
| |
| 92 | else | |
| 93 | return gotUrl.readAll() | |
| 94 | end | |
| 95 | end | |
| 96 | ||
| 97 | --Gets all the files from github | |
| 98 | function getFiles() | |
| 99 | clearTerm() | |
| 100 | print("Getting new files...")
| |
| 101 | --Changelog | |
| 102 | print("Changelog files...")
| |
| 103 | writeFile(getURL("changelog/changelogDE.txt"),"changelog/changelogDE.txt")
| |
| 104 | writeFile(getURL("changelog/changelogEn.txt"),"changelog/changelogDE.txt")
| |
| 105 | --Config | |
| 106 | print("Config files...")
| |
| 107 | writeFile(getURL("config/input.lua"),"config/input.lua")
| |
| 108 | writeFile(getURL("config/options.txt"),"config/options.txt")
| |
| 109 | writeFile(getURL("config/touchpoint.lua"),"config/touchpoint.lua")
| |
| 110 | --Install | |
| 111 | print("Install files...")
| |
| 112 | writeFile(getURL("install/installer.lua"),"install/installer.lua")
| |
| 113 | --Program | |
| 114 | print("Program files...")
| |
| 115 | writeFile(getURL("program/editOptions.lua"),"program/editOptions.lua")
| |
| 116 | writeFile(getURL("program/reactorControl.lua"),"program/reactorControl.lua")
| |
| 117 | writeFile(getURL("program/turbineControl.lua"),"program/turbineControl.lua")
| |
| 118 | --Start | |
| 119 | print("Start files...")
| |
| 120 | writeFile(getURL("start/menu.lua"),"start/menu.lua")
| |
| 121 | writeFile(getURL("start/start.lua"),"start/start.lua")
| |
| 122 | --Startup | |
| 123 | print("Startup file...")
| |
| 124 | local file = fs.open("startup","w")
| |
| 125 | file.writeLine("shell.run(\"/reactor-turbine-program/start/start.lua\")")
| |
| 126 | file.close() | |
| 127 | end | |
| 128 | ||
| 129 | --Clears the terminal | |
| 130 | function clearTerm() | |
| 131 | shell.run("clear")
| |
| 132 | term.setCursorPos(1,1) | |
| 133 | end | |
| 134 | ||
| 135 | function releaseVersion() | |
| 136 | removeAll() | |
| 137 | --Downloads the installer | |
| 138 | if installLang == "de" then | |
| 139 | writeFile(getURL("install/installer.lua"),"install/installer.lua")
| |
| 140 | elseif installLang == "en" then | |
| 141 | writeFile(getURL("install/installerEn.lua"),"install/installer.lua")
| |
| 142 | end | |
| 143 | shell.run("/reactor-turbine-program/install/installer.lua")
| |
| 144 | end | |
| 145 | ||
| 146 | function betaVersion() | |
| 147 | removeAll() | |
| 148 | getFiles() | |
| 149 | print("Done!")
| |
| 150 | sleep(2) | |
| 151 | end | |
| 152 | ||
| 153 | --Run | |
| 154 | selectLanguage() | |
| 155 | ||
| 156 | selectBranch() | |
| 157 | os.reboot() |