From c3e59bf1f8f911dc04bd714a19eeeec4d452a356 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 28 Mar 2016 22:41:02 +1000 Subject: Move some scripts to the bin directory. --- bin/grindem.sh | 40 +++++++++++++++++++++ bin/killem.sh | 21 +++++++++++ bin/unpacker.lua | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100755 bin/grindem.sh create mode 100755 bin/killem.sh create mode 100755 bin/unpacker.lua (limited to 'bin') diff --git a/bin/grindem.sh b/bin/grindem.sh new file mode 100755 index 0000000..96edc5d --- /dev/null +++ b/bin/grindem.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Memory checker, and the default tool. +# --tool=memcheck --leak-check=full +# --track-origins=yes + +# Cache and branch prediction profiler, analyse speed issues. +# --tool=cachegrind +# --branch-sim=yes + +# Heap profiler, check memory sizes. +# --tool=massif + +# Heap profiler. +# --tool=dhat + +# "Call-graph generating cache profiler", complements cachegrind. +# --tool=callgrind + +# Thread error detector. +# --tool=helgrind + +# Thread error detector. +# --tool=drd + +# "experimental tool that can detect overruns of stack and global arrays" +# --tool=sgcheck + +tool="memcheck" +#tool="helgrind" +#tool="drd" +#extra="" +extra="--leak-check=full" + +valgrind --tool=$tool --time-stamp=yes --log-file=valgrind_LuaSL.log $extra ./LuaSL & +sleep 3 +valgrind --tool=$tool --time-stamp=yes --log-file=valgrind_love.log $extra ./love & +sleep 3 +valgrind --tool=$tool --time-stamp=yes --log-file=valgrind_extantz.log $extra ./extantz + diff --git a/bin/killem.sh b/bin/killem.sh new file mode 100755 index 0000000..7b4d3a2 --- /dev/null +++ b/bin/killem.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# TODO - Deal with the valgrind left overs, by scanning the output of the following lines, picking out the PIDs, then "kill -KILL pid" +ps aux | grep love +ps aux | grep LuaSL + +killall -TERM love +sleep 1 +killall -TERM LuaSL +sleep 1 + +ps aux | grep love +ps aux | grep LuaSL + +killall -KILL love +sleep 1 +killall -KILL LuaSL +sleep 1 + +ps aux | grep love +ps aux | grep LuaSL diff --git a/bin/unpacker.lua b/bin/unpacker.lua new file mode 100755 index 0000000..c60ef30 --- /dev/null +++ b/bin/unpacker.lua @@ -0,0 +1,105 @@ +#!/usr/bin/env luajit + +local args = ... +local tmpFile = os.tmpname() + +readCommand = function (command) + os.execute(command .. ' >' .. tmpFile) + local tf = io.open(tmpFile, 'r') + local result = tf:read() + tf:close() + return result +end + +function scanDir(directory) + local i, t, popen = 0, {}, io.popen +-- for filename in popen('dir "'..directory..'" /b'):lines() do + for filename in popen('ls -AF "'..directory..'"'):lines() do + i = i + 1 + t[i] = filename + end + return t +end + + +--workingDir = readCommand('pwd') +--baseDir = workingDir +--baseDir = string.gsub(baseDir, '(.*)/.-$', '%1') + +--bin_d = baseDir .. '' +--lib_d = baseDir .. '/lib' +--data_d = baseDir .. '/media' +--locale_d = baseDir .. '/locale' +home_d = readCommand('echo "$HOME"') + + +unpackers = +{ + iar = function (src, dst) return('tar -xzf ' .. src .. ' -C ' .. dst) end, + oar = function (src, dst) return('tar -xzf ' .. src .. ' -C ' .. dst) end, + rar = function (src, dst) return('unrar x ' .. src .. ' ' .. dst) end, + tar_bz2 = function (src, dst) return('tar -xzf ' .. src .. ' -C ' .. dst) end, + tar_gz = function (src, dst) return('tar -xzf ' .. src .. ' -C ' .. dst) end, + tgz = function (src, dst) return('tar -xzf ' .. src .. ' -C ' .. dst) end, + zip = function (src, dst) return('unzip ' .. src .. ' -d ' .. dst) end, +} + +--[[ TODO +Make it accept arguments - file dir + file = archive file, or directory to scan + dir = output directory + +If it's an OAR, or other sim defining format, or a model format, then create .omg files, stuff into .cache/converted/ or inventory/converted. + Or should conversion be a separate tool? + The problem is that we need to link back to the original archive, or carry other info like the archive type with us from here. + So might as well start the process by creating basic .omg files, with the info we have here, before we lose that info. + +]] + +print('Searching for archives in ' .. home_d .. '/.SledjHamr', ' -> ', ' unpack into ' .. home_d .. '/.SledjHamr/.cache/unpacked/') + +for k, v in pairs(scanDir(home_d .. '/.SledjHamr')) do + + -- First find if there's one of the special flags at the end, and strip it off. + t = string.sub(v, -1, -1) + v = string.sub(v, 1, -2) + f = true + if '@' == t then t = t + elseif '*' == t then t = t + elseif '/' == t then f = false + elseif '=' == t then t = t + elseif '>' == t then t = t + elseif '|' == t then t = t + else v = v .. t; t = ' '; + end + + -- Figure out what sort of file it is. + name, ext = string.match(v, "(.*)%.(.*)$") + if f and nil ~= ext then + name1, tar = string.match(name, "(.*)%.(.*)$") + if 'tar' == tar then + name = name1 + ext = tar .. '_' .. ext + end + + ext = string.lower(ext) + u = unpackers[ext] + if nil ~= u then + src = home_d .. '/.SledjHamr/' .. v + dst = home_d .. '/.SledjHamr/.cache/unpacked/' .. name + + os.execute('rm -fr ' .. dst) + os.execute('mkdir -p ' .. dst) + print('un' .. string.upper(ext) .. 'ing ', '"' .. v .. '"', ' -> ', '"' .. name .. '"') + if '@' == t then print(' ' .. v, ' is a soft link.') + elseif '*' == t then print(' ' .. v, ' is an executable.') + elseif '/' == t then print(' ' .. v, ' is a directory.'); + elseif '=' == t then print(' ' .. v, ' is a socket.') + elseif '>' == t then print(' ' .. v, ' is a door.') + elseif '|' == t then print(' ' .. v, ' is a FIFO.') +-- else print(' ' .. v, ' is an ordinary file.') + end + os.execute(u(src, dst) .. ' >/dev/null') + end + end +end -- cgit v1.1