diff -ur tar2rubyscript-none.tar.gz/tar2rubyscript/README tar2rubyscript-0.1.tar.gz/tar2rubyscript/README --- tar2rubyscript-none.tar.gz/tar2rubyscript/README 2004-06-23 00:35:54.000000000 +0200 +++ tar2rubyscript-0.1.tar.gz/tar2rubyscript/README 2003-08-18 18:54:13.000000000 +0200 @@ -0,0 +1,5 @@ +Usage: ruby tar2rubyscript.rb tarrubyscript.rb application.tar application.rb [licence.txt] + +Just ignore the existance of init.rb ... + +For more information, see http://www.erikveen.dds.nl/tar2rubyscript/ . diff -ur tar2rubyscript-none.tar.gz/tar2rubyscript/init.rb tar2rubyscript-0.1.tar.gz/tar2rubyscript/init.rb --- tar2rubyscript-none.tar.gz/tar2rubyscript/init.rb 2004-06-23 00:35:54.000000000 +0200 +++ tar2rubyscript-0.1.tar.gz/tar2rubyscript/init.rb 2003-08-18 18:59:33.000000000 +0200 @@ -0,0 +1,17 @@ +scriptfile = "tarrubyscript.rb" +tarfile = oldlocation(ARGV.shift) +outfile = oldlocation(ARGV.shift) +licensefile = oldlocation(ARGV.shift) + +script = File.new(scriptfile).read +archive = [File.new(tarfile, "rb").read].pack("m").split("\n").collect{|s| "# " + s}.join("\n") +license = File.new(licensefile).read if not licensefile.nil? + +script = "# License, not of this script, but of the application it contains:\n\n" +license + "\n" + script if not licensefile.nil? + +script.gsub!(/%LINES%/, (script.split("\n", -1).length-1).to_s) + +File.open(outfile, "wb") do |f| + f.write script + f.write archive +end diff -ur tar2rubyscript-none.tar.gz/tar2rubyscript/tar2rubyscript.rb tar2rubyscript-0.1.tar.gz/tar2rubyscript/tar2rubyscript.rb --- tar2rubyscript-none.tar.gz/tar2rubyscript/tar2rubyscript.rb 2004-06-23 00:35:54.000000000 +0200 +++ tar2rubyscript-0.1.tar.gz/tar2rubyscript/tar2rubyscript.rb 2003-08-18 18:59:33.000000000 +0200 @@ -0,0 +1,17 @@ +scriptfile = ARGV.shift +tarfile = ARGV.shift +outfile = ARGV.shift +licensefile = ARGV.shift + +script = File.new(scriptfile).read +archive = [File.new(tarfile, "rb").read].pack("m").split("\n").collect{|s| "# " + s}.join("\n") +license = File.new(licensefile).read if not licensefile.nil? + +script = "# License, not of this script, but of the application it contains:\n\n" +license + "\n" + script if not licensefile.nil? + +script.gsub!(/%LINES%/, (script.split("\n", -1).length-1).to_s) + +File.open(outfile, "wb") do |f| + f.write script + f.write archive +end diff -ur tar2rubyscript-none.tar.gz/tar2rubyscript/tarrubyscript.rb tar2rubyscript-0.1.tar.gz/tar2rubyscript/tarrubyscript.rb --- tar2rubyscript-none.tar.gz/tar2rubyscript/tarrubyscript.rb 2004-06-23 00:35:54.000000000 +0200 +++ tar2rubyscript-0.1.tar.gz/tar2rubyscript/tarrubyscript.rb 2003-08-18 18:59:33.000000000 +0200 @@ -0,0 +1,253 @@ +# License of this script, not of the application it contains: + +# Copyright Erik Veenstra <tar2rubyscript@erikveen.dds.nl> + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License, +# version 2, as published by the Free Software Foundation. + +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. + +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA + +LINES = %LINES% + +BLOCKSIZE = 512 + +NAMELEN = 100 +MODELEN = 8 +UIDLEN = 8 +GIDLEN = 8 +CHKSUMLEN = 8 +SIZELEN = 12 +MAGICLEN = 8 +MODTIMELEN = 12 +UNAMELEN = 32 +GNAMELEN = 32 +DEVLEN = 8 +TMAGIC = ´ustar´ +GNU_TMAGIC = ´ustar ´ + +LF_OLDFILE = ´\0´ +LF_FILE = ´0´ +LF_LINK = ´1´ +LF_SYMLINK = ´2´ +LF_CHAR = ´3´ +LF_BLOCK = ´4´ +LF_DIR = ´5´ +LF_FIFO = ´6´ +LF_CONTIG = ´7´ + +class Reader + def initialize(filehandle) + @fp = filehandle + end + + def each + @fp.rewind + + while entry = next_entry + yield(entry) + end + end + + def next_entry + buf = @fp.read(BLOCKSIZE) + + if buf == "\000" * BLOCKSIZE + entry = nil + else + entry = Entry.new(buf, @fp) + end + + entry + end + + def extract + each do |entry| + entry.extract + end + end +end + +class Entry + attr_reader(:header, :data) + + def initialize(header, fp) + @header = Header.new(header) + + if @header.file? + #puts "File: #{@header.name}, #{@header.size} bytes" + + padding = (BLOCKSIZE - (@header.size % BLOCKSIZE)) % BLOCKSIZE + + @data = fp.read(@header.size) if @header.size > 0 + dummy = fp.read(padding) if padding > 0 + end + end + + def extract + if not @header.name.empty? + if @header.dir? + begin + Dir.mkdir(@header.name, @header.mode) + rescue SystemCallError => e + puts "Couldn´t create dir: " + e.message + end + else + begin + File.open(@header.name, "wb") do |fp| + fp.write(@data) + fp.chmod(@header.mode) + end + rescue => e + puts "Couldn´t create file: " + e.message + end + end + + #File.utime(@header.mtime, Time.new, @header.name) # ??? + end + end +end + +class Header + attr_reader(:name, :size, :mtime, :uname, :gname, :mode) + + def initialize(header) + types = [´str´, ´oct´, ´oct´, ´oct´, ´oct´, ´time´, ´oct´, ´str´, ´str´, ´str´, ´str´, ´str´, ´oct´, ´oct´] + fields = header.unpack(´A100 A8 A8 A8 A12 A12 A8 A1 A100 A8 A32 A32 A8 A8´) + converted = [] + + begin + while field = fields.shift + type = types.shift + + case type + when ´str´ then converted.push(field) + when ´oct´ then converted.push(field.oct) + when ´time´ then converted.push(Time::at(field.oct)) + end + end + + @name, @mode, @uid, @gid, @size, @mtime, @chksum, @linkflag, @linkname, @magic, @uname, @gname, @devmajor, @devminor = converted + + @name.gsub!(/\.\//, "") + + @raw = header + rescue ArgumentError => e + raise "Couldn´t determine a real value for a field (#{field})" + end + + raise "Magic header value ´#{@magic}´ is invalid." if @magic != TMAGIC and @magic != GNU_TMAGIC + + @linkflag = LF_FILE if @linkflag == LF_OLDFILE or @linkflag == LF_CONTIG + @linkflag = LF_DIR if @name[-1] == ´/´ and @linkflag == LF_FILE + @linkname = @linkname[1,-1] if @linkname[0] == ´/´ + @size = 0 if @size < 0 + @name = @linkname + ´/´ + @name if @linkname.size > 0 + end + + def file? + @linkflag == LF_FILE + end + + def dir? + @linkflag == LF_DIR + end +end + +class Jail + def initialize(code, ldir) + @ldir = ldir + @code = code + end + + def eval + instance_eval(@code) + end + + def oldlocation(file) + if not file.nil? + res = @ldir + "/" + file + res = file if file =~ /^\// + res = file if file =~ /^.:/ + end + + res + end +end + +def rm(entry) + if FileTest.file?(entry) + File.delete(entry) + end + + if FileTest.directory?(entry) + ldir = Dir.pwd + + Dir.chdir(entry) + Dir.new(".").each do |e| + rm(e) if not [".", ".."].include?(e) + end + Dir.chdir(ldir) + + Dir.rmdir(entry) + end +end + +if FileTest.exists?("c:/") + WD = "c:/tmp" +else + WD = "/tmp" +end + +MF = "#{WD}/ear.f.#{Process.pid}" +MP = "#{WD}/ear.d.#{Process.pid}" + +Dir.mkdir(WD) if not FileTest.exists?(WD) +Dir.mkdir(MP) + +LDIR = Dir.pwd + +begin + + archive = File.new($0, "rb").read.split(/\n/, LINES+1)[-1].split("\n").collect{|s| s[2..-1]}.join("\n").unpack("m").shift + + File.open(MF, "wb"){|f| f.write archive} + + Dir.chdir(MP) + + File.open(MF, "rb") do |fp| + Reader.new(fp).extract + end + + entries = Dir.entries(".") + entries.delete(".") + entries.delete("..") + + if entries.length == 1 + entry = entries.shift + if FileTest.directory?(entry) + Dir.chdir(entry) + end + end + + File.open("init.rb") do |f| + Jail.new(f.read, LDIR).eval + end + +ensure + + Dir.chdir(LDIR) + + rm(MF) + rm(MP) + +end +