#!/usr/bin/ruby $oxodir="/data/oxocard" def ex(cmd) puts cmd res = system(cmd) if (res==nil) puts "Could not even run the command #{cmd}. Aborting." exit(-1) end return res end def trycmd(cmd, n=2) n.times { return true if ex(cmd) puts "command returned an error, trying again in 2 sec.." sleep(2) } puts "Executing #{cmd} returned an error. Aborting." exit(-1) end def dl(url, force=false) file = File.basename(url) ext = file.rindex(".") file = file[0...ext]+"-"+Time.now.strftime("%F")+file[ext..-1] if File.exists?(file) and !force puts "File #{file} already exists. Not downloading again. (use -f to force)" else unless ex("curl -L #{url} > #{$oxodir}/#{file}") ex("rm -f #{$oxodir}/#{file}") puts "Could not download from #{url}, aborting." exit(-1) end end end force = (ARGV[0]=="-f") puts "Downloading TigerJython Images to #{$oxodir}" dl("https://www.tigerjython4kids.ch/download/MicroPython.bin", force) dl("https://www.tigerjython4kids.ch/download/oxocardmodules.zip", force) dl("https://www.tigerjython4kids.ch/download/blockly_flash.zip", force)