Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- File: install - TurtleSHELL
- Purpose: Installs TurtleSHELL and it's components!
- Author: da404lewzer
- Project: http://turtlescripts.com/project/gjdgyz
- License: Creative Commons Attribution-ShareAlike 3.0 Unported License.
- http://creativecommons.org/licenses/by-sa/3.0/
- ]]
- local betaKey = "" --used for dev
- local running = true
- --Initial setup routines.. reverted to single monitor.. to emulate old windows installs
- local function drawModalMessage(monitor, monID, messageArr, bgText, bgColor, bgTextColor)
- local w,h = monitor.getSize()
- local xOffset,yOffset = 2,2
- local setupBG,setupBGText = colors.black, colors.white
- if monitor.isColor() then
- setupBG,setupBGText = bgColor, bgTextColor
- end
- monitor.setBackgroundColor(setupBG)
- monitor.setTextColor(setupBGText)
- monitor.clear()
- monitor.setCursorPos(xOffset,yOffset)
- monitor.write("TurtleSHELL Setup")
- monitor.setCursorPos(xOffset,yOffset+1)
- monitor.write(string.rep("-",w-((xOffset -1)*2)))
- local extraLineFeed = 2
- for i=1, #messageArr do
- monitor.setCursorPos(xOffset,yOffset+i+extraLineFeed)
- local wl = 0
- for word in string.gmatch(messageArr[i], "[^%s]+") do
- if wl+string.len(word) > w - ((xOffset -1)*2) then
- wl = 0
- extraLineFeed=extraLineFeed+1
- end
- monitor.setCursorPos(xOffset+wl,yOffset+i+extraLineFeed)
- wl=wl+string.len(word)+1
- monitor.write(word)
- end
- end
- monitor.setCursorPos(xOffset,h - yOffset+1)
- monitor.write(bgText)
- end
- local showingMessage = false
- function setupMessage(msgArr, bgText, bgColor, bgTextColor)
- local timer = os.startTimer(0)
- showingMessage = true
- drawModalMessage(term, 0, msgArr, bgText, bgColor, bgTextColor)
- sleep(0.5)
- while running and showingMessage do
- local event, p1, p2 = os.pullEvent()
- if event == "key" then
- lastKeypress = os.clock()
- showingMessage = false
- else
- drawModalMessage(term, 0, msgArr, bgText, bgColor, bgTextColor)
- end
- end
- showingMessage = false
- end
- function updateAllTheThings()
- fs.makeDir("turtleshell")
- --shell.run("market get gjdgz7 market y")
- shell.run("market get gjdh20 turtleshell/update "..betaKey.." y")
- if fs.exists("turtleshell/update") then
- shell.run("turtleshell/update")
- end
- end
- function getDefaultSettingsFiles()
- shell.run("market get gjdh05 turtleshell/os.settings "..betaKey) --DO NOT OVERRIDE IF FILE EXISTS
- shell.run("market get gjdh21 turtleshell/texty.settings "..betaKey) --DO NOT OVERRIDE IF FILE EXISTS
- end
- function setToStartup()
- if fs.exists("startup") and not fs.exists("startup.bak") then
- fs.move("startup", "startup.bak")
- end
- h = fs.open("startup", "w")
- h.write('shell.run("turtleshell/os")')
- h.close()
- end
- function cleanUp()
- term.clear()
- term.setCursorPos(1,1)
- end
- local logo = {
- " cccc ";
- " c0cc0c ";
- " cccccc 111111 1 11 111 1 111";
- " cc cccc cc 1 1 1 1 1 1 1 1 ";
- "cccc55d55d55cccc 1 1 1 11 1 1 11 ";
- " cd5dd5dd5dd5dc 1 1 1 1 1 1 1 1 ";
- " d5dd5dd5dd5d 1 111 1 1 1 111 111";
- " 5d55d55d55d5 ";
- " d5dd5dd5dd5d 3333 3 3 3333 3 3 ";
- " d5dd5dd5dd5d 3 3 3 3 3 3 ";
- " 5d55d55d55d5 333 3333 333 3 3 ";
- " d5dd5dd5dd5d 3 3 3 3 3 3 ";
- " cc5dd5dd5dd5cc 3333 3 3 3333 333 333";
- "cccc55d55d55cccc ";
- " cc cc cc ";
- }
- --[[Stolen Shamelessly from nPaintPro - http://pastebin.com/4QmTuJGU]]
- local function getColourOf(hex)
- local value = tonumber(hex, 16)
- if not value then return nil end
- value = math.pow(2,value)
- return value
- end
- local function drawPictureTable(mon, image, xinit, yinit, alpha)
- if not alpha then alpha = 1 end
- for y=1,#image do
- for x=1,#image[y] do
- mon.setCursorPos(xinit + x-1, yinit + y-1)
- local col = getColourOf(string.sub(image[y], x, x))
- if not col then col = alpha end
- if term.isColor() then
- mon.setBackgroundColour(col)
- else
- if string.sub(image[y], x, x) ~= " " then
- mon.setBackgroundColour(colors.black)
- else
- mon.setBackgroundColour(colors.white)
- end
- end
- mon.write(" ")
- end
- end
- end
- --[[End Theft]]
- function performOSSetup()
- cleanUp()
- setupMessage({
- "Welcome to TurtleSHELL BETA Setup",
- "",
- "Current Features:",
- " * Screen Savers [4D, Texty, and Matrix]",
- " * Customizable Menus / Footer Text",
- " * Multi-monitor support (screensavers too!)",
- " * Color Support",
- "",
- "To configure see 'os.settings' file after install."
- }, "[Next]", colors.blue, colors.white)
- setupMessage({
- "We will now download the remainder of the system including a couple screensavers and settings files.",
- "",
- "Settings files are isolated so you don't have to worry about losing settings when we make updates!",
- "",
- "This will also override your startup and make a backup if it exists :)",
- }, "[Install]", colors.blue, colors.white)
- cleanUp()
- updateAllTheThings()
- getDefaultSettingsFiles()
- setToStartup()
- fs.delete("install") --remove the installer
- drawModalMessage(term, 0, {"Everything seems normal..","","The system will now reboot :)"}, "Please wait...", colors.blue, colors.white)
- sleep(2)
- os.reboot()
- end
- --End of Initial setup routines
- term.setBackgroundColor(colors.white)
- term.clear()
- local w, h = term.getSize()
- drawPictureTable(term, logo, w/2 - #logo[1]/2, h/2 - #logo/2, colours.white)
- sleep(2)
- performOSSetup() --reboots if completes, can return errors or when cancelled
Add Comment
Please, Sign In to add comment